Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #31849 - delete thumbnails on write hooks #31853

Merged
merged 1 commit into from
Jun 21, 2018
Merged
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
17 changes: 14 additions & 3 deletions lib/private/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -1306,11 +1306,22 @@ public static function post_delete_versions($args) {
public static function post_delete($args, $prefix = '') {
$path = Files\Filesystem::normalizePath($args['path']);
if (!isset(self::$deleteFileMapper[$path])) {
return;
$user = isset($args['user']) ? $args['user'] : \OC_User::getUser();
if ($user === false) {
$user = Filesystem::getOwner($path);
Copy link
Contributor

Choose a reason for hiding this comment

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

what user do we receive here in the following scenario:

  1. admin sets up system-wide ext storage "/sftp" with sharing enabled
  2. user1 shares folder "sftp/test" with public link
  3. log out
  4. anonymous user opens link and upload+overwrites file

There is a slight risk that you'll get null here as the storage has no owner since it's system-wide. In other code paths we somehow hackily resolve this to the sharer.

Copy link
Member Author

Choose a reason for hiding this comment

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

let me return in case $user is null and we will see how far we get

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me know when you are finished editing the "real code" and I will quickly re-run the 3 scenarios in the issue report.
After that, you can write unit tests all you like, and it won't make a difference to the run-time behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no need in checking if Filesystem::getOwner is returning a valid user - it will always be a user (maybe not the correct on - but this is a different story).
An exception will be thrown if there is no owner - so we will stop execution of the hook listener.

no further changes from my pov - let's merge this and I take care about the backport

}

$userFolder = \OC::$server->getUserFolder($user);
if ($userFolder === null) {
return;
}

$node = $userFolder->get($path);
} else {
/** @var FileInfo $node */
$node = self::$deleteFileMapper[$path];
}

/** @var FileInfo $node */
$node = self::$deleteFileMapper[$path];
$preview = new Preview($node->getOwner()->getUID(), $prefix, $node);
$preview->deleteAllPreviews();
}
Expand Down