summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2013-11-27 10:24:55 -0800
committerBjörn Schießle <bjoern@schiessle.org>2013-11-27 10:24:55 -0800
commit34a8c3c4cd7841e3a8b1730c580003736277e2d7 (patch)
tree2ee2458d727809be014b9283a0bd6ed6eb8118b8 /apps
parent39f9e16f2051b938c611eb5ce3ea871de9cb1cd9 (diff)
parentd2840a045d8d4e5996c847e8bbf93e80c111fdac (diff)
downloadnextcloud-server-34a8c3c4cd7841e3a8b1730c580003736277e2d7.tar.gz
nextcloud-server-34a8c3c4cd7841e3a8b1730c580003736277e2d7.zip
Merge pull request #6039 from owncloud/trashbin_move_file_to_owners_trash
move files to owners trash
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/appinfo/app.php1
-rw-r--r--apps/files_sharing/lib/updater.php7
-rw-r--r--apps/files_trashbin/lib/trashbin.php146
-rw-r--r--apps/files_versions/lib/versions.php1
4 files changed, 116 insertions, 39 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index bdaea64bb90..217bc005faf 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -14,6 +14,7 @@ OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
OCP\Util::addScript('files_sharing', 'share');
\OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Shared_Updater', 'writeHook');
+\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'postDeleteHook');
\OC_Hook::connect('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook');
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook');
\OC_Hook::connect('OCP\Share', 'post_shared', '\OC\Files\Cache\Shared_Updater', 'shareHook');
diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php
index 171999ea652..0c35b18c42b 100644
--- a/apps/files_sharing/lib/updater.php
+++ b/apps/files_sharing/lib/updater.php
@@ -89,9 +89,14 @@ class Shared_Updater {
*/
static public function deleteHook($params) {
self::correctFolders($params['path']);
- self::removeShare($params['path']);
}
+ /**
+ * @param array $params
+ */
+ static public function postDeleteHook($params) {
+ self::removeShare($params['path']);
+ }
/**
* @param array $params
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index f419f515f1e..bb6bdd547a0 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -41,13 +41,7 @@ class Trashbin {
return array($uid, $filename);
}
- /**
- * move file to the trash bin
- *
- * @param $file_path path to the deleted file/directory relative to the files root directory
- */
- public static function move2trash($file_path) {
- $user = \OCP\User::getUser();
+ private static function setUpTrash($user) {
$view = new \OC\Files\View('/' . $user);
if (!$view->is_dir('files_trashbin')) {
$view->mkdir('files_trashbin');
@@ -64,6 +58,48 @@ class Trashbin {
if (!$view->is_dir('files_trashbin/share-keys')) {
$view->mkdir('files_trashbin/share-keys');
}
+ }
+
+
+ private static function copyFilesToOwner($sourcePath, $owner, $ownerPath, $timestamp, $type, $mime) {
+ self::setUpTrash($owner);
+
+ $ownerFilename = basename($ownerPath);
+ $ownerLocation = dirname($ownerPath);
+
+ $sourceFilename = basename($sourcePath);
+
+ $view = new \OC\Files\View('/');
+
+ $source = \OCP\User::getUser().'/files_trashbin/files/' . $sourceFilename . '.d' . $timestamp;
+ $target = $owner.'/files_trashbin/files/' . $ownerFilename . '.d' . $timestamp;
+ self::copy_recursive($source, $target, $view);
+
+
+ if ($view->file_exists($target)) {
+ $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
+ $result = $query->execute(array($ownerFilename, $timestamp, $ownerLocation, $type, $mime, $owner));
+ if (!$result) { // if file couldn't be added to the database than also don't store it in the trash bin.
+ $view->deleteAll($owner.'/files_trashbin/files/' . $ownerFilename . '.d' . $timestamp);
+ \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated for the files owner', \OC_log::ERROR);
+ return;
+ }
+ }
+ }
+
+
+ /**
+ * move file to the trash bin
+ *
+ * @param $file_path path to the deleted file/directory relative to the files root directory
+ */
+ public static function move2trash($file_path) {
+ $user = \OCP\User::getUser();
+ $size = 0;
+ list($owner, $ownerPath) = self::getUidAndFilename($file_path);
+ self::setUpTrash($user);
+
+ $view = new \OC\Files\View('/' . $user);
$path_parts = pathinfo($file_path);
$filename = $path_parts['basename'];
@@ -77,19 +113,20 @@ class Trashbin {
$type = 'file';
}
- $trashbinSize = self::getTrashbinSize($user);
- if ($trashbinSize === false || $trashbinSize < 0) {
- $trashbinSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin'));
+ $userTrashSize = self::getTrashbinSize($user);
+ if ($userTrashSize === false || $userTrashSize < 0) {
+ $userTrashSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin'));
}
// disable proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
- $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/' . $filename . '.d' . $timestamp, $view);
+ $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
+ $sizeOfAddedFiles = self::copy_recursive('/files/'.$file_path, $trashPath, $view);
\OC_FileProxy::$enabled = $proxyStatus;
if ($view->file_exists('files_trashbin/files/' . $filename . '.d' . $timestamp)) {
- $trashbinSize += $sizeOfAddedFiles;
+ $size = $sizeOfAddedFiles;
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
$result = $query->execute(array($filename, $timestamp, $location, $type, $mime, $user));
if (!$result) { // if file couldn't be added to the database than also don't store it in the trash bin.
@@ -100,15 +137,31 @@ class Trashbin {
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path),
'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
- $trashbinSize += self::retainVersions($file_path, $filename, $timestamp);
- $trashbinSize += self::retainEncryptionKeys($file_path, $filename, $timestamp);
+ $size += self::retainVersions($file_path, $filename, $timestamp);
+ $size += self::retainEncryptionKeys($file_path, $filename, $timestamp);
+
+ // if owner !== user we need to also add a copy to the owners trash
+ if ($user !== $owner) {
+ self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp, $type, $mime);
+ }
} else {
\OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
}
- $trashbinSize -= self::expire($trashbinSize);
+ $userTrashSize += $size;
+ $userTrashSize -= self::expire($userTrashSize, $user);
+ self::setTrashbinSize($user, $userTrashSize);
- self::setTrashbinSize($user, $trashbinSize);
+ // if owner !== user we also need to update the owners trash size
+ if($owner !== $user) {
+ $ownerTrashSize = self::getTrashbinSize($owner);
+ if ($ownerTrashSize === false || $ownerTrashSize < 0) {
+ $ownerTrashSize = self::calculateSize(new \OC\Files\View('/' . $owner . '/files_trashbin'));
+ }
+ $ownerTrashSize += $size;
+ $ownerTrashSize -= self::expire($ownerTrashSize, $owner);
+ self::setTrashbinSize($owner, $ownerTrashSize);
+ }
}
/**
@@ -135,10 +188,16 @@ class Trashbin {
if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) {
$size += self::calculateSize(new \OC\Files\View('/' . $owner . '/files_versions/' . $ownerPath));
+ if ($owner !== $user) {
+ $rootView->copy($owner . '/files_versions/' . $ownerPath, $owner . '/files_trashbin/versions/' . basename($ownerPath) . '.d' . $timestamp);
+ }
$rootView->rename($owner . '/files_versions/' . $ownerPath, $user . '/files_trashbin/versions/' . $filename . '.d' . $timestamp);
} else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) {
foreach ($versions as $v) {
$size += $rootView->filesize($owner . '/files_versions' . $v['path'] . '.v' . $v['version']);
+ if ($owner !== $user) {
+ $rootView->copy($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $owner . '/files_trashbin/versions/' . $v['name'] . '.v' . $v['version'] . '.d' . $timestamp);
+ }
$rootView->rename($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp);
}
}
@@ -187,9 +246,15 @@ class Trashbin {
// move keyfiles
if ($rootView->is_dir($keyfile)) {
$size += self::calculateSize(new \OC\Files\View($keyfile));
+ if ($owner !== $user) {
+ $rootView->copy($keyfile, $owner . '/files_trashbin/keyfiles/' . basename($ownerPath) . '.d' . $timestamp);
+ }
$rootView->rename($keyfile, $user . '/files_trashbin/keyfiles/' . $filename . '.d' . $timestamp);
} else {
$size += $rootView->filesize($keyfile . '.key');
+ if ($owner !== $user) {
+ $rootView->copy($keyfile . '.key', $owner . '/files_trashbin/keyfiles/' . basename($ownerPath) . '.key.d' . $timestamp);
+ }
$rootView->rename($keyfile . '.key', $user . '/files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp);
}
}
@@ -199,6 +264,9 @@ class Trashbin {
if ($rootView->is_dir($sharekeys)) {
$size += self::calculateSize(new \OC\Files\View($sharekeys));
+ if ($owner !== $user) {
+ $rootView->copy($sharekeys, $owner . '/files_trashbin/share-keys/' . basename($ownerPath) . '.d' . $timestamp);
+ }
$rootView->rename($sharekeys, $user . '/files_trashbin/share-keys/' . $filename . '.d' . $timestamp);
} else {
// get local path to share-keys
@@ -211,22 +279,23 @@ class Trashbin {
// get source file parts
$pathinfo = pathinfo($src);
- // we only want to keep the owners key so we can access the private key
- $ownerShareKey = $filename . '.' . $user . '.shareKey';
+ // we only want to keep the users key so we can access the private key
+ $userShareKey = $filename . '.' . $user . '.shareKey';
// if we found the share-key for the owner, we need to move it to files_trashbin
- if ($pathinfo['basename'] == $ownerShareKey) {
+ if ($pathinfo['basename'] == $userShareKey) {
// calculate size
$size += $rootView->filesize($sharekeys . '.' . $user . '.shareKey');
// move file
- $rootView->rename($sharekeys . '.' . $user . '.shareKey', $user . '/files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp);
+ $rootView->rename($sharekeys . '.' . $user . '.shareKey', $user . '/files_trashbin/share-keys/' . $userShareKey . '.d' . $timestamp);
+ } elseif ($owner !== $user) {
+ $ownerShareKey = basename($ownerPath) . '.' . $owner . '.shareKey';
+ if ($pathinfo['basename'] == $ownerShareKey) {
+ $rootView->rename($sharekeys . '.' . $owner . '.shareKey', $owner . '/files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp);
+ }
} else {
-
- // calculate size
- $size += filesize($src);
-
// don't keep other share-keys
unlink($src);
}
@@ -679,7 +748,7 @@ class Trashbin {
$freeSpace = self::calculateFreeSpace($size);
if ($freeSpace < 0) {
- $newSize = $size - self::expire($size);
+ $newSize = $size - self::expire($size, $user);
if ($newSize !== $size) {
self::setTrashbinSize($user, $newSize);
}
@@ -688,10 +757,11 @@ class Trashbin {
/**
* clean up the trash bin
- * @param current size of the trash bin
- * @return size of expired files
+ * @param int $trashbinSize current size of the trash bin
+ * @param string $user
+ * @return int size of expired files
*/
- private static function expire($trashbinSize) {
+ private static function expire($trashbinSize, $user) {
$user = \OCP\User::getUser();
$view = new \OC\Files\View('/' . $user);
@@ -742,23 +812,23 @@ class Trashbin {
*/
private static function copy_recursive($source, $destination, $view) {
$size = 0;
- if ($view->is_dir('files' . $source)) {
+ if ($view->is_dir($source)) {
$view->mkdir($destination);
- $view->touch($destination, $view->filemtime('files' . $source));
- foreach (\OC_Files::getDirectoryContent($source) as $i) {
+ $view->touch($destination, $view->filemtime($source));
+ foreach ($view->getDirectoryContent($source) as $i) {
$pathDir = $source . '/' . $i['name'];
- if ($view->is_dir('files' . $pathDir)) {
+ if ($view->is_dir($pathDir)) {
$size += self::copy_recursive($pathDir, $destination . '/' . $i['name'], $view);
} else {
- $size += $view->filesize('files' . $pathDir);
- $view->copy('files' . $pathDir, $destination . '/' . $i['name']);
- $view->touch($destination . '/' . $i['name'], $view->filemtime('files' . $pathDir));
+ $size += $view->filesize($pathDir);
+ $view->copy($pathDir, $destination . '/' . $i['name']);
+ $view->touch($destination . '/' . $i['name'], $view->filemtime($pathDir));
}
}
} else {
- $size += $view->filesize('files' . $source);
- $view->copy('files' . $source, $destination);
- $view->touch($destination, $view->filemtime('files' . $source));
+ $size += $view->filesize($source);
+ $view->copy($source, $destination);
+ $view->touch($destination, $view->filemtime($source));
}
return $size;
}
diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php
index b03e1d4e93a..3ad73284ef2 100644
--- a/apps/files_versions/lib/versions.php
+++ b/apps/files_versions/lib/versions.php
@@ -263,6 +263,7 @@ class Storage {
$versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($version);
$versions[$key]['preview'] = \OCP\Util::linkToRoute('core_ajax_versions_preview', array('file' => $filename, 'version' => $version, 'user' => $uid));
$versions[$key]['path'] = $filename;
+ $versions[$key]['name'] = $versionedFile;
$versions[$key]['size'] = $file['size'];
}
}