-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Filesapi renamefailcase #26629
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
Filesapi renamefailcase #26629
Conversation
|
@PVince81, thanks for your PR! By analyzing the history of the files in this pull request, we identified @icewind1991, @DeepDiver1975 and @nickvergessen to be potential reviewers. |
| $this->root->emit('\OC\Files', 'preRename', [$this, $nonExisting]); | ||
| $this->root->emit('\OC\Files', 'preWrite', [$nonExisting]); | ||
| if (!$this->view->rename($this->path, $targetPath)) { | ||
| throw new NotPermittedException('Could not move ' . $this->path . ' to ' . $targetPath); |
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 is the actual fix: add a if here and in the copy method later
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.
👍
lib/private/Files/Node/File.php
Outdated
| use OCP\Files\NotPermittedException; | ||
|
|
||
| class File extends Node implements \OCP\Files\File { | ||
| protected $nonExistingClass = 'OC\Files\Node\NonExistingFile'; |
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 think using a method is more clear. In the Node class you could use something like:
protected function getNonExistingClass() {
if (__CLASS__ === 'OC\Files\Node\Node') {
throw Exception();
} else {
$convertedClass = convertToNonExistingString(__CLASS__); // 'OC\Files\Node\File' -> 'OC\Files\Node\NonExistingFile';
return new $convertedClass();
}
}
We'll need to define the expected return values for the function.
This way, the subclasses won't need to define the $nonExistingClass variable. As long as the method is aware that the target class might not exists, it should be fine
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're right. I was assuming that no one would ever bother to extend that class 😄
Will adjust...
1a8146d to
489f2e0
Compare
|
@jvillafanez adjusted slightly differently. I used a method to simply return the string name of the NonExisting class to use. |
|
Right now, the Node class needs to create the non-existent class, and to do that it needs to know how (particularly the parameters). On the other hand, if an instance is returned, the Node class might only need to check if the instance is a Node class or subclass. In fact, taking into account the Node class isn't abstract we should make sure the returned instances are a subclass of Node but not Node. Btw, the tests need to be adjusted. |
489f2e0 to
d8997b1
Compare
|
@jvillafanez I've now adjusted the node to have a method that creates the non existing instance for a given path. The tests still pass and I think they are fine. I don't want to add the same logic there because the tests really only check instanceof so a string for the class name to verify is enough. |
| * @param string $path path | ||
| * @return string non-existing node class | ||
| */ | ||
| protected function createNonExistingNode($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.
missing return
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.
uh oh... so the tests were lying... I'll add some hook tests to make sure this is caught too
| * @param string $path path | ||
| * @return string non-existing node class | ||
| */ | ||
| protected function createNonExistingNode($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.
missing return
Whenever a rename or copy operation failed on the view, we must throw an exception instead of just ignoring.
createMock only accepts a single param
d8997b1 to
ba9bf30
Compare
|
I fixed what you said and tried adding a test for the rename hook, but that one isn't done yet. Need to properly mock |
|
So, added and fixed tests for the move/copy hooks. Ready for another review. |
|
Code looks good 👍 |
|
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. |
Description
Why so much refatoring ? If I'd do the fix directly I'd have to add a lot of missing tests in the "FolderTest" class and also duplicate the fix across File and Folder.
Now I agree that throwing
NotPermittedExceptionin case of unknown failure from the view isn't very elegant. Any better suggestions welcome.Related Issue
Fixes #26625
Motivation and Context
Because we must not ignore errors.
Also, this blocks #26615 where I need to rely on a move failure for a unit test.
How Has This Been Tested?
Running unit tests
Screenshots (if appropriate):
Types of changes
Checklist:
@jvillafanez @DeepDiver1975