Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions apps/dav/lib/Upload/UploadHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OC\Files\Filesystem;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\Directory;
use OCP\IConfig;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\ICollection;

Expand Down Expand Up @@ -97,10 +98,43 @@ private function getView() {
$rootView = new View();
$user = \OC::$server->getUserSession()->getUser();
Filesystem::initMountPoints($user->getUID());
if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) {
$rootView->mkdir('/' . $user->getUID() . '/uploads');

$config = \OC::$server->get(IConfig::class);

$allowSymlinks = $config->getSystemValueBool('localstorage.allowsymlinks', false);
$uploadsPath = $config->getSystemValueString('uploads_path', '');
$userPath = '/' . $user->getUID() . '/uploads';
$absoluteUserPath = $rootView->getLocalFile($userPath);

if ($allowSymlinks && $uploadsPath !== '' && $absoluteUserPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicit check?

Suggested change
if ($allowSymlinks && $uploadsPath !== '' && $absoluteUserPath) {
if ($allowSymlinks && $uploadsPath !== '' && $absoluteUserPath !== null) {

$uploadUserPath = $uploadsPath . $userPath;

if (!$rootView->file_exists($userPath) || !is_link($absoluteUserPath) || ($uploadUserPath != realpath($absoluteUserPath)) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do we check for !$rootView->file_exists($userPath)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would invert the if/else statement to have a more readable condition.

Suggested change
if (!$rootView->file_exists($userPath) || !is_link($absoluteUserPath) || ($uploadUserPath != realpath($absoluteUserPath)) ) {
if ($rootView->file_exists($userPath) && is_link($absoluteUserPath) && ($uploadUserPath === realpath($absoluteUserPath)) ) {


if (!is_dir($uploadUserPath)) {
mkdir($uploadUserPath, 0750, true);
}

// useful if link is broken due to $uploadUserPath changes
if (is_link($absoluteUserPath)) {
unlink($absoluteUserPath);
} elseif (is_dir($absoluteUserPath)) {
$rootView->rmdir($userPath);
}
symlink($uploadUserPath, $absoluteUserPath);

}

} else {
if ($absoluteUserPath && is_link($absoluteUserPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicit check?

Suggested change
if ($absoluteUserPath && is_link($absoluteUserPath)) {
if ($absoluteUserPath !== null && is_link($absoluteUserPath)) {

unlink($absoluteUserPath);
}
if (!$rootView->file_exists($userPath)) {
$rootView->mkdir($userPath);
}
}
return new View('/' . $user->getUID() . '/uploads');

return new View($userPath);
}

private function getStorage() {
Expand Down
8 changes: 8 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,14 @@
*/
'updatedirectory' => '',

/**
* Override where Nextcloud stores uploaded user files while uploading (chunks). Useful in situations
* where the default `<user_id>/uploads` is on network disk like NFS.
* Defaults to the value of '' if unset. Require `localstorage.allowsymlinks` set to `true` because
* impementation require symlink to works.
*/
'uploads_path' => '',

/**
* Blacklist a specific file or files and disallow the upload of files
* with this name. ``.htaccess`` is blocked by default.
Expand Down