Skip to content

Conversation

@tanganellilore
Copy link
Contributor

Summary

This PR will address the feature above, adding new config parameter and manage it.

The "smart" solution adopted is to use the conjunction of param that already exists localstorage.allowsymlinks and new config param uploadsdirectory.
The idea is to use a symlink to avoid the rework in all files/functions where <user_id>/uploads it's used.

The only piece of code that require changes is apps/dav/lib/Upload/UploadHome.php that check if localstorage.allowsymlinks is true and uploadsdirectory is setted, if yes we create symlink (if not already exists), if not, we continue to use the current implementation.

In case of user changes localstorage.allowsymlinks or uploadsdirectory, we will delete current link (or directory) and recreate it (link or dir based on settings).

TODO

  • ...

Checklist

@szaimen szaimen added the 3. to review Waiting for reviews label May 30, 2023
@szaimen szaimen added this to the Nextcloud 28 milestone May 30, 2023
@szaimen szaimen requested review from a team, blizzz, come-nc and icewind1991 and removed request for a team May 30, 2023 07:08
@tanganellilore tanganellilore force-pushed the add_uploads_directory branch from 40e6825 to 4619c80 Compare May 30, 2023 07:23
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

Comments on code

@tanganellilore tanganellilore force-pushed the add_uploads_directory branch from 52d9724 to c7bea9c Compare May 30, 2023 10:45
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

Small comments on codestyle.
Codewise this looks good to me. I’d just like other opinion on the chosen solution to rely on symlink for this, does anyone see this causing trouble in the future?

tanganellilore and others added 7 commits June 1, 2023 10:39
Signed-off-by: Lorenzo Tanganelli <[email protected]>
Signed-off-by: Lorenzo Tanganelli <[email protected]>
Signed-off-by: Lorenzo Tanganelli <[email protected]>
Signed-off-by: Lorenzo Tanganelli <[email protected]>
Signed-off-by: Lorenzo Tanganelli <[email protected]>
Signed-off-by: Lorenzo Tanganelli <[email protected]>
Signed-off-by: Lorenzo Tanganelli <[email protected]>

Signed-off-by: Lorenzo Tanganelli <[email protected]>
@tanganellilore tanganellilore force-pushed the add_uploads_directory branch from 329cea1 to a98604e Compare June 1, 2023 10:39
@tanganellilore
Copy link
Contributor Author

Thnaks @come-nc ,

the other alternative, is to rework where chunk uploads are store, without usage of symlink, but I don't have a lot fo experience on nextcloud codebase to identfy where uploads folder is used (i suppose on ChunkPlugin, but i don't know if somewhere else)

Copy link
Contributor

@artonge artonge left a comment

Choose a reason for hiding this comment

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

Not 100% sure about the current logic, I left a few comments to make is more readable.

Also, did you consider changing the code to directly write files to the PHP tmp folder? Probably a bigger change, but it would remove the need of creating and maintaining symlinks.
Or we could also append each successive chunks to the same final file, which would also reduce the read/write to 1. But chunks are probably coming unordered.

$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) {

if ($allowSymlinks && $uploadsPath !== '' && $absoluteUserPath) {
$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)) ) {

}

} 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)) {

@artonge
Copy link
Contributor

artonge commented Jun 1, 2023

Could you also check if adding tests is doable?

@artonge artonge added feature: files php Pull requests that update Php code pending documentation This pull request needs an associated documentation update labels Jun 1, 2023
@tanganellilore
Copy link
Contributor Author

As already commented, we can think to use directly a path like tmp for php, but i don't know which function need to be rewrite, in each piece/application.

If everything is under this repo, i can check it, but i don't know all dependecies

@tanganellilore tanganellilore mentioned this pull request Jun 1, 2023
5 tasks
@tanganellilore
Copy link
Contributor Author

@come-nc and @artonge I proposed new PR that should be address removal of symlink.

Let me know if I need to fix this one or we move to the "new" approach.

Thanks

@icewind1991
Copy link
Member

icewind1991 commented Jun 1, 2023

The use case of having the uploads go somewhere else is already supported by setting the cache_path config value:

When set, uploads will go into $cache_path/$userId/uploads

public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$cacheBaseDir = $this->config->getSystemValueString('cache_path', '');
if ($cacheBaseDir !== '') {
$cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID();
if (!file_exists($cacheDir)) {
mkdir($cacheDir, 0770, true);
mkdir($cacheDir . '/uploads', 0770, true);
}
return [
new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir], $loader, null, null, self::class),
new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads'], $loader, null, null, self::class)
];
} else {
return [];
}
}

@tanganellilore
Copy link
Contributor Author

tanganellilore commented Jun 2, 2023

Thanks @icewind1991, Yes i notice it when i work in the new PR, but this means that one config cover two different path.
I think to maintain 2 path separated with 2 different config.

What so you think? If yes we can consider only my last PR and close this one.

From my point of view, other PR #38587 it's much correct (and will be documented)

@tanganellilore
Copy link
Contributor Author

Close in favour of #38587

@tanganellilore tanganellilore deleted the add_uploads_directory branch June 21, 2024 15:07
@skjnldsv skjnldsv removed this from the Nextcloud 28 milestone Aug 14, 2024
@skjnldsv skjnldsv removed the pending documentation This pull request needs an associated documentation update label Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews feature: files php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support to custom user uploads dir

7 participants