diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-04-01 15:12:59 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-04-13 17:10:01 +0200 |
commit | d7b3a1a35a47dd37f68f7819aa0789b794e352e5 (patch) | |
tree | 79b377310bb6b8b3b822889aabc345d43ca974c8 /lib/private/files/cache/cache.php | |
parent | a88e013f722a2bf30100074760509613c76ca807 (diff) | |
download | nextcloud-server-d7b3a1a35a47dd37f68f7819aa0789b794e352e5.tar.gz nextcloud-server-d7b3a1a35a47dd37f68f7819aa0789b794e352e5.zip |
preserve cache data when doing a cross storage move
Diffstat (limited to 'lib/private/files/cache/cache.php')
-rw-r--r-- | lib/private/files/cache/cache.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index c5e118946e5..fd4c5715a67 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -464,6 +464,43 @@ class Cache { } /** + * Move a file or folder in the cache + * + * @param \OC\Files\Cache\Cache $sourceCache + * @param string $sourcePath + * @param string $targetPath + * @throws \OC\DatabaseException + */ + public function moveFromCache(Cache $sourceCache, $sourcePath, $targetPath) { + // normalize source and target + $sourcePath = $this->normalize($sourcePath); + $targetPath = $this->normalize($targetPath); + + $sourceData = $sourceCache->get($sourcePath); + $sourceId = $sourceData['fileid']; + $newParentId = $this->getParentId($targetPath); + + if ($sourceData['mimetype'] === 'httpd/unix-directory') { + //find all child entries + $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?'; + $result = \OC_DB::executeAudited($sql, [$sourceCache->getNumericStorageId(), $sourcePath . '/%']); + $childEntries = $result->fetchAll(); + $sourceLength = strlen($sourcePath); + \OC_DB::beginTransaction(); + $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?'); + + foreach ($childEntries as $child) { + $newTargetPath = $targetPath . substr($child['path'], $sourceLength); + \OC_DB::executeAudited($query, [$this->getNumericStorageId(), $newTargetPath, md5($newTargetPath), $child['fileid']]); + } + \OC_DB::commit(); + } + + $sql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?'; + \OC_DB::executeAudited($sql, [$this->getNumericStorageId(), $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]); + } + + /** * remove all entries for files that are stored on the storage from the cache */ public function clear() { |