X Tutup
Skip to content

Return false if the rename fails except for connect exceptions#35598

Merged
DeepDiver1975 merged 5 commits intomasterfrom
smb_rename_fix
Jun 27, 2019
Merged

Return false if the rename fails except for connect exceptions#35598
DeepDiver1975 merged 5 commits intomasterfrom
smb_rename_fix

Conversation

@jvillafanez
Copy link
Member

Description

A failure during the rename operation due to insufficient permissions was causing the storage to be unavailable. In this case, the operation should return false instead of throwing a StorageNotAvailableException

Related Issue

https://github.com/owncloud/phoenix/issues/1326

Motivation and Context

It should fail normally instead of blocking the storage

How Has This Been Tested?

This has been checked with the "old" UI, not with phoenix, although it's expected a similar behaviour.

  1. Ensure the file can be edited by the user, but the parent folder is only readable
  2. Try to rename a file.

Note: it seems the UI behaves badly under these circumstances. There is an error shown, but the "renamed" file disappears. The storage is available, and you can go outside and then inside the folder to make the file reappear again. The "move" http request ends up with a 404 error code.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open tasks:

  • Backport (if applicable set "backport-request" label and remove when the backport was done)

$this->swallow(__FUNCTION__, $e);
$result = false;
} else {
$ex = new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
Copy link
Member

Choose a reason for hiding this comment

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

This code logic is there in other operations as well. Please double check those locations as well. THX

@codecov
Copy link

codecov bot commented Jun 19, 2019

Codecov Report

Merging #35598 into master will increase coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #35598      +/-   ##
============================================
+ Coverage     65.67%   65.67%   +<.01%     
  Complexity    18763    18763              
============================================
  Files          1222     1222              
  Lines         70887    70886       -1     
  Branches       1289     1289              
============================================
  Hits          46555    46555              
+ Misses        23954    23953       -1     
  Partials        378      378
Flag Coverage Δ Complexity Δ
#javascript 53.7% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 67.04% <0%> (ø) 18763 <0> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
apps/files_external/lib/Lib/Storage/SMB.php 48.05% <0%> (+0.1%) 0 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11b6636...752ef8e. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 19, 2019

Codecov Report

Merging #35598 into master will increase coverage by 0.06%.
The diff coverage is 36.36%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #35598      +/-   ##
============================================
+ Coverage     65.67%   65.73%   +0.06%     
- Complexity    18763    18779      +16     
============================================
  Files          1222     1222              
  Lines         70887    70903      +16     
  Branches       1289     1289              
============================================
+ Hits          46555    46609      +54     
+ Misses        23954    23916      -38     
  Partials        378      378
Flag Coverage Δ Complexity Δ
#javascript 53.7% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 67.11% <36.36%> (+0.06%) 18779 <0> (+16) ⬆️
Impacted Files Coverage Δ Complexity Δ
lib/private/Files/View.php 84.65% <100%> (+0.04%) 401 <0> (+3) ⬆️
apps/dav/lib/Connector/Sabre/Node.php 81.14% <100%> (+6.14%) 50 <0> (+1) ⬆️
apps/files_external/lib/Lib/Storage/SMB.php 52.44% <19.23%> (+4.49%) 0 <0> (ø) ⬇️
apps/dav/lib/Tree.php 80.95% <0%> (-7.29%) 11% <0%> (+5%)
...es_sharing/lib/Controller/Share20OcsController.php 87.5% <0%> (+0.1%) 211% <0%> (+2%) ⬆️
core/Controller/LostController.php 89.18% <0%> (+0.69%) 37% <0%> (+4%) ⬆️
core/Command/Encryption/EncryptAll.php 92% <0%> (+1.09%) 12% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11b6636...17c624d. Read the comment docs.

@mmattel
Copy link
Contributor

mmattel commented Jun 19, 2019

@jvillafanez question:
would your change also work in following situation:
client: macos, sync client installed
backend mount to sync to: smb
create a file on macos containing an invalid character for smb like mypicture_2019:06:19.png
when syncing, it tells that storage is not available instead rejecting the sync

@jvillafanez
Copy link
Member Author

It's very likely. In any case, the error isn't caused by the storage not being available but due to invalid chars in the file name.
I'm not fully sure how the client will behave because the changes are currently limited to the storage connector and there are several layers on top of it. This is still under investigation.

@jvillafanez
Copy link
Member Author

Rename UI problem should be fixed with 1799af8 (checked in the "old" UI, not in phoenix). Throwing a Forbidden exception might not be nice, but I haven't seen a better alternative.

I've also notice that we've been writing information in the cache even though the operation failed. Maybe that has been the cause of ghost entries. They should be fixed with 5780701 (pending to be verified, but changes make sense to me)

@mmattel
Copy link
Contributor

mmattel commented Jun 19, 2019

Throwing a Forbidden exception might not be nice, but I haven't seen a better alternative.

Maybe http 422 (Unprocessable Entity) ?
(The response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.)

@jvillafanez
Copy link
Member Author

I think we should throw any of the exceptions in https://github.com/sabre-io/dav/tree/master/lib/DAV/Exception which should be the ones that are expected to be handled by the sabre library (which will be the one handling the request anyway). It's unlikely that any other exception outside of that list will be properly handled.
I'm not familiar with the code around dav, so maybe I'm wrong. In any case I'd wait until @DeepDiver1975 confirms

@mmattel
Copy link
Contributor

mmattel commented Jun 19, 2019

ok, got the client to run on ubuntu 18.04.

did a test with the client with a local file tt.txt - ok
renaming the file to tt\:1.txt - 503 Service Unavailable
renaming back to tt.txt
cloning your branch
renaming the file to tt\:1.txt - 403 Forbidden
renaming the file to tt\>.txt - 403 Forbidden

nice 👍

I just read that 422 Unprocessable Entity is currently not present, but that maybe a good chance to implement it as that would be much clearer... @DeepDiver1975 didn´t you do some coding in sabre dav 😄

@jvillafanez
Copy link
Member Author

I don't think I can improve coverage here. Most of the changes related to the storage can't be unittested, and testing the changes in the view, if possible, is too complex.

@DeepDiver1975
Copy link
Member

Maybe http 422 (Unprocessable Entity) ?

no - see https://tools.ietf.org/html/rfc4918#section-11.2

422 has a clear definition which does not match to this case.

403 looks reasonable and is consistent with the way we use this exception in other places

@jvillafanez
Copy link
Member Author

Backport in #35683

@haribhandari07
Copy link
Contributor

haribhandari07 commented Sep 9, 2019

@jvillafanez I am doing manual testing of this pr. How can I achieve step 1 Ensure the file can be edited by the user, but the parent folder is only readable of How has this been tested? .

When a parent folder is shared with read-only permission the receiver cannot edit the child files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

X Tutup