From b117a1e3ec4bee5365db2a2363b21013e9b027e0 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Mon, 4 Jun 2012 17:59:21 +0200
Subject: [PATCH] update file paths in filecache when the parent is renamed

---
 lib/filecache.php | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/filecache.php b/lib/filecache.php
index a94349e19cb..cef1ea04729 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -169,6 +169,15 @@ class OC_FileCache{
 		$newParent=self::getParentId($newPath);
 		$query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=?, path_hash=? WHERE path_hash=?');
 		$query->execute(array($newParent,basename($newPath),$newPath,md5($newPath),md5($oldPath)));
+
+		$query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE path LIKE ?');
+		$oldLength=strlen($oldPath);
+		$updateQuery=OC_DB::prepare('UPDATE *PREFIX*fscache SET path=?, path_hash=? WHERE path_hash=?');
+		while($row= $query->execute(array($oldPath.'/%'))->fetchRow()){
+			$old=$row['path'];
+			$new=$newPath.substr($old,$oldLength);
+			$updateQuery->execute(array($new,md5($new),md5($old)));
+		}
 	}
 
 	/**
-- 
GitLab