From 43090a9c804c025c3b3885f08618172e10bcec5f Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 3 Sep 2024 12:08:22 +0300 Subject: [PATCH 1/7] Fix scandir --- src/Storage/Device/Local.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index 13bed91a..ed73b218 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -364,15 +364,13 @@ public function deletePath(string $path): bool foreach ($files as $file) { if (is_dir($file)) { - $this->deletePath(\ltrim($file, $this->getRoot().DIRECTORY_SEPARATOR)); + $this->deletePath(substr_replace($file, '', 0, strlen($this->getRoot()))); } else { $this->delete($file, true); } } - \rmdir($path); - - return true; + return \rmdir($path); } /** @@ -517,18 +515,11 @@ public function getPartitionTotalSpace(): float */ public function getFiles(string $dir, int $max = self::MAX_PAGE_SIZE, string $continuationToken = ''): array { - if (! (\str_ends_with($dir, DIRECTORY_SEPARATOR))) { - $dir .= DIRECTORY_SEPARATOR; - } - + $dir = rtrim($dir, DIRECTORY_SEPARATOR); $files = []; - foreach (\scandir($dir) as $file) { - if ($file === '.' || $file === '..') { - continue; - } - - $files[] = $dir.$file; + foreach (\glob($dir.'/*') as $file) { + $files[] = $file; } return $files; From 2119125381f2fed6e16fa4676621b3df0d805031 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 3 Sep 2024 12:18:50 +0300 Subject: [PATCH 2/7] use DIRECTORY_SEPARATOR --- src/Storage/Device/Local.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index ed73b218..3f6e1596 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -518,7 +518,7 @@ public function getFiles(string $dir, int $max = self::MAX_PAGE_SIZE, string $co $dir = rtrim($dir, DIRECTORY_SEPARATOR); $files = []; - foreach (\glob($dir.'/*') as $file) { + foreach (\glob($dir.DIRECTORY_SEPARATOR.'*') as $file) { $files[] = $file; } From 272eb4538615e2a9918619c4b788fb9a258f6f07 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 3 Sep 2024 14:10:31 +0300 Subject: [PATCH 3/7] tests --- src/Storage/Device/Local.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index 3f6e1596..2045cc18 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -364,6 +364,7 @@ public function deletePath(string $path): bool foreach ($files as $file) { if (is_dir($file)) { + //$this->deletePath(\ltrim($file, $this->getRoot().DIRECTORY_SEPARATOR)); $this->deletePath(substr_replace($file, '', 0, strlen($this->getRoot()))); } else { $this->delete($file, true); From 8d74182488562c62f1556863b0b1e7baad429470 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 3 Sep 2024 17:36:26 +0300 Subject: [PATCH 4/7] Add hidden files --- src/Storage/Device/Local.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index 2045cc18..80d49d8c 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -364,7 +364,6 @@ public function deletePath(string $path): bool foreach ($files as $file) { if (is_dir($file)) { - //$this->deletePath(\ltrim($file, $this->getRoot().DIRECTORY_SEPARATOR)); $this->deletePath(substr_replace($file, '', 0, strlen($this->getRoot()))); } else { $this->delete($file, true); @@ -523,6 +522,10 @@ public function getFiles(string $dir, int $max = self::MAX_PAGE_SIZE, string $co $files[] = $file; } + foreach (\glob($dir.DIRECTORY_SEPARATOR.'.[!.]*') as $file) { + $files[] = $file; + } + return $files; } } From 179123e09cfd2922c23f0cff1d05a883fd635d23 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 3 Sep 2024 17:53:44 +0300 Subject: [PATCH 5/7] Add comment --- src/Storage/Device/Local.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index 80d49d8c..e9319db4 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -522,6 +522,9 @@ public function getFiles(string $dir, int $max = self::MAX_PAGE_SIZE, string $co $files[] = $file; } + /** + * Hidden files + */ foreach (\glob($dir.DIRECTORY_SEPARATOR.'.[!.]*') as $file) { $files[] = $file; } From b60be790ef3793190165934f44c07dfa4e5cad81 Mon Sep 17 00:00:00 2001 From: Shmuel Fogel Date: Wed, 4 Sep 2024 11:22:54 +0300 Subject: [PATCH 6/7] Update src/Storage/Device/Local.php Co-authored-by: Jake Barnby --- src/Storage/Device/Local.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index e9319db4..86729863 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -364,7 +364,7 @@ public function deletePath(string $path): bool foreach ($files as $file) { if (is_dir($file)) { - $this->deletePath(substr_replace($file, '', 0, strlen($this->getRoot()))); + $this->deletePath(\substr_replace($file, '', 0, \strlen($this->getRoot() . DIRECTORY_SEPARATOR))); } else { $this->delete($file, true); } From 68aec328c3b0520d0981a583ed363a4d1790a084 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 4 Sep 2024 11:24:04 +0300 Subject: [PATCH 7/7] Linter --- src/Storage/Device/Local.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index 86729863..6819bf7f 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -364,7 +364,7 @@ public function deletePath(string $path): bool foreach ($files as $file) { if (is_dir($file)) { - $this->deletePath(\substr_replace($file, '', 0, \strlen($this->getRoot() . DIRECTORY_SEPARATOR))); + $this->deletePath(\substr_replace($file, '', 0, \strlen($this->getRoot().DIRECTORY_SEPARATOR))); } else { $this->delete($file, true); }