Skip to content

Call getFullPath only if its defined in storage#29337

Merged
PVince81 merged 1 commit into
masterfrom
fix-getfullpath-sharedstorage
Oct 26, 2017
Merged

Call getFullPath only if its defined in storage#29337
PVince81 merged 1 commit into
masterfrom
fix-getfullpath-sharedstorage

Conversation

@sharidas

@sharidas sharidas commented Oct 24, 2017

Copy link
Copy Markdown
Contributor

Call getFullPath only if its defined in storage.
Else use mount point to resolve the full path.

Signed-off-by: Sujith H sharidasan@owncloud.com

Description

This change adds getFullPath method to shared external storage file.

Related Issue

#29167

Motivation and Context

Setup to recreate the issue:

  1. Create 2 instances of oC. Lets say oC1 and oC2.
  2. oC1 is not encrypted and oC2 is encrypted ( tested with masterkey ). oC2 is added as an external storage to oC1.
  3. Create a folder in oC2 name test
  4. Share the folder to an oC1 user user1 using federated share
  5. Now login as user1 in oC1 and create a file under test
  6. Try to delete the file. The log file in oC1, can see message mentioned in the issue.
    Since oC1 is non encrypted and when file under test is being deleted, the https://github.com/owncloud/core/blob/v10.0.3/lib/private/Files/Storage/Wrapper/Encryption.php#L786 code is hit. The reason is its a cross storage move. And getFullPath is defined only in Encryption storage. Its not available in other storages. So during the iteration to find the getFullPath method under storage wrappers, it couldn't find and throws the error. This change helps us to resolve that issue.

How Has This Been Tested?

Recreated the issue with the steps mentioned above. After applying this change when the file is deleted, the log file doesn't spit the error message.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sharidas sharidas self-assigned this Oct 24, 2017
@sharidas
sharidas requested a review from PVince81 October 24, 2017 11:13
@sharidas sharidas added this to the development milestone Oct 24, 2017
@sharidas

Copy link
Copy Markdown
Contributor Author

@PVince81 Let me know if you have suggestions to improve this change.

@codecov

codecov Bot commented Oct 24, 2017

Copy link
Copy Markdown

Codecov Report

Merging #29337 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #29337      +/-   ##
============================================
+ Coverage     60.21%   60.21%   +<.01%     
- Complexity    17183    17184       +1     
============================================
  Files          1030     1030              
  Lines         57280    57281       +1     
============================================
+ Hits          34493    34494       +1     
  Misses        22787    22787
Impacted Files Coverage Δ Complexity Δ
lib/private/Files/Storage/Wrapper/Encryption.php 68.51% <100%> (+0.07%) 151 <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 c12854c...6748fba. Read the comment docs.

@PVince81

Copy link
Copy Markdown
Contributor

This is just a quick workaround as it adds the method only on one implementation instead of the interface. I'm not sure if we should add this on the interface as it would affect every possible storage implementation out there.

@sharidas please also add a PHP "has_method" (or "is_method"?) check in the encryption code to check if the target storage does have the method before calling. If not, find a way to fallback.

@sharidas
sharidas force-pushed the fix-getfullpath-sharedstorage branch from 426a3b4 to 8a0ee8d Compare October 25, 2017 13:50
@sharidas sharidas changed the title Add getFullPath method to shared external storage Call getFullPath only if its defined in storage Oct 25, 2017
@sharidas

Copy link
Copy Markdown
Contributor Author

@PVince81 Hope the new change looks better.

if (method_exists($sourceStorage, "getFullPath")) {
$this->sourcePath[$targetInternalPath] = $sourceStorage->getFullPath($sourceInternalPath);
} else {
$this->sourcePath[$targetInternalPath] = $mountPoint . '/' . $sourceInternalPath;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can $mountPoint be undefined or is it always set ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With OC instance with encryption enabled:

  1. External Storage
    a) SFTP
    Delete a file from SFTP. mountPoint is not empty.
    Restore the file from trashbin. mountPoint is not empty
    b) ownCloud
    Delete a file from another oC instance ( encryption enabled ). mountPoint is not empty

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With the tests done other than fed share, I found that if condition is not getting true. The reason I guess is wrapper could be checksum and which doesn't have "getFullPath", so it moves to else.

@sharidas
sharidas force-pushed the fix-getfullpath-sharedstorage branch 2 times, most recently from e0f3acd to cd39315 Compare October 26, 2017 08:26
Call getFullPath only if its defined in storage.
Else use mount point to resolve the full path.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas
sharidas force-pushed the fix-getfullpath-sharedstorage branch from cd39315 to 6748fba Compare October 26, 2017 08:58

@PVince81 PVince81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 if CI passes

$source = $sourceStorage->fopen($sourceInternalPath, 'r');
if ($isRename) {
$this->sourcePath[$targetInternalPath] = $sourceStorage->getFullPath($sourceInternalPath);
if ($isRename && (count($mount) === 1)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This way $mount is not used without defining. The path obtained using this method and getFullPath in the scenario of transfer file onwership between users ( with masterkey encryption ), both path remains same.

@sharidas

Copy link
Copy Markdown
Contributor Author

Backport PR : #29360

@PVince81
PVince81 merged commit f4b3388 into master Oct 26, 2017
@PVince81
PVince81 deleted the fix-getfullpath-sharedstorage branch October 26, 2017 11:53
@lock

lock Bot commented Aug 2, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants