-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Providing --path option to transfer-ownership #27343
Providing --path option to transfer-ownership #27343
Conversation
@sharidas, thanks for your PR! By analyzing the history of the files in this pull request, we identified @DeepDiver1975, @PVince81 and @chagrawil to be potential reviewers. |
'path', | ||
'', | ||
InputArgument::OPTIONAL, | ||
'selectively provide the path to copy. For example --path "alice/files/Music"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/copy/transfer/ (it's a move, not a copy)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced copy with transfer in the new update.
$view->mkdir("$this->sourceUser/files"); | ||
$sourcePath = (strlen($this->inputPath) > 0) ? $this->inputPath : "$this->sourceUser/files"; | ||
$view->rename($sourcePath, $this->finalTarget); | ||
if (!is_dir($this->sourceUser/files)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing double quotes on string ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the double quotes on string in the new update.
d5eb4ce
to
d0b7dfb
Compare
8531de1
to
3440a1f
Compare
The updated version of the patch is ready for review. @PVince81 Can you please review this change. |
Expected result: folder "transferthis" is no more in "user1"'s account and is present in "user2's" account. Please have a look. |
you might need to debug into |
@PVince81 Thanks for the feedback. I will have a look at it. |
Best would be to write an integration test right away because setting this up for testing is time consuming as you need to start from scratch after a transfer. Running the test when debugging would help save this time. |
cde6634
to
8a62eb7
Compare
@sharidas it seems you have found a bug deep in the FS code. In the old code, the move operation would do: But now with the new logic the rename is: Still, it seems the @sharidas for you the fix is to call The View but will need to be fixed separately, I'll make a ticket for it. |
Raised View issue here: #27376 |
04f7dd1
to
f388285
Compare
@PVince81 I have updated the PR by adding $view->mkdir at https://github.com/owncloud/core/pull/27343/files#diff-0674cc8bda871e32d63705af16fa8144R258. I have verified that share folders and other folders which are created by user1 do get transferred. |
9c2b4d3
to
339e546
Compare
Given user "user0" exists | ||
And user "user1" exists | ||
And User "user0" created a folder "/test" | ||
When transfering ownership path from path "test" "user0" to "user1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is not clear.
Something like this seems better:
When transfering ownership of path "test" from "user0" to "user1"
Also I recommend to put the starting slash before any paths as it is the decided choice to name paths in scenarios.
339e546
to
ed8523a
Compare
@SergioBertolinSG I have updated the integration tests. Kindly review the same. |
* @When /^transfering ownership path from path "([^"]+)" "([^"]+)" to "([^"]+)"/ | ||
*/ | ||
public function transferingOwnershipPath($path, $user1, $user2) { | ||
$path = '--path "' . $path . '"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The occ command is expecting a --path=$PATH. So this is failing because the lack of '='.
Also the occ command example is wrong because it is not adding the '='.
Usage:
files:transfer-ownership [options] [--] <source-user> <destination-user>
Arguments:
source-user owner of files which shall be moved
destination-user user who will be the new owner of the files
Options:
--path=PATH selectively provide the path to transfer. For example --path "alice/files/Music"
And user "user1" exists | ||
And User "user0" created a folder "/test" | ||
When transfering ownership of path "test" from "user0" to "user1" | ||
And the command was successful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Then
Tests passed locally. But this explanation in the help of the command is wrong: Options: Which this changes It has to be: Or change it to use '=' with the command. |
ed044bd
to
2c691dd
Compare
@PVince81 @SergioBertolinSG I have made the changes. Kindly review them. |
Seems to have trouble with PHP 5.6 ?
I did run 'make clean |
'path', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
'selectively provide the path to transfer. For example --path "alice/files/Music"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the example is wrong, it should not contain the "$userId/files/" piece
$objectsDir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); | ||
$dirFound = false; | ||
foreach ($objectsDir as $name => $object) { | ||
if (strpos($name, $this->inputPath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this safe ? what if there are two directories within the same path, like "somedir/test/somedir" ?
Can you add a PHP comment to explain why you are using strpos
here ?
Would also be good to add an explicit condition like >= 0
if (strlen($this->inputPath) >= 1) { | ||
$unknownDir = $this->inputPath; | ||
$this->inputPath = $this->sourceUser . "/files/" . $this->inputPath; | ||
$path = realpath(getcwd()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh, no. Don't do anything with the direct FS. There are some storages that do not store anything in the "data" folder but store in object store.
Please always use the $view
methods for checking path existence. $view->is_dir($this->inputPath)
.
In general in OC never ever access the FS directly, always use a $view or the files public API.
2c691dd
to
0886c50
Compare
@PVince81 Kindly review my updated PR. I have removed ugly changes which directly access FS. Used $view->is_dir in the updated PR. I have also modified the example 'selectively provide the path to transfer. For example --path "folder_name" or --path="folder_name'. |
'path', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
'selectively provide the path to transfer. For example --path "folder_name" or --path="folder_name"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--path "folder_name" or --path="folder_name"
? it's twice the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
A few more required changes, especially the one about init mount points.
$unknownDir = $this->inputPath; | ||
$this->inputPath = $this->sourceUser . "/files/" . $this->inputPath; | ||
if (!$view->is_dir($this->inputPath)) { | ||
$output->writeln("<error>Unknown path provided:$unknownDir</error>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after ":" for better readability
if (strlen($this->inputPath) >= 1) { | ||
$view = new View(); | ||
$unknownDir = $this->inputPath; | ||
$this->inputPath = $this->sourceUser . "/files/" . $this->inputPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you use ltrim($this->inputPath, '/')
to avoid doubling slashes in case the user input a leading slash in the path
$this->inputPath = $input->getOption('path'); | ||
|
||
if (strlen($this->inputPath) >= 1) { | ||
$view = new View(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before you can use the view you need to first call initMountPoints
which is done a bit later.
I suggest you move this validation after the initMountPoints
call below, or at least the one from the source user.
The reason for this is that sometimes the storage is not directly on FS but in an object store. Only if the object store is mounted for that user will you be able to access it with the View.
// This change will help user to transfer the folder specified using --path option. | ||
// Else only the content inside folder is transferred which is not correct. | ||
if (strlen($this->inputPath) > 0) { | ||
if($this->inputPath !== "$this->sourceUser/files") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, when comparing paths you really need to make sure there are no double slashes.
this makes the ltrim($path, '/')
call I suggested above really necessary.
0886c50
to
a42b2af
Compare
@PVince81 I have moved the validation part for the path under the initMount. Have provided ltrim for the path ( i.e, $this->inputPath ) and during the path comparison I have used ltrim both in the left hand side and right hand side of the comparison. I have added leading space for $unknownDir ( around the ). I have removed --path="folder_name" in the help. All these are made in the updated commit. |
Integration tests fail, see https://jenkins.owncloud.org/job/owncloud-core/job/core/job/PR-27343/15/display/redirect |
This behaviour should not be this way:
it looks like path value is optional, that's misleading. It should look like --path=PATH Also when running the command without --help it should show the same [--path=PATH] In this case:
|
e630a80
to
6008bce
Compare
@@ -103,6 +113,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { | |||
|
|||
$this->sourceUser = $sourceUserObject->getUID(); | |||
$this->destinationUser = $destinationUserObject->getUID(); | |||
$this->inputPath = $input->getOption('path'); | |||
$this->inputPath = ltrim($this->inputPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ltrim($this->inputPath,'/')
to remove leading slashes
// This change will help user to transfer the folder specified using --path option. | ||
// Else only the content inside folder is transferred which is not correct. | ||
if (strlen($this->inputPath) > 0) { | ||
if(ltrim($this->inputPath, '/') !== ltrim("$this->sourceUser/files", '/')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to ltrim the input path if you do it right at the start
if (strlen($this->inputPath) >= 1) { | ||
$view = new View(); | ||
$unknownDir = $this->inputPath; | ||
$this->inputPath = $this->sourceUser . "/files/" . $this->inputPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason I'm asking you to ltrim the path is that if someone sets --path=/somedir
, this concatenation here would result in "$userId/files//somedir" (double slash)
This will help user to selectively move the folders specified using --path option, instead of moving entire folder under files directory. Signed-off-by: Sujith H <[email protected]>
Update the integration test for transfer-ownership as the new option --path is introduced in the command. Signed-off-by: Sujith H <[email protected]>
6008bce
to
ed2be64
Compare
👍 if tests still pass |
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. |
This will help user to selectively move the folders
specified using --path option, instead of moving
entire folder under files directory.
Signed-off-by: Sujith H [email protected]
Description
The change has been made for occ command's transfer-ownership. An additional --path argument has been added to support. This will help user to pass particular folder/file to move to destination user/target. So I have introduced an optional argument --path. I have deliberately made it optional, as its user choice to move entire folder under files or selectively.
Related Issue
This issue which this patch addresses is https://github.com/owncloud/platform/issues/91
Motivation and Context
This helps the user to selectively transfer the ownership of the files/folders instead of moving entire folder under files.
How Has This Been Tested?
Below is the way I have tested:
The folder files/1/1a/1aa/ has 1aaa, 1aab and 1aac folders
root@silburyadmin-Inspiron-5567:/home/sujith/test/owncloud# sudo -u www-data ./occ files:transfer-ownership --path "test1/files/1/1a/1aa" test1 test2
Analysing files of test1 ...
0 [>---------------------------]
Collecting all share information for files and folder of test1 ...
0 [>---------------------------]
Transferring files to test2/files/transferred from test1 on 20170309_101206 ...
Restoring shares ...
0 [>---------------------------]
root@silburyadmin-Inspiron-5567:/home/sujith/test/owncloud#
after the execution I was able to see in test2 user:
root@silburyadmin-Inspiron-5567:/home/sujith/test/owncloud# ls -lt data/test2/files/transferred\ from\ test1\ on\ 20170309_101206/
total 12
drwxr-xr-x 2 www-data www-data 4096 Mar 9 15:42 1aac
drwxr-xr-x 2 www-data www-data 4096 Mar 9 15:42 1aab
drwxr-xr-x 2 www-data www-data 4096 Mar 9 15:42 1aaa
root@silburyadmin-Inspiron-5567:/home/sujith/test/owncloud#
and in test1 user:
root@silburyadmin-Inspiron-5567:/home/sujith/test/owncloud# ls data/test1/files/1/1a/
1ab
root@silburyadmin-Inspiron-5567:/home/sujith/test/owncloud#
Screenshots (if appropriate):
Types of changes
Checklist: