symbolic links treating files as folder

Created on 10 August 2022, over 2 years ago
Updated 16 September 2024, 2 months ago

Steps to reproduce

Add a symlink on any file behaves as a folder.
File having syblinks is not downloading they are opening as a folder under that folder gives no files found.

๐Ÿ› Bug report
Status

Closed: works as designed

Version

3.0

Component

Directory Listing Pages

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia Yatendra Singh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States binquanwang

    Hello @clivesj,

    I'm reopening this issue since I can reproduce this issue on my Drupal 10 Website.
    Here is the error on the command line:
    Uncaught PHP Exception Drupal\\Core\\File\\Exception\\NotRegularDirectoryException: "public://my_files/organism_1/collection1/nothing.txt is not a directory." at /var/www/t4/web/core/lib/Drupal/Core/File/FileSystem.php line 668, referer: http://t4.bigrig.local/node/1?fid=8

    Here are the logs showing the error:
    php
    Date Thursday, August 1, 2024 - 15:08
    User drupaladmin
    Location http://localhost/tripal4/node/1?fid=42
    Referrer http://localhost/tripal4/node/1
    Message Drupal\Core\File\Exception\NotRegularDirectoryException: public://uploads/example-link.txt is not a directory. in Drupal\Core\File\FileSystem->scanDirectory() (line 646 of /var/www/tripal4/web/core/lib/Drupal/Core/File/FileSystem.php).
    Severity Error
    Hostname ::1
    Operations
    Backtrace
    #0 /var/www/tripal4/web/modules/contrib/filebrowser/src/ServerFileList.php(72): Drupal\Core\File\FileSystem->scanDirectory()
    #1 /var/www/tripal4/web/modules/contrib/filebrowser/src/ServerFileList.php(42): Drupal\filebrowser\ServerFileList->createServerFileList()
    #2 /var/www/tripal4/web/modules/contrib/filebrowser/src/File/DisplayFileList.php(180): Drupal\filebrowser\ServerFileList->__construct()
    #3 /var/www/tripal4/web/modules/contrib/filebrowser/src/File/DisplayFileList.php(116): Drupal\filebrowser\File\DisplayFileList->createFileDisplayList()
    #4 /var/www/tripal4/web/modules/contrib/filebrowser/filebrowser.module(241): Drupal\filebrowser\File\DisplayFileList->__construct()
    #5 [internal function]: filebrowser_node_view()
    #6 /var/www/tripal4/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(416): call_user_func_array()
    #7 /var/www/tripal4/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(395): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}()
    #8 /var/www/tripal4/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(423): Drupal\Core\Extension\ModuleHandler->invokeAllWith()
    #9 /var/www/tripal4/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(288): Drupal\Core\Extension\ModuleHandler->invokeAll()
    #10 /var/www/tripal4/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(239): Drupal\Core\Entity\EntityViewBuilder->buildMultiple()
    #11 [internal function]: Drupal\Core\Entity\EntityViewBuilder->build()
    #12 /var/www/tripal4/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(113): call_user_func_array()
    #13 /var/www/tripal4/web/core/lib/Drupal/Core/Render/Renderer.php(870): Drupal\Core\Render\Renderer->doTrustedCallback()
    #14 /var/www/tripal4/web/core/lib/Drupal/Core/Render/Renderer.php(432): Drupal\Core\Render\Renderer->doCallback()
    #15 /var/www/tripal4/web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender()
    #16 /var/www/tripal4/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(238): Drupal\Core\Render\Renderer->render()
    #17 /var/www/tripal4/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
    #18 /var/www/tripal4/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(239): Drupal\Core\Render\Renderer->executeInRenderContext()
    #19 /var/www/tripal4/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(128): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
    #20 /var/www/tripal4/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
    #21 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
    #22 /var/www/tripal4/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
    #23 /var/www/tripal4/vendor/symfony/http-kernel/HttpKernel.php(186): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
    #24 /var/www/tripal4/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #25 /var/www/tripal4/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
    #26 /var/www/tripal4/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #27 /var/www/tripal4/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #28 /var/www/tripal4/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
    #29 /var/www/tripal4/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
    #30 /var/www/tripal4/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #31 /var/www/tripal4/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #32 /var/www/tripal4/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #33 /var/www/tripal4/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #34 /var/www/tripal4/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #35 /var/www/tripal4/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #36 /var/www/tripal4/web/index.php(19): Drupal\Core\DrupalKernel->handle()
    #37 {main}

    The log entry you're seeing indicates that Drupal is encountering an issue with handling symbolic links as if they are directories.

    Here are the steps on how to replicate this issue:
    On Windows (Using Ubuntu Subsystem) - I have a file example.txt in C:\test\symbolic
    Create a Symbolic Link in Ubuntu Subsystem:

    Open your Ubuntu terminal (the WSL terminal).

    Mount your Windows drive if it's not already mounted. Itโ€™s usually mounted under /mnt/, so C: is accessible at /mnt/c/.

    Create a symbolic link in the Ubuntu filesystem pointing to your Windows file. Run:
    sudo ln -s /mnt/c/test/symbolic/example.txt /var/www/tripal4/web/sites/default/files/uploads/example-link.txt

    This command creates a symbolic link named example-link.txt in the Filebrowser directory (/var/www/tripal4/web/sites/default/files/uploads) that points to example.txt located on your Windows drive.

    After creating these commands and ensure the symbolic link is shown on the FileBrowser module content you created, if you want to download rthe symbolic link, it will show an error.

    I believe the php file: filebrowser/src/ServerFileList.php - needs to be updated to clear this issue.

    Would you please take a look when you have some time?

    Thank you so much!

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands clivesj

    OK, I see it.
    The code mis-identifies the symbolic link as a folder and tries to treat it that way.
    I will try to find time to fix this in coming days.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States sean.buehler

    sean.buehler โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States sean.buehler

    I've opened a fork for this as binquanwang and I have and are working on a fix for this. It is the last hurdle for finalizing this as our file list solution for when we migrate to Drupal 10+.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands clivesj

    The current version of Filebrowser works fine if the symbolic link links to a directory on the same linux storage.

    The code, at the moment does not distinguish between a linked file or a linked directory. As soon as it detects a link it will assume it's a directory. As far as I know it is a bit of a problem trying to read the symbolic links since PHP is_link() is_dir() etc. should be able to execute without an error. A lot of things (like permissions on webservers level) will influence this, making it tricky.
    And I am not even talking about a symbolic link within a WSL2 system linking to a Windows file system.

    As I stand now, I am leaning into declaring Filebrowser to be *not* compatible with symbolic links.
    If the fork produces a full solution we can put that into a new release.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States sean.buehler

    So earlier I simply used the button at the top of this issue to create a fork, but it seems like it was created against the 8.x-2.x branch, which appears to be somewhat out-of-date. Should the fork for this issue be created against something a little more recent, such as the 3.1.x-dev branch?

  • Status changed to Closed: works as designed 2 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands clivesj

    ### Symbolic links ###
    Filebrowser only partially supports symbolic links. Symbolic links to directories *on the same storage* will work well. However, symbolic links to files will not work.
    The code, at the moment, does not distinguish between a linked file or a linked directory. As soon as it detects a link it will assume it's a directory.
    PHP functions like is_link() is_dir() etc. should be able to execute without an error in order to manage symbolic links. However, a lot of things (like permissions on webservers level) will influence this, making it tricky.
    And I am not even talking about a symbolic link within a WSL2 system linking to a Windows file system.
    There is a initiative to make FB fully compatible with symbolic links, so it might become available in a future release.

    I have added above information to the README.
    And closing this issue.
    If anyone comes-up with a solution to fully support symbolic links I will follow-up on it.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States sean.buehler

    Binquan and I need this for our site, and despite the closing of the issue have continued to work on it. On this fork and branch, filebrowser now supports symlinked files: https://git.drupalcode.org/issue/filebrowser-3302774/-/commits/3.1.x

    We still want to perform some testing to make sure it works on a variety of systems and configurations, including WSL, and also perhaps include functionality that gracefully handles files that have insufficient file permissions and/or are not accessible for whatever reason.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands clivesj

    OK.
    When ready I will review and merge it.
    Please also provide updated info on the simlink handling for the README file.

Production build 0.71.5 2024