Fix issue with brackets in directory names

This commit is contained in:
bohwaz 2022-11-15 13:07:07 +01:00
parent 4fac8cf26f
commit 5aef69423a
2 changed files with 22 additions and 10 deletions

View file

@ -1303,13 +1303,19 @@ namespace NanoKaraDAV
$this->path = __DIR__ . '/';
}
static protected function glob(string $path, string $pattern = '', int $flags = 0): array
{
$path = preg_replace('/[\*\?\[\]]/', '\\\\$0', $path);
return glob($path . $pattern, $flags);
}
public function list(string $uri, ?array $properties): iterable
{
$dirs = glob($this->path . $uri . '/*', \GLOB_ONLYDIR);
$dirs = self::glob($this->path . $uri, '/*', \GLOB_ONLYDIR);
$dirs = array_map('basename', $dirs);
natcasesort($dirs);
$files = glob($this->path . $uri . '/*');
$files = self::glob($this->path . $uri, '/*');
$files = array_map('basename', $files);
$files = array_diff($files, $dirs);
@ -1486,7 +1492,7 @@ namespace NanoKaraDAV
}
if (is_dir($target)) {
foreach (glob($target . '/*') as $file) {
foreach (self::glob($target, '/*') as $file) {
$this->delete(substr($file, strlen($this->path)));
}
@ -1583,7 +1589,7 @@ namespace NanoKaraDAV
$last = 0;
$path = rtrim($path, '/');
foreach (glob($path . '/*', GLOB_NOSORT) as $f) {
foreach (self::glob($path, '/*', GLOB_NOSORT) as $f) {
if (is_dir($f)) {
$m = self::getDirectoryMTime($f);
@ -1651,11 +1657,11 @@ namespace {
$fp = fopen(__FILE__, 'r');
if ($relative_uri == 'webdav.js') {
fseek($fp, 43652, SEEK_SET);
fseek($fp, 43873, SEEK_SET);
echo fread($fp, 24265);
}
else {
fseek($fp, 43652 + 24265, SEEK_SET);
fseek($fp, 43873 + 24265, SEEK_SET);
echo fread($fp, 6760);
}

View file

@ -27,13 +27,19 @@ namespace NanoKaraDAV
$this->path = __DIR__ . '/';
}
static protected function glob(string $path, string $pattern = '', int $flags = 0): array
{
$path = preg_replace('/[\*\?\[\]]/', '\\\\$0', $path);
return glob($path . $pattern, $flags);
}
public function list(string $uri, ?array $properties): iterable
{
$dirs = glob($this->path . $uri . '/*', \GLOB_ONLYDIR);
$dirs = self::glob($this->path . $uri, '/*', \GLOB_ONLYDIR);
$dirs = array_map('basename', $dirs);
natcasesort($dirs);
$files = glob($this->path . $uri . '/*');
$files = self::glob($this->path . $uri, '/*');
$files = array_map('basename', $files);
$files = array_diff($files, $dirs);
@ -210,7 +216,7 @@ namespace NanoKaraDAV
}
if (is_dir($target)) {
foreach (glob($target . '/*') as $file) {
foreach (self::glob($target, '/*') as $file) {
$this->delete(substr($file, strlen($this->path)));
}
@ -307,7 +313,7 @@ namespace NanoKaraDAV
$last = 0;
$path = rtrim($path, '/');
foreach (glob($path . '/*', GLOB_NOSORT) as $f) {
foreach (self::glob($path, '/*', GLOB_NOSORT) as $f) {
if (is_dir($f)) {
$m = self::getDirectoryMTime($f);