Skip to content

Conversation

@PVince81
Copy link
Contributor

Description

  • refactored Files Node API tests to have more coverage: basically make NodeTest abstract and put the common tests there
  • refactored "rename()" and "copy()" operations to be in the Node class instead of File and Folder
  • fixed "rename()" and "copy()" operations to not ignore failures

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 NotPermittedException in 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

  • 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)
  • Tech debt

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.

@jvillafanez @DeepDiver1975

@PVince81 PVince81 added this to the 9.2 milestone Nov 14, 2016
@mention-bot
Copy link

@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);
Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

👍

use OCP\Files\NotPermittedException;

class File extends Node implements \OCP\Files\File {
protected $nonExistingClass = 'OC\Files\Node\NonExistingFile';
Copy link
Member

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

Copy link
Contributor Author

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...

@PVince81 PVince81 force-pushed the filesapi-renamefailcase branch from 1a8146d to 489f2e0 Compare November 21, 2016 13:48
@PVince81
Copy link
Contributor Author

@jvillafanez adjusted slightly differently. I used a method to simply return the string name of the NonExisting class to use.

@jvillafanez
Copy link
Member

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.

@PVince81 PVince81 force-pushed the filesapi-renamefailcase branch from 489f2e0 to d8997b1 Compare November 22, 2016 17:40
@PVince81
Copy link
Contributor Author

@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) {
Copy link
Member

Choose a reason for hiding this comment

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

missing return

Copy link
Contributor Author

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) {
Copy link
Member

Choose a reason for hiding this comment

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

missing return

Vincent Petry added 2 commits November 24, 2016 12:10
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
@PVince81 PVince81 force-pushed the filesapi-renamefailcase branch from d8997b1 to ba9bf30 Compare November 24, 2016 11:10
@PVince81
Copy link
Contributor Author

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 $root but keeping listen as is. Will need more work.

@PVince81
Copy link
Contributor Author

So, added and fixed tests for the move/copy hooks.

Ready for another review.

@jvillafanez
Copy link
Member

Code looks good 👍

@PVince81 PVince81 merged commit c154785 into master Nov 25, 2016
@PVince81 PVince81 deleted the filesapi-renamefailcase branch November 25, 2016 08:23
@lock
Copy link

lock bot commented Aug 4, 2019

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 4, 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.

Node API's move doesn't check view->rename return value

4 participants