Skip to content
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

fix: Pass parent to NonExistingFile instances #40312

Merged
merged 1 commit into from Sep 13, 2023

Conversation

juliushaertl
Copy link
Member

@juliushaertl juliushaertl commented Sep 6, 2023

Summary

Fixes calls to getParent after #38150 when calling on NonExistingFile instances, e.g. within a BeforeNodeRenamedEvent.

Found in failing tests for moving files in text which has special handling. CI is passing with this branch again: nextcloud/text#4779

Checklist

@juliushaertl juliushaertl added bug 3. to review Waiting for reviews labels Sep 6, 2023
@juliushaertl juliushaertl added this to the Nextcloud 28 milestone Sep 6, 2023
@juliushaertl juliushaertl marked this pull request as ready for review September 6, 2023 18:37
@juliushaertl juliushaertl force-pushed the bugfix/noid/non-existing-node-parent branch from 581c2be to 0dfddfc Compare September 6, 2023 18:42
@@ -40,7 +40,7 @@ class File extends Node implements \OCP\Files\File {
* @return NonExistingFile non-existing node
*/
protected function createNonExistingNode($path) {
return new NonExistingFile($this->root, $this->view, $path);
return new NonExistingFile($this->root, $this->view, $path, $this->root->get(dirname($path)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you go into the details of what breaks without this and why is the lazy parent not enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

getParent used to just directly get it in https://github.com/nextcloud/server/pull/38150/files#diff-edc136e5646ea4171607db53b38833e8f6caaacc64874a0a850aa4444f0a56edL303-R309 but now always makes use of the file info which is not available for a nonexisting file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then wouldn’t the right fix be to check for fileinfo presence before calling getParentId on it and fallback on previous behavior if fileInfo is not there? I’m afraid there might be other side effects we missed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah might be indeed a good idea, will check that

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed a more generic approach but still passing the parent to the NonExistingFile to avoid an extra queries in that case.

Copy link
Member

Choose a reason for hiding this comment

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

to avoid an extra queries in that case.

doesn't it just move the query to the constructor call here?

As is it always does the "get parent" query even when getParentId isn't called, without this it only does the query when getParentId is called

@juliushaertl juliushaertl force-pushed the bugfix/noid/non-existing-node-parent branch from 0dfddfc to a86fa96 Compare September 7, 2023 19:48
@@ -297,10 +297,18 @@ public function getParent(): INode|IRootFolder {
return $this->root;
}

// Manually the parent if the current node doesn't have a file info yet
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Manually the parent if the current node doesn't have a file info yet
// Manually fetch the parent if the current node doesn't have a file info yet

Or get? But a word is missing there I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, fixed

@juliushaertl juliushaertl force-pushed the bugfix/noid/non-existing-node-parent branch from a86fa96 to 9d584b0 Compare September 11, 2023 13:31
@juliushaertl
Copy link
Member Author

I cannot see the same psalm error locally :/

@@ -40,7 +40,7 @@ class File extends Node implements \OCP\Files\File {
* @return NonExistingFile non-existing node
*/
protected function createNonExistingNode($path) {
return new NonExistingFile($this->root, $this->view, $path);
return new NonExistingFile($this->root, $this->view, $path, $this->root->get(dirname($path)));
Copy link
Member

Choose a reason for hiding this comment

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

to avoid an extra queries in that case.

doesn't it just move the query to the constructor call here?

As is it always does the "get parent" query even when getParentId isn't called, without this it only does the query when getParentId is called

@juliushaertl
Copy link
Member Author

doesn't it just move the query to the constructor call here?

Yeah let me maybe drop that then instead and just rely on the manual get in getParent instead

Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliushaertl juliushaertl force-pushed the bugfix/noid/non-existing-node-parent branch from b9bffa9 to 7f958e8 Compare September 13, 2023 08:28
@juliushaertl juliushaertl merged commit 1137b7a into master Sep 13, 2023
40 checks passed
@juliushaertl juliushaertl deleted the bugfix/noid/non-existing-node-parent branch September 13, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants