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: Throw instead of yielding nothing when listing local directories #43787

Merged
merged 1 commit into from
Feb 24, 2024

Conversation

juliushaertl
Copy link
Member

@juliushaertl juliushaertl commented Feb 23, 2024

I've been poking around in code trying to replicate scenarios where out of a sudden file ids were changed. Due to one case where we have seen this with a temporary storage failure I tried making the __groupfolders directory not readable by changing filesystem permissions. Now when we hit file scanning logic we may end up calling the directory listing from the Local storage class which on an error does not fail but instead yields nothing which means that the scanner will handle the given directory as if it would be empty.

Note I'm not sure this actually fixes the issue and also not what could cause a scan on the folder out of a sudden (in testing i manually set the size to -1 to trigger this).

@icewind1991 Maybe you can have a look, i think from a code perspective is sensible and should avoid unnecessary file cache entry drops if the opendir fails. However I also cannot really exclude possible side-effects of a scanner then not removing a missing directory on the filesystem.

Related to nextcloud/groupfolders#1468

I also remember issues in the past where the size was always pending on some group folders (not sure if that was fixed meanwhile), but could then probably trigger such cases if the scan never finishes or happens regularly.

Checklist

@juliushaertl juliushaertl added bug 3. to review Waiting for reviews labels Feb 23, 2024
@juliushaertl juliushaertl requested review from icewind1991, Altahrim, a team and Fenn-CS and removed request for a team February 23, 2024 15:15
Copy link
Contributor

@Fenn-CS Fenn-CS left a comment

Choose a reason for hiding this comment

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

Strictly from a code-based perspective this looks okay, worst case it does not solve the issue but I don't see it causing another problem.

@@ -898,6 +899,11 @@ public function writeStream(string $path, $stream, int $size = null): int {

public function getDirectoryContent($directory): \Traversable {
$dh = $this->opendir($directory);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question:

Suggested change
$dh = $this->opendir($directory);
try {
$dh = $this->opendir($directory);
} catch(\Exception $e) {
// Throw and take other actions?
}

Can't be caught? To capture the actual failure/error? (That might required an update to method opendir if the reading functions through meaningful error messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

If that method throws the exception should already propagate, don't think we need to wrap that.

The local storage implementation would already log an error but return false which just wasn't handled before.

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Feb 24, 2024
@skjnldsv skjnldsv merged commit 1d8d43f into master Feb 24, 2024
159 checks passed
@skjnldsv skjnldsv deleted the fix/opendir-temporary-failure branch February 24, 2024 16:38
@juliushaertl
Copy link
Member Author

/backport to stable28

@juliushaertl
Copy link
Member Author

/backport to stable27

@juliushaertl
Copy link
Member Author

/backport to stable26

@max-nextcloud
Copy link
Contributor

/backport to stable25

@max-nextcloud
Copy link
Contributor

/backport to stable24

@max-nextcloud
Copy link
Contributor

/backport to stable23

@max-nextcloud
Copy link
Contributor

/backport to stable24

@max-nextcloud
Copy link
Contributor

/backport to stable23

if ($dh === false) {
throw new StorageNotAvailableException('Directory listing failed');
}

Choose a reason for hiding this comment

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

Potentially impacts all storage subsystems, since you put the change into Common.php . In particular, the sftp storage inherits the same implementation and breaks on sub-folders without sufficient permissions. Please revert that patch or move it to Local.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants