From 006580a36ec49926a94bbbe468bb22894f18f2e2 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 17 Sep 2020 19:49:28 +0200 Subject: [PATCH] fixed filemanager was not able to show home directory of user --- api/src/Vfs.php | 12 +++++++++--- api/src/Vfs/UserContextTrait.php | 9 +++++++-- vfs-context.php | 4 ++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/api/src/Vfs.php b/api/src/Vfs.php index 1e68753d25..3a0aa7a686 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -315,6 +315,7 @@ class Vfs extends Vfs\Base * * @param string|array $base base of the search * @param array $options =null the following keys are allowed: + * * - 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) @@ -334,6 +335,7 @@ class Vfs extends Vfs\Base * - follow => {true|false(default)} follow symlinks * - hidden => {true|false(default)} include hidden files (name starts with a '.' or is Thumbs.db) * - show-deleted => {true|false(default)} get also set by hidden, if not explicitly set otherwise (requires versioning!) + * * @param string|array/true $exec =null function to call with each found file/dir as first param and stat array as last param or * true to return file => stat pairs * @param array $exec_params =null further params for exec as array, path is always the first param and stat the last! @@ -352,11 +354,11 @@ class Vfs extends Vfs\Base // process some of the options (need to be done only once) if (isset($options['name']) && !isset($options['name_preg'])) // change from simple *,? wildcards to preg regular expression once { - $options['name_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['name'])).'$/i'; + $options['name_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['name'], '/')).'$/i'; } if (isset($options['path']) && !isset($options['preg_path'])) // change from simple *,? wildcards to preg regular expression once { - $options['path_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['path'])).'$/i'; + $options['path_preg'] = '/^'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($options['path'], '/')).'$/i'; } if (!isset($options['uid'])) { @@ -391,7 +393,11 @@ class Vfs extends Vfs\Base } // make all find options available as stream context option "find", to allow plugins to use them - $context = stream_context_create(array(self::SCHEME => array('find' => $options))); + $context = stream_context_create(array_merge_recursive(stream_context_get_options(stream_context_get_default()), [ + self::SCHEME => [ + 'find' => $options, + ], + ])); $url = $options['url']; diff --git a/api/src/Vfs/UserContextTrait.php b/api/src/Vfs/UserContextTrait.php index c24d0a0442..d04363eb97 100644 --- a/api/src/Vfs/UserContextTrait.php +++ b/api/src/Vfs/UserContextTrait.php @@ -42,9 +42,14 @@ trait UserContextTrait { $this->context = $url_or_context; } - elseif(is_string($url_or_context)) + else { - $this->check_set_context($url_or_context, true); + $this->context = stream_context_get_default(); + + if(is_string($url_or_context)) + { + $this->check_set_context($url_or_context, true); + } } } diff --git a/vfs-context.php b/vfs-context.php index 7b3d4787a9..ccc52b059e 100644 --- a/vfs-context.php +++ b/vfs-context.php @@ -21,12 +21,16 @@ Vfs::$is_root = true; Vfs::mount("$schema://default/home", '/home', false, false); Vfs::$is_root = false; var_dump(Vfs::mount()); +var_dump(Vfs::scandir('/home')); +var_dump(Vfs::find('/home', ['maxdepth' => 1])); +//var_dump(Vfs::scandir("/home/$sysop")); var_dump(file_put_contents("vfs://default/home/$sysop/test.txt", "Just a test ;)\n")); var_dump("Vfs::proppatch('/home/$sysop/test.txt', [['ns' => Vfs::DEFAULT_PROP_NAMESPACE, 'name' => 'test', 'val' => 'something']])=".array2string(Vfs::proppatch("/home/$sysop/test.txt", [['ns' => Vfs::DEFAULT_PROP_NAMESPACE, 'name' => 'test', 'val' => 'something']])), "Vfs::propfind('/home/$sysop/test.txt')=".json_encode(Vfs::propfind("/home/$sysop/test.txt"), JSON_UNESCAPED_SLASHES)); var_dump($f=fopen("vfs://default/home/$sysop/test.txt", 'r'), fread($f, 100), fclose($f)); +//var_dump(Vfs::find("/home/$sysop", ['maxdepth' => 1])); Vfs::$is_root = true; var_dump(file_put_contents("vfs://default/home/$other/test.txt", "Just a test ;)\n"));