From 63408fa6ef70fb26ef57d93c24a36e325e788b2b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 May 2016 15:07:23 +0200 Subject: allow deleting "ghost files" trough the View and Node api --- lib/private/Files/View.php | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index f738542ea8c..8a99bc609cf 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -337,10 +337,17 @@ class View { return $this->removeMount($mount, $absolutePath); } if ($this->is_dir($path)) { - return $this->basicOperation('rmdir', $path, array('delete')); + $result = $this->basicOperation('rmdir', $path, array('delete')); } else { - return false; + $result = false; } + + if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete + $storage = $mount->getStorage(); + $internalPath = $mount->getInternalPath($absolutePath); + $storage->getUpdater()->remove($internalPath); + } + return $result; } /** @@ -429,7 +436,7 @@ class View { /** * @param string $path - * @param int $from + * @param int $from * @param int $to * @return bool|mixed * @throws \OCP\Files\InvalidPathException @@ -441,18 +448,18 @@ class View { $handle = $this->fopen($path, 'rb'); if ($handle) { if (fseek($handle, $from) === 0) { - $chunkSize = 8192; // 8 kB chunks - $end = $to + 1; - while (!feof($handle) && ftell($handle) < $end) { - $len = $end-ftell($handle); - if ($len > $chunkSize) { - $len = $chunkSize; + $chunkSize = 8192; // 8 kB chunks + $end = $to + 1; + while (!feof($handle) && ftell($handle) < $end) { + $len = $end - ftell($handle); + if ($len > $chunkSize) { + $len = $chunkSize; + } + echo fread($handle, $len); + flush(); } - echo fread($handle, $len); - flush(); - } - $size = ftell($handle) - $from; - return $size; + $size = ftell($handle) - $from; + return $size; } throw new \OCP\Files\UnseekableException('fseek error'); @@ -679,7 +686,13 @@ class View { if ($mount and $mount->getInternalPath($absolutePath) === '') { return $this->removeMount($mount, $absolutePath); } - return $this->basicOperation('unlink', $path, array('delete')); + $result = $this->basicOperation('unlink', $path, array('delete')); + if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete + $storage = $mount->getStorage(); + $internalPath = $mount->getInternalPath($absolutePath); + $storage->getUpdater()->remove($internalPath); + } + return $result; } /** -- cgit v1.2.3 From 14f96f86e7da12abd754d50abdac236f9b879e62 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Jun 2016 13:34:54 +0200 Subject: return success when deleting ghost files --- lib/private/Files/View.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 8a99bc609cf..e9daa123470 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -691,8 +691,10 @@ class View { $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($absolutePath); $storage->getUpdater()->remove($internalPath); + return true; + } else { + return $result; } - return $result; } /** -- cgit v1.2.3 From 6bc8305eddc1eeb9c80955e5b0444c670d794201 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Jun 2016 13:35:27 +0200 Subject: Fix warnings when trying to get mtime of non existing files --- lib/private/Files/Storage/Local.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index b07e26a3358..acd4c3b4838 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -157,7 +157,7 @@ class Local extends \OC\Files\Storage\Common { public function filemtime($path) { clearstatcache($this->getSourcePath($path)); - return filemtime($this->getSourcePath($path)); + return $this->file_exists($path) ? filemtime($this->getSourcePath($path)) : false; } public function touch($path, $mtime = null) { @@ -188,7 +188,7 @@ class Local extends \OC\Files\Storage\Common { return ''; } - $handle = fopen($fileName,'rb'); + $handle = fopen($fileName, 'rb'); $content = fread($handle, $fileSize); fclose($handle); return $content; @@ -377,7 +377,7 @@ class Local extends \OC\Files\Storage\Common { * @return bool */ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { - if($sourceStorage->instanceOfStorage('\OC\Files\Storage\Local')){ + if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Local')) { /** * @var \OC\Files\Storage\Local $sourceStorage */ -- cgit v1.2.3