From f26b2710678800e187ede0803375dabe51a03dfd Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 9 Apr 2018 13:56:37 -0600 Subject: [PATCH] Exclude symlinks from Vfs --- api/src/Vfs.php | 5 +++-- api/src/Vfs/Sharing.php | 12 +++++++++++- api/tests/Vfs/SharingBase.php | 11 ++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 15d3024288..a97661b54e 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -384,7 +384,7 @@ class Vfs * * @param string|array $base base of the search * @param array $options =null the following keys are allowed: - * - type => {d|f|F} d=dirs, f=files (incl. symlinks), F=files (incl. symlinks to files), default all + * - type => {d|f|F|!l} d=dirs, f=files (incl. symlinks), F=files (incl. symlinks to files), !l=no symlinks, default all * - depth => {true|false(default)} put the contents of a dir before the dir itself * - dirsontop => {true(default)|false} allways return dirs before the files (two distinct blocks) * - mindepth,maxdepth minimal or maximal depth to be returned @@ -646,7 +646,8 @@ class Vfs return; // not found, should not happen } if ($type && (($type == 'd') == !($stat['mode'] & Vfs\Sqlfs\StreamWrapper::MODE_DIR) || // != is_dir() which can be true for symlinks - $type == 'F' && is_dir($path))) // symlink to a directory + $type == 'F' && is_dir($path)) || // symlink to a directory + $type == '!l' && ($stat['mode'] & Vfs::MODE_LINK)) // Symlink { return; // wrong type } diff --git a/api/src/Vfs/Sharing.php b/api/src/Vfs/Sharing.php index 8abc61b760..7c4ba250b4 100644 --- a/api/src/Vfs/Sharing.php +++ b/api/src/Vfs/Sharing.php @@ -443,7 +443,7 @@ class Sharing } // We don't allow sharing links, share target instead - if($target = Vfs::readlink($path)) + if(($target = Vfs::readlink($path))) { $path = $target; } @@ -761,5 +761,15 @@ if (file_exists(__DIR__.'/../../../filemanager/inc/class.filemanager_ui.inc.php' ); return $actions; } + + protected function get_vfs_options($query) + { + $options = parent::get_vfs_options($query); + + // Hide symlinks + $options['type'] = '!l'; + + return $options; + } } } \ No newline at end of file diff --git a/api/tests/Vfs/SharingBase.php b/api/tests/Vfs/SharingBase.php index 945d25cd96..82f1c574fd 100644 --- a/api/tests/Vfs/SharingBase.php +++ b/api/tests/Vfs/SharingBase.php @@ -131,8 +131,8 @@ class SharingBase extends LoggedInTest $this->files += $this->addFiles($dir); $logged_in_files = array_map( - function($path) use ($dir) {return str_replace($dir, '/', $path);}, - Vfs::find($dir, static::VFS_OPTIONS) + function($path) use ($dir) {return str_replace($dir, '/', $path);}, + Vfs::find($dir, static::VFS_OPTIONS) ); if(static::LOG_LEVEL > 1) @@ -354,15 +354,16 @@ class SharingBase extends LoggedInTest ); // Symlinked file - /* + /* We don't test these because they don't work - the target will always + * be outside the share root // Always says its empty $files[] = $symlink = $path.'symlink.txt'; if(Vfs::file_exists($symlink)) Vfs::remove($symlink); $this->assertTrue( Vfs::symlink($file, $symlink), - 'Unable to create symlink' + "Unable to create symlink $symlink => $file" ); -/* + // Symlinked dir $files[] = $symlinked_dir = $path.'sym_dir/'; $this->assertTrue(