diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-02-25 12:44:44 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-02-26 15:11:37 +0100 |
commit | 232de3bdc093e839048d5b00d7f08ecc87ba7908 (patch) | |
tree | 67e9cc622e69a6cdd0aa239554d5149059b65bbc /lib | |
parent | 20738d287e456ddb05a617f6b808f152cc3028a9 (diff) | |
download | nextcloud-server-232de3bdc093e839048d5b00d7f08ecc87ba7908.tar.gz nextcloud-server-232de3bdc093e839048d5b00d7f08ecc87ba7908.zip |
Delete target file for unsuccessful copy/rename
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/view.php | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 7de7ef7b32c..e4732f8bb3d 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -574,8 +574,11 @@ class View { } /** - * @param string $path1 - * @param string $path2 + * Rename/move a file or folder from the source path to target path. + * + * @param string $path1 source path + * @param string $path2 target path + * * @return bool|mixed */ public function rename($path1, $path2) { @@ -617,7 +620,7 @@ class View { $mount = $manager->find($absolutePath1 . $postFix1); $storage1 = $mount->getStorage(); $internalPath1 = $mount->getInternalPath($absolutePath1 . $postFix1); - list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2); + list($storage2, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2); if ($internalPath1 === '' and $mount instanceof MoveableMount) { if ($this->isTargetAllowed($absolutePath2)) { /** @@ -646,8 +649,10 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - list($count, $result) = \OC_Helper::streamCopy($source, $target); - $this->touch($path2, $this->filemtime($path1)); + list(, $result) = \OC_Helper::streamCopy($source, $target); + if ($result !== false) { + $this->touch($path2, $this->filemtime($path1)); + } // close open handle - especially $source is necessary because unlink below will // throw an exception on windows because the file is locked @@ -656,6 +661,11 @@ class View { if ($result !== false) { $result &= $storage1->unlink($internalPath1); + } else { + // delete partially written target file + $storage2->unlink($internalPath2); + // delete cache entry that was created by fopen + $storage2->getCache()->remove($internalPath2); } } } @@ -688,9 +698,12 @@ class View { } /** - * @param string $path1 - * @param string $path2 - * @param bool $preserveMtime + * Copy a file/folder from the source path to target path + * + * @param string $path1 source path + * @param string $path2 target path + * @param bool $preserveMtime whether to preserve mtime on the copy + * * @return bool|mixed */ public function copy($path1, $path2, $preserveMtime = false) { @@ -732,6 +745,11 @@ class View { list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2); if ($storage) { $result = $storage->copy($internalPath1, $internalPath2); + if (!$result) { + // delete partially written target file + $storage->unlink($internalPath2); + $storage->getCache()->remove($internalPath2); + } } else { $result = false; } @@ -749,14 +767,20 @@ class View { } } } else { + list($storage2, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2); $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - list($count, $result) = \OC_Helper::streamCopy($source, $target); - if($preserveMtime) { + list(, $result) = \OC_Helper::streamCopy($source, $target); + if($result && $preserveMtime) { $this->touch($path2, $this->filemtime($path1)); } fclose($source); fclose($target); + if (!$result) { + // delete partially written target file + $storage2->unlink($internalPath2); + $storage2->getCache()->remove($internalPath2); + } } } $this->updater->update($path2); |