-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 symlink issues when scanning for files #21723
Conversation
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.
Thank you for taking the time to debug and submit a patch 👍
lib/private/Files/Storage/Local.php
Outdated
$fullPath = $this->getSourcePath($path); | ||
$fullPath = null; | ||
try { | ||
$fullPath = $this->getSourcePath($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.
👍
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.
Please see my comment for Local.php
below. It's getting a bit longer...
lib/private/Files/Cache/Scanner.php
Outdated
@@ -415,6 +415,10 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s | |||
$childQueue = []; | |||
$newChildNames = []; | |||
foreach ($newChildren as $fileMeta) { | |||
if ($fileMeta === null) { | |||
continue; |
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'm unsure. If we are not able to process symlinks properly getDirectoryContent
should not return them.
server/lib/private/Files/Storage/Common.php
Line 877 in da2d425
if (!Filesystem::isIgnoredDir($file) && !Filesystem::isFileBlacklisted($file)) { |
We might add is_link
check there and not yield the meta data. Probably is_link could be added to isFileBlacklisted
if every symlink is actually forbidden (cc @icewind1991)
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.
Please see my comment below. It's getting a bit longer...
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.
Hey @kesselb Thanks a lot for your review! I gave this some thought... It makes sense to return only readable data from
And by the way, in Hence, it seams reasonable to fix it in
|
I just found another symlink issue. If you scanned a folder that contains symlinks and try to delete the folder afterwards in Nextcloud, it will fail with the following error: |
Thanks for your report. This PR tries to fix issues with the scanner. |
@adrium would you mind to rebase this branch and solve the conflicts? I will request another review then. Sorry it took so long. Thanks again for debugging 👍 |
I am not using nextcloud for this anymore, but I can try set up another test case, if there is interest. Please give me about two weeks. |
3e5f43e
to
7bcd87b
Compare
7bcd87b
to
191c57e
Compare
e77fa75
to
2439b7c
Compare
Hey, I worked on the PR again and tested it in the VM. It also fixes cyclic symlinks now!
What to do about the DCO check? Do I just have to repeat my name in the commit message? The below script can be used to create files to test the scanner. NCDATA=/mnt/ncdata
NCUSER=admin
NCTEST=$NCDATA/$NCUSER/files/Tests
DIR=$NCTEST/valid
mkdir -p $DIR
echo '# Valid links' > $DIR/README.md
ln -s ../../Photos $DIR/photos
ln -s ../../Photos/Library.jpg $DIR/file.jpg
# Case 1
DIR=$NCTEST/invalid
mkdir -p $DIR
echo '# Test for invalid link target' > $DIR/README.md
ln -s /invalid $DIR/link1
ln -s /tmp/invalid $DIR/link2
# Case 2
DIR=$NCTEST/outside
mkdir -p $DIR
mkdir /tmp/hello
echo '# Test for link target outside the user folder' > $DIR/README.md
echo '# Hello World' > /tmp/hello/README.md
ln -s /tmp/hello $DIR/link
# Case 3
DIR=$NCTEST/cyclic
mkdir -p $DIR
echo '# Test link pointing to parent' > $DIR/README.md
mkdir -p $DIR/directory/files
ln -s ../../directory $DIR/directory/files/parent |
Hi, from the first look at Do you need support with testing? |
@icewind1991 and @kesselb what is the current status? Can we help? |
Just one quick question: Is this still a problem now? |
It seems like this isn't such an issue for most people and failed to gain attraction :( Thanks for the interest in Nextcloud and the effort put into this! 🙇 |
Description
Hi, there are issues with the file scanner and symlinks.
This PR fixes the ones that are crashing the
files:scan
command for local storage:I am using Nextcloud more like a GUI to browse files online and do the sync or copy by other means.
Hence, some of the symlinks are not valid anymore when copied to the storage folder.
With the fixes applied, I was finally able to run a full scan of all files:
Folders: 46353
Files: 433857
Elapsed time: 00:20:28
The commits may not pass all checks when submitting.
I will try to update the code and force-push the branch with improvements.
Let me know about other adjustments so that the code is ready for merging.
Case 1
The scanner uses
OC\Files\Storage\Storage::getDirectoryContent()
which callsOC\Files\Storage\Local::getMetaData()
for local storage to populate the array of children.Because invalid symlinks are not readable, the array can contain
null
which is not expected byOC\Files\Cache\Scanner::handleChildren()
The PR fixes this by ignoring unreadable entries.
Case 2
OC\Files\Storage\Local::getMetaData()
usesOC\Files\Storage\Local::getSourcePath()
to resolve the filename.The method can throw a
ForbiddenException
if the path is outside the data directory which is not handled gracefully.Since
null
is returned, if the file is not readable, it is consistent to returnnull
in that case as well.