From 3c100af1329c1c101f38f23f2d74710954387fdf Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 1 May 2013 01:38:06 +0200 Subject: revert changes to fbbc76f281f50afa3072d99e4e0d413df835b3d3 because master is very unstable right now --- apps/files_trashbin/l10n/id.php | 8 +- apps/files_trashbin/l10n/nn_NO.php | 5 - apps/files_trashbin/l10n/pl.php | 4 +- apps/files_trashbin/l10n/pt_PT.php | 2 +- apps/files_trashbin/l10n/ro.php | 1 - apps/files_trashbin/l10n/sk_SK.php | 2 +- apps/files_trashbin/lib/trash.php | 395 ++++++++----------------------------- 7 files changed, 94 insertions(+), 323 deletions(-) (limited to 'apps/files_trashbin') diff --git a/apps/files_trashbin/l10n/id.php b/apps/files_trashbin/l10n/id.php index 62a63d515a3..e06c66784f2 100644 --- a/apps/files_trashbin/l10n/id.php +++ b/apps/files_trashbin/l10n/id.php @@ -2,13 +2,13 @@ "Couldn't delete %s permanently" => "Tidak dapat menghapus permanen %s", "Couldn't restore %s" => "Tidak dapat memulihkan %s", "perform restore operation" => "jalankan operasi pemulihan", -"Error" => "Galat", +"Error" => "kesalahan", "delete file permanently" => "hapus berkas secara permanen", -"Delete permanently" => "Hapus secara permanen", +"Delete permanently" => "hapus secara permanen", "Name" => "Nama", "Deleted" => "Dihapus", -"1 folder" => "1 folder", -"{count} folders" => "{count} folder", +"1 folder" => "1 map", +"{count} folders" => "{count} map", "1 file" => "1 berkas", "{count} files" => "{count} berkas", "Nothing in here. Your trash bin is empty!" => "Tempat sampah anda kosong!", diff --git a/apps/files_trashbin/l10n/nn_NO.php b/apps/files_trashbin/l10n/nn_NO.php index 8166a024e58..14345ddcc4d 100644 --- a/apps/files_trashbin/l10n/nn_NO.php +++ b/apps/files_trashbin/l10n/nn_NO.php @@ -1,10 +1,5 @@ "Feil", -"Delete permanently" => "Slett for godt", "Name" => "Namn", -"1 folder" => "1 mappe", -"{count} folders" => "{count} mapper", -"1 file" => "1 fil", -"{count} files" => "{count} filer", "Delete" => "Slett" ); diff --git a/apps/files_trashbin/l10n/pl.php b/apps/files_trashbin/l10n/pl.php index 5c9f558f11f..7fd1ab21ecd 100644 --- a/apps/files_trashbin/l10n/pl.php +++ b/apps/files_trashbin/l10n/pl.php @@ -8,9 +8,9 @@ "Name" => "Nazwa", "Deleted" => "Usunięte", "1 folder" => "1 folder", -"{count} folders" => "Ilość folderów: {count}", +"{count} folders" => "{count} foldery", "1 file" => "1 plik", -"{count} files" => "Ilość plików: {count}", +"{count} files" => "{count} pliki", "Nothing in here. Your trash bin is empty!" => "Nic tu nie ma. Twój kosz jest pusty!", "Restore" => "Przywróć", "Delete" => "Usuń", diff --git a/apps/files_trashbin/l10n/pt_PT.php b/apps/files_trashbin/l10n/pt_PT.php index ba85158b70e..7dfe610466b 100644 --- a/apps/files_trashbin/l10n/pt_PT.php +++ b/apps/files_trashbin/l10n/pt_PT.php @@ -13,6 +13,6 @@ "{count} files" => "{count} ficheiros", "Nothing in here. Your trash bin is empty!" => "Não hà ficheiros. O lixo está vazio!", "Restore" => "Restaurar", -"Delete" => "Eliminar", +"Delete" => "Apagar", "Deleted Files" => "Ficheiros Apagados" ); diff --git a/apps/files_trashbin/l10n/ro.php b/apps/files_trashbin/l10n/ro.php index 3af21b7e3f3..c03ef600f35 100644 --- a/apps/files_trashbin/l10n/ro.php +++ b/apps/files_trashbin/l10n/ro.php @@ -1,6 +1,5 @@ "Eroare", -"Delete permanently" => "Stergere permanenta", "Name" => "Nume", "1 folder" => "1 folder", "{count} folders" => "{count} foldare", diff --git a/apps/files_trashbin/l10n/sk_SK.php b/apps/files_trashbin/l10n/sk_SK.php index 7cef36ef1c0..7203f4c75fc 100644 --- a/apps/files_trashbin/l10n/sk_SK.php +++ b/apps/files_trashbin/l10n/sk_SK.php @@ -5,7 +5,7 @@ "Error" => "Chyba", "delete file permanently" => "trvalo zmazať súbor", "Delete permanently" => "Zmazať trvalo", -"Name" => "Názov", +"Name" => "Meno", "Deleted" => "Zmazané", "1 folder" => "1 priečinok", "{count} folders" => "{count} priečinkov", diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 88c71a75ab0..f0b56eef014 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -39,15 +39,14 @@ class Trashbin { $view = new \OC\Files\View('/'. $user); if (!$view->is_dir('files_trashbin')) { $view->mkdir('files_trashbin'); - $view->mkdir('files_trashbin/files'); - $view->mkdir('files_trashbin/versions'); - $view->mkdir('files_trashbin/keyfiles'); - $view->mkdir('files_trashbin/share-keys'); + $view->mkdir("files_trashbin/files"); + $view->mkdir("files_trashbin/versions"); + $view->mkdir("files_trashbin/keyfiles"); } $path_parts = pathinfo($file_path); - $filename = $path_parts['basename']; + $deleted = $path_parts['basename']; $location = $path_parts['dirname']; $timestamp = time(); $mime = $view->getMimeType('files'.$file_path); @@ -63,24 +62,45 @@ class Trashbin { $trashbinSize = self::calculateSize(new \OC\Files\View('/'. $user.'/files_trashbin')); } - $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$filename.'.d'.$timestamp, $view); - - if ( $view->file_exists('files_trashbin/files/'.$filename.'.d'.$timestamp) ) { + $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$deleted.'.d'.$timestamp, $view); + + if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) { $trashbinSize += $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)); + $result = $query->execute(array($deleted, $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. - $view->deleteAll('files_trashbin/files/'.$filename.'.d'.$timestamp); + $view->deleteAll('files_trashbin/files/'.$deleted.'.d'.$timestamp); \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR); return; } \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($view, $file_path, $filename, $timestamp); - $trashbinSize += self::retainEncryptionKeys($view, $file_path, $filename, $timestamp); - + 'trashPath' => \OC\Files\Filesystem::normalizePath($deleted.'.d'.$timestamp))); + + // Take care of file versions + if ( \OCP\App::isEnabled('files_versions') ) { + if ( $view->is_dir('files_versions/'.$file_path) ) { + $trashbinSize += self::calculateSize(new \OC\Files\View('/'. $user.'/files_versions/'.$file_path)); + $view->rename('files_versions/'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp); + } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path) ) { + foreach ($versions as $v) { + $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']); + $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions/'. $deleted.'.v'.$v['version'].'.d'.$timestamp); + } + } + } + + // Take care of encryption keys + $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/'.$file_path); + if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile.'.key') ) { + if ( $view->is_dir('files'.$file_path) ) { + $trashbinSize += self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile)); + $view->rename($keyfile, 'files_trashbin/keyfiles/'. $deleted.'.d'.$timestamp); + } else { + $trashbinSize += $view->filesize($keyfile.'.key'); + $view->rename($keyfile.'.key', 'files_trashbin/keyfiles/'. $deleted.'.key.d'.$timestamp); + } + } } else { \OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR); } @@ -91,134 +111,15 @@ class Trashbin { } - /** - * Move file versions to trash so that they can be restored later - * - * @param \OC\Files\View $view - * @param $file_path path to original file - * @param $filename of deleted file - * @param $timestamp when the file was deleted - * - * @return size of stored versions - */ - private static function retainVersions($view, $file_path, $filename, $timestamp) { - $size = 0; - if (\OCP\App::isEnabled('files_versions')) { - - // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; - - $user = \OCP\User::getUser(); - if ($view->is_dir('files_versions/' . $file_path)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/files_versions/' . $file_path)); - $view->rename('files_versions/' . $file_path, 'files_trashbin/versions/' . $filename . '.d' . $timestamp); - } else if ($versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path)) { - foreach ($versions as $v) { - $size += $view->filesize('files_versions' . $v['path'] . '.v' . $v['version']); - $view->rename('files_versions' . $v['path'] . '.v' . $v['version'], 'files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); - } - } - - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - } - - return $size; - } - - /** - * Move encryption keys to trash so that they can be restored later - * - * @param \OC\Files\View $view - * @param $file_path path to original file - * @param $filename of deleted file - * @param $timestamp when the file was deleted - * - * @return size of encryption keys - */ - private static function retainEncryptionKeys($view, $file_path, $filename, $timestamp) { - $size = 0; - - if (\OCP\App::isEnabled('files_encryption')) { - - $user = \OCP\User::getUser(); - - // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; - - // retain key files - $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path); - - if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) { - $user = \OCP\User::getUser(); - // move keyfiles - if ($view->is_dir($keyfile)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); - $view->rename($keyfile, 'files_trashbin/keyfiles/' . $filename . '.d' . $timestamp); - } else { - $size += $view->filesize($keyfile . '.key'); - $view->rename($keyfile . '.key', 'files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp); - } - } - - // retain share keys - $sharekeys = \OC\Files\Filesystem::normalizePath('files_encryption/share-keys/' . $file_path); - - if ($view->is_dir($sharekeys)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys)); - $view->rename($sharekeys, 'files_trashbin/share-keys/' . $filename . '.d' . $timestamp); - } else { - // get local path to share-keys - $localShareKeysPath = $view->getLocalFile($sharekeys); - - // handle share-keys - $matches = glob(preg_quote($localShareKeysPath).'*.shareKey'); - foreach ($matches as $src) { - // 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'; - - // if we found the share-key for the owner, we need to move it to files_trashbin - if($pathinfo['basename'] == $ownerShareKey) { - - // calculate size - $size += $view->filesize($sharekeys. '.' . $user. '.shareKey'); - - // move file - $view->rename($sharekeys. '.' . $user. '.shareKey', 'files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp); - } else { - - // calculate size - $size += filesize($src); - - // don't keep other share-keys - unlink($src); - } - } - - } - - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - } - return $size; - } /** * restore files from trash bin * @param $file path to the deleted file * @param $filename name of the file * @param $timestamp time when the file was deleted - * - * @return bool - */ + */ public static function restore($file, $filename, $timestamp) { - - $user = \OCP\User::getUser(); + $user = \OCP\User::getUser(); $view = new \OC\Files\View('/'.$user); $trashbinSize = self::getTrashbinSize($user); @@ -256,17 +157,8 @@ class Trashbin { // we need a extension in case a file/dir with the same name already exists $ext = self::getUniqueExtension($location, $filename, $view); $mtime = $view->filemtime($source); - - // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; - - // restore file - $restoreResult = $view->rename($source, $target.$ext); - - // handle the restore result - if( $restoreResult ) { - $view->touch($target.$ext, $mtime); + if( $view->rename($source, $target.$ext) ) { + $view->touch($target.$ext, $mtime); \OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', array('filePath' => \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext), 'trashPath' => \OC\Files\Filesystem::normalizePath($file))); @@ -275,183 +167,68 @@ class Trashbin { } else { $trashbinSize -= $view->filesize($target.$ext); } - - $trashbinSize -= self::restoreVersions($view, $file, $filename, $ext, $location, $timestamp); - $trashbinSize -= self::restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp); - + // if versioning app is enabled, copy versions from the trash bin back to the original location + if ( \OCP\App::isEnabled('files_versions') ) { + if ($timestamp ) { + $versionedFile = $filename; + } else { + $versionedFile = $file; + } + if ( $result[0]['type'] === 'dir' ) { + $trashbinSize -= self::calculateSize(new \OC\Files\View('/'.$user.'/'.'files_trashbin/versions/'. $file)); + $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/'. $file), \OC\Files\Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext)); + } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) { + foreach ($versions as $v) { + if ($timestamp ) { + $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp); + $view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); + } else { + $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v); + $view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); + } + } + } + } + + // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!) + $parts = pathinfo($file); + if ( $result[0]['type'] === 'dir' ) { + $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$parts['dirname'].'/'.$filename); + } else { + $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$parts['dirname'].'/'.$filename.'.key'); + } + if ($timestamp) { + $keyfile .= '.d'.$timestamp; + } + if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) { + if ( $result[0]['type'] === 'dir' ) { + $trashbinSize -= self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile)); + $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename); + } else { + $trashbinSize -= $view->filesize($keyfile); + $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename.'.key'); + } + } + if ( $timestamp ) { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=? AND `id`=? AND `timestamp`=?'); $query->execute(array($user,$filename,$timestamp)); } self::setTrashbinSize($user, $trashbinSize); - - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - + return true; + } else { + \OC_Log::write('files_trashbin', 'Couldn\'t restore file from trash bin, '.$filename, \OC_log::ERROR); } - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - return false; } - /** - * @brief restore versions from trash bin - * - * @param \OC\Files\View $view file view - * @param $file complete path to file - * @param $filename name of file - * @param $ext file extension in case a file with the same $filename already exists - * @param $location location if file - * @param $timestamp deleteion time - * - * @return size of restored versions - */ - private static function restoreVersions($view, $file, $filename, $ext, $location, $timestamp) { - $size = 0; - if (\OCP\App::isEnabled('files_versions')) { - // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; - - $user = \OCP\User::getUser(); - if ($timestamp) { - $versionedFile = $filename; - } else { - $versionedFile = $file; - } - - if ($view->is_dir('/files_trashbin/versions/'.$file)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . 'files_trashbin/versions/' . $file)); - $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath('files_versions/' . $location . '/' . $filename . $ext)); - } else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp)) { - foreach ($versions as $v) { - if ($timestamp) { - $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp); - $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); - } else { - $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v); - $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); - } - } - } - - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - } - return $size; - } - - - /** - * @brief restore encryption keys from trash bin - * - * @param \OC\Files\View $view - * @param $file complete path to file - * @param $filename name of file - * @param $ext file extension in case a file with the same $filename already exists - * @param $location location if file - * @param $timestamp deleteion time - * - * @return size of restored encrypted file - */ - private static function restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp) { - // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!) - $size = 0; - if (\OCP\App::isEnabled('files_encryption')) { - $user = \OCP\User::getUser(); - - $path_parts = pathinfo($file); - $source_location = $path_parts['dirname']; - - if ($view->is_dir('/files_trashbin/keyfiles/'.$file)) { - if($source_location != '.') { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename); - $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename); - } else { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename); - $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename); - } - } else { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key'); - } - - if ($timestamp) { - $keyfile .= '.d' . $timestamp; - } - - // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; - - if ($view->file_exists($keyfile)) { - // handle directory - if ($view->is_dir($keyfile)) { - - // handle keyfiles - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); - $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext); - - // handle share-keys - if ($timestamp) { - $sharekey .= '.d' . $timestamp; - } - $view->rename($sharekey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext); - - } else { - // handle keyfiles - $size += $view->filesize($keyfile); - $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext . '.key'); - - // handle share-keys - $ownerShareKey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey'); - if ($timestamp) { - $ownerShareKey .= '.d' . $timestamp; - } - - $size += $view->filesize($ownerShareKey); - - // move only owners key - $view->rename($ownerShareKey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext . '.' . $user. '.shareKey'); - - // try to re-share if file is shared - $filesystemView = new \OC_FilesystemView('/'); - $session = new \OCA\Encryption\Session($filesystemView); - $util = new \OCA\Encryption\Util($filesystemView, $user); - - // fix the file size - $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $user . '/files/'. $location. '/' .$filename); - $util->fixFileSize($absolutePath); - - // get current sharing state - $sharingEnabled = \OCP\Share::isEnabled(); - - // get the final filename - $target = \OC\Files\Filesystem::normalizePath($location.'/'.$filename); - - // get users sharing this file - $usersSharing = $util->getSharingUsersArray($sharingEnabled, $target.$ext, $user); - - // Attempt to set shareKey - $util->setSharedFileKeyfiles($session, $usersSharing, $target.$ext); - } - } - - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - } - return $size; - } - /** - * @brief delete file from trash bin permanently - * + * delete file from trash bin permanently * @param $filename path to the file * @param $timestamp of deletion time - * * @return size of deleted files */ public static function delete($filename, $timestamp=null) { -- cgit v1.2.3 From 9f8f052f0d429d24c91ae1f68f7a534cb50f3775 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 1 May 2013 01:52:06 +0200 Subject: merged files_trashbin --- apps/files_trashbin/lib/trash.php | 395 +++++++++++++++++++++++++++++--------- 1 file changed, 309 insertions(+), 86 deletions(-) (limited to 'apps/files_trashbin') diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index f0b56eef014..88c71a75ab0 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -39,14 +39,15 @@ class Trashbin { $view = new \OC\Files\View('/'. $user); if (!$view->is_dir('files_trashbin')) { $view->mkdir('files_trashbin'); - $view->mkdir("files_trashbin/files"); - $view->mkdir("files_trashbin/versions"); - $view->mkdir("files_trashbin/keyfiles"); + $view->mkdir('files_trashbin/files'); + $view->mkdir('files_trashbin/versions'); + $view->mkdir('files_trashbin/keyfiles'); + $view->mkdir('files_trashbin/share-keys'); } $path_parts = pathinfo($file_path); - $deleted = $path_parts['basename']; + $filename = $path_parts['basename']; $location = $path_parts['dirname']; $timestamp = time(); $mime = $view->getMimeType('files'.$file_path); @@ -62,45 +63,24 @@ class Trashbin { $trashbinSize = self::calculateSize(new \OC\Files\View('/'. $user.'/files_trashbin')); } - $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$deleted.'.d'.$timestamp, $view); - - if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) { + $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$filename.'.d'.$timestamp, $view); + + if ( $view->file_exists('files_trashbin/files/'.$filename.'.d'.$timestamp) ) { $trashbinSize += $sizeOfAddedFiles; $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)"); - $result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user)); + $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. - $view->deleteAll('files_trashbin/files/'.$deleted.'.d'.$timestamp); + $view->deleteAll('files_trashbin/files/'.$filename.'.d'.$timestamp); \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR); return; } \OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path), - 'trashPath' => \OC\Files\Filesystem::normalizePath($deleted.'.d'.$timestamp))); - - // Take care of file versions - if ( \OCP\App::isEnabled('files_versions') ) { - if ( $view->is_dir('files_versions/'.$file_path) ) { - $trashbinSize += self::calculateSize(new \OC\Files\View('/'. $user.'/files_versions/'.$file_path)); - $view->rename('files_versions/'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp); - } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path) ) { - foreach ($versions as $v) { - $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']); - $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions/'. $deleted.'.v'.$v['version'].'.d'.$timestamp); - } - } - } - - // Take care of encryption keys - $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/'.$file_path); - if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile.'.key') ) { - if ( $view->is_dir('files'.$file_path) ) { - $trashbinSize += self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile)); - $view->rename($keyfile, 'files_trashbin/keyfiles/'. $deleted.'.d'.$timestamp); - } else { - $trashbinSize += $view->filesize($keyfile.'.key'); - $view->rename($keyfile.'.key', 'files_trashbin/keyfiles/'. $deleted.'.key.d'.$timestamp); - } - } + 'trashPath' => \OC\Files\Filesystem::normalizePath($filename.'.d'.$timestamp))); + + $trashbinSize += self::retainVersions($view, $file_path, $filename, $timestamp); + $trashbinSize += self::retainEncryptionKeys($view, $file_path, $filename, $timestamp); + } else { \OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR); } @@ -111,15 +91,134 @@ class Trashbin { } + /** + * Move file versions to trash so that they can be restored later + * + * @param \OC\Files\View $view + * @param $file_path path to original file + * @param $filename of deleted file + * @param $timestamp when the file was deleted + * + * @return size of stored versions + */ + private static function retainVersions($view, $file_path, $filename, $timestamp) { + $size = 0; + if (\OCP\App::isEnabled('files_versions')) { + + // disable proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + $user = \OCP\User::getUser(); + if ($view->is_dir('files_versions/' . $file_path)) { + $size += self::calculateSize(new \OC\Files\View('/' . $user . '/files_versions/' . $file_path)); + $view->rename('files_versions/' . $file_path, 'files_trashbin/versions/' . $filename . '.d' . $timestamp); + } else if ($versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path)) { + foreach ($versions as $v) { + $size += $view->filesize('files_versions' . $v['path'] . '.v' . $v['version']); + $view->rename('files_versions' . $v['path'] . '.v' . $v['version'], 'files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); + } + } + + // enable proxy + \OC_FileProxy::$enabled = $proxyStatus; + } + + return $size; + } + + /** + * Move encryption keys to trash so that they can be restored later + * + * @param \OC\Files\View $view + * @param $file_path path to original file + * @param $filename of deleted file + * @param $timestamp when the file was deleted + * + * @return size of encryption keys + */ + private static function retainEncryptionKeys($view, $file_path, $filename, $timestamp) { + $size = 0; + + if (\OCP\App::isEnabled('files_encryption')) { + + $user = \OCP\User::getUser(); + + // disable proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + // retain key files + $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path); + + if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) { + $user = \OCP\User::getUser(); + // move keyfiles + if ($view->is_dir($keyfile)) { + $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); + $view->rename($keyfile, 'files_trashbin/keyfiles/' . $filename . '.d' . $timestamp); + } else { + $size += $view->filesize($keyfile . '.key'); + $view->rename($keyfile . '.key', 'files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp); + } + } + + // retain share keys + $sharekeys = \OC\Files\Filesystem::normalizePath('files_encryption/share-keys/' . $file_path); + + if ($view->is_dir($sharekeys)) { + $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys)); + $view->rename($sharekeys, 'files_trashbin/share-keys/' . $filename . '.d' . $timestamp); + } else { + // get local path to share-keys + $localShareKeysPath = $view->getLocalFile($sharekeys); + + // handle share-keys + $matches = glob(preg_quote($localShareKeysPath).'*.shareKey'); + foreach ($matches as $src) { + // 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'; + + // if we found the share-key for the owner, we need to move it to files_trashbin + if($pathinfo['basename'] == $ownerShareKey) { + + // calculate size + $size += $view->filesize($sharekeys. '.' . $user. '.shareKey'); + + // move file + $view->rename($sharekeys. '.' . $user. '.shareKey', 'files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp); + } else { + + // calculate size + $size += filesize($src); + + // don't keep other share-keys + unlink($src); + } + } + + } + + // enable proxy + \OC_FileProxy::$enabled = $proxyStatus; + } + return $size; + } /** * restore files from trash bin * @param $file path to the deleted file * @param $filename name of the file * @param $timestamp time when the file was deleted - */ + * + * @return bool + */ public static function restore($file, $filename, $timestamp) { - $user = \OCP\User::getUser(); + + $user = \OCP\User::getUser(); $view = new \OC\Files\View('/'.$user); $trashbinSize = self::getTrashbinSize($user); @@ -157,8 +256,17 @@ class Trashbin { // we need a extension in case a file/dir with the same name already exists $ext = self::getUniqueExtension($location, $filename, $view); $mtime = $view->filemtime($source); - if( $view->rename($source, $target.$ext) ) { - $view->touch($target.$ext, $mtime); + + // disable proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + // restore file + $restoreResult = $view->rename($source, $target.$ext); + + // handle the restore result + if( $restoreResult ) { + $view->touch($target.$ext, $mtime); \OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', array('filePath' => \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext), 'trashPath' => \OC\Files\Filesystem::normalizePath($file))); @@ -167,68 +275,183 @@ class Trashbin { } else { $trashbinSize -= $view->filesize($target.$ext); } - // if versioning app is enabled, copy versions from the trash bin back to the original location - if ( \OCP\App::isEnabled('files_versions') ) { - if ($timestamp ) { - $versionedFile = $filename; - } else { - $versionedFile = $file; - } - if ( $result[0]['type'] === 'dir' ) { - $trashbinSize -= self::calculateSize(new \OC\Files\View('/'.$user.'/'.'files_trashbin/versions/'. $file)); - $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/'. $file), \OC\Files\Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext)); - } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) { - foreach ($versions as $v) { - if ($timestamp ) { - $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp); - $view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); - } else { - $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v); - $view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); - } - } - } - } - - // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!) - $parts = pathinfo($file); - if ( $result[0]['type'] === 'dir' ) { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$parts['dirname'].'/'.$filename); - } else { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$parts['dirname'].'/'.$filename.'.key'); - } - if ($timestamp) { - $keyfile .= '.d'.$timestamp; - } - if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) { - if ( $result[0]['type'] === 'dir' ) { - $trashbinSize -= self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile)); - $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename); - } else { - $trashbinSize -= $view->filesize($keyfile); - $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename.'.key'); - } - } - + + $trashbinSize -= self::restoreVersions($view, $file, $filename, $ext, $location, $timestamp); + $trashbinSize -= self::restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp); + if ( $timestamp ) { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=? AND `id`=? AND `timestamp`=?'); $query->execute(array($user,$filename,$timestamp)); } self::setTrashbinSize($user, $trashbinSize); - + + // enable proxy + \OC_FileProxy::$enabled = $proxyStatus; + return true; - } else { - \OC_Log::write('files_trashbin', 'Couldn\'t restore file from trash bin, '.$filename, \OC_log::ERROR); } + // enable proxy + \OC_FileProxy::$enabled = $proxyStatus; + return false; } + /** + * @brief restore versions from trash bin + * + * @param \OC\Files\View $view file view + * @param $file complete path to file + * @param $filename name of file + * @param $ext file extension in case a file with the same $filename already exists + * @param $location location if file + * @param $timestamp deleteion time + * + * @return size of restored versions + */ + private static function restoreVersions($view, $file, $filename, $ext, $location, $timestamp) { + $size = 0; + if (\OCP\App::isEnabled('files_versions')) { + // disable proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + $user = \OCP\User::getUser(); + if ($timestamp) { + $versionedFile = $filename; + } else { + $versionedFile = $file; + } + + if ($view->is_dir('/files_trashbin/versions/'.$file)) { + $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . 'files_trashbin/versions/' . $file)); + $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath('files_versions/' . $location . '/' . $filename . $ext)); + } else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp)) { + foreach ($versions as $v) { + if ($timestamp) { + $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp); + $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); + } else { + $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v); + $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); + } + } + } + + // enable proxy + \OC_FileProxy::$enabled = $proxyStatus; + } + return $size; + } + + + /** + * @brief restore encryption keys from trash bin + * + * @param \OC\Files\View $view + * @param $file complete path to file + * @param $filename name of file + * @param $ext file extension in case a file with the same $filename already exists + * @param $location location if file + * @param $timestamp deleteion time + * + * @return size of restored encrypted file + */ + private static function restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp) { + // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!) + $size = 0; + if (\OCP\App::isEnabled('files_encryption')) { + $user = \OCP\User::getUser(); + + $path_parts = pathinfo($file); + $source_location = $path_parts['dirname']; + + if ($view->is_dir('/files_trashbin/keyfiles/'.$file)) { + if($source_location != '.') { + $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename); + $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename); + } else { + $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename); + $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename); + } + } else { + $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key'); + } + + if ($timestamp) { + $keyfile .= '.d' . $timestamp; + } + + // disable proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + if ($view->file_exists($keyfile)) { + // handle directory + if ($view->is_dir($keyfile)) { + + // handle keyfiles + $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); + $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext); + + // handle share-keys + if ($timestamp) { + $sharekey .= '.d' . $timestamp; + } + $view->rename($sharekey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext); + + } else { + // handle keyfiles + $size += $view->filesize($keyfile); + $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext . '.key'); + + // handle share-keys + $ownerShareKey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey'); + if ($timestamp) { + $ownerShareKey .= '.d' . $timestamp; + } + + $size += $view->filesize($ownerShareKey); + + // move only owners key + $view->rename($ownerShareKey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext . '.' . $user. '.shareKey'); + + // try to re-share if file is shared + $filesystemView = new \OC_FilesystemView('/'); + $session = new \OCA\Encryption\Session($filesystemView); + $util = new \OCA\Encryption\Util($filesystemView, $user); + + // fix the file size + $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $user . '/files/'. $location. '/' .$filename); + $util->fixFileSize($absolutePath); + + // get current sharing state + $sharingEnabled = \OCP\Share::isEnabled(); + + // get the final filename + $target = \OC\Files\Filesystem::normalizePath($location.'/'.$filename); + + // get users sharing this file + $usersSharing = $util->getSharingUsersArray($sharingEnabled, $target.$ext, $user); + + // Attempt to set shareKey + $util->setSharedFileKeyfiles($session, $usersSharing, $target.$ext); + } + } + + // enable proxy + \OC_FileProxy::$enabled = $proxyStatus; + } + return $size; + } + /** - * delete file from trash bin permanently + * @brief delete file from trash bin permanently + * * @param $filename path to the file * @param $timestamp of deletion time + * * @return size of deleted files */ public static function delete($filename, $timestamp=null) { -- cgit v1.2.3 From 996a557475f8ad0d5e8c75ca524817f1a7c4831e Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 3 May 2013 13:00:04 +0200 Subject: get original path in case of shared files --- apps/files_trashbin/lib/trash.php | 45 ++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'apps/files_trashbin') diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 88c71a75ab0..10e48a497d4 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -29,6 +29,17 @@ class Trashbin { // unit: percentage; 50% of available disk space/quota const DEFAULTMAXSIZE=50; + public static function getUidAndFilename($filename) { + $uid = \OC\Files\Filesystem::getOwner($filename); + \OC\Files\Filesystem::initMountPoints($uid); + if ( $uid != \OCP\User::getUser() ) { + $info = \OC\Files\Filesystem::getFileInfo($filename); + $ownerView = new \OC\Files\View('/'.$uid.'/files'); + $filename = $ownerView->getPath($info['fileid']); + } + return array($uid, $filename); + } + /** * move file to the trash bin * @@ -143,35 +154,38 @@ class Trashbin { if (\OCP\App::isEnabled('files_encryption')) { $user = \OCP\User::getUser(); + $rootView = new \OC\Files\View('/'); + + list($owner, $ownerPath) = self::getUidAndFilename($file_path); + // disable proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; // retain key files - $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path); + $keyfile = \OC\Files\Filesystem::normalizePath($owner.'/files_encryption/keyfiles/' . $ownerPath); - if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) { - $user = \OCP\User::getUser(); + if ($rootView->is_dir($keyfile) || $rootView->file_exists($keyfile . '.key')) { // move keyfiles - if ($view->is_dir($keyfile)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); - $view->rename($keyfile, 'files_trashbin/keyfiles/' . $filename . '.d' . $timestamp); + if ($rootView->is_dir($keyfile)) { + $size += self::calculateSize(new \OC\Files\View($keyfile)); + $rootView->rename($keyfile, $user.'/files_trashbin/keyfiles/' . $filename . '.d' . $timestamp); } else { - $size += $view->filesize($keyfile . '.key'); - $view->rename($keyfile . '.key', 'files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp); + $size += $rootView->filesize($keyfile . '.key'); + $rootView->rename($keyfile . '.key', $user.'/files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp); } } // retain share keys - $sharekeys = \OC\Files\Filesystem::normalizePath('files_encryption/share-keys/' . $file_path); + $sharekeys = \OC\Files\Filesystem::normalizePath($owner.'/files_encryption/share-keys/' . $ownerPath); - if ($view->is_dir($sharekeys)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys)); - $view->rename($sharekeys, 'files_trashbin/share-keys/' . $filename . '.d' . $timestamp); + if ($rootView->is_dir($sharekeys)) { + $size += self::calculateSize(new \OC\Files\View($sharekeys)); + $rootView->rename($sharekeys, $user.'/files_trashbin/share-keys/' . $filename . '.d' . $timestamp); } else { // get local path to share-keys - $localShareKeysPath = $view->getLocalFile($sharekeys); + $localShareKeysPath = $rootView->getLocalFile($sharekeys); // handle share-keys $matches = glob(preg_quote($localShareKeysPath).'*.shareKey'); @@ -186,10 +200,10 @@ class Trashbin { if($pathinfo['basename'] == $ownerShareKey) { // calculate size - $size += $view->filesize($sharekeys. '.' . $user. '.shareKey'); + $size += $rootView->filesize($sharekeys. '.' . $user. '.shareKey'); // move file - $view->rename($sharekeys. '.' . $user. '.shareKey', 'files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp); + $rootView->rename($sharekeys. '.' . $user. '.shareKey', $user.'/files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp); } else { // calculate size @@ -220,6 +234,7 @@ class Trashbin { $user = \OCP\User::getUser(); $view = new \OC\Files\View('/'.$user); + $rootView = new \OC\Files\View('/'); $trashbinSize = self::getTrashbinSize($user); if ( $trashbinSize === false || $trashbinSize < 0 ) { -- cgit v1.2.3 From a2516e549b3e59171448c6e9182f5b3c110dd076 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 3 May 2013 14:03:42 +0200 Subject: get original path in case of shared files when restoring file from trash bin --- apps/files_trashbin/lib/trash.php | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'apps/files_trashbin') diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 10e48a497d4..221c32f553d 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -234,7 +234,6 @@ class Trashbin { $user = \OCP\User::getUser(); $view = new \OC\Files\View('/'.$user); - $rootView = new \OC\Files\View('/'); $trashbinSize = self::getTrashbinSize($user); if ( $trashbinSize === false || $trashbinSize < 0 ) { @@ -368,7 +367,7 @@ class Trashbin { * @param $file complete path to file * @param $filename name of file * @param $ext file extension in case a file with the same $filename already exists - * @param $location location if file + * @param $location location of file * @param $timestamp deleteion time * * @return size of restored encrypted file @@ -378,20 +377,25 @@ class Trashbin { $size = 0; if (\OCP\App::isEnabled('files_encryption')) { $user = \OCP\User::getUser(); + $rootView = new \OC\Files\View('/'); + + $target = \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext); + + list($owner, $ownerPath) = self::getUidAndFilename($target); $path_parts = pathinfo($file); $source_location = $path_parts['dirname']; if ($view->is_dir('/files_trashbin/keyfiles/'.$file)) { if($source_location != '.') { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename); - $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename); + $keyfile = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/keyfiles/' . $source_location . '/' . $filename); + $sharekey = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/share-keys/' . $source_location . '/' . $filename); } else { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename); - $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename); + $keyfile = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/keyfiles/' . $filename); + $sharekey = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/share-keys/' . $filename); } } else { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key'); + $keyfile = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key'); } if ($timestamp) { @@ -402,35 +406,36 @@ class Trashbin { $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - if ($view->file_exists($keyfile)) { + if ($rootView->file_exists($keyfile)) { // handle directory - if ($view->is_dir($keyfile)) { + if ($rootView->is_dir($keyfile)) { // handle keyfiles - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); - $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext); + $size += self::calculateSize(new \OC\Files\View($keyfile)); + $rootView->rename($keyfile, $owner.'/files_encryption/keyfiles/' . $ownerPath); // handle share-keys if ($timestamp) { $sharekey .= '.d' . $timestamp; } - $view->rename($sharekey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext); + $size += self::calculateSize(new \OC\Files\View($sharekey)); + $rootView->rename($sharekey, $owner.'/files_encryption/share-keys/' . $ownerPath); } else { // handle keyfiles - $size += $view->filesize($keyfile); - $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext . '.key'); + $size += $rootView->filesize($keyfile); + $rootView->rename($keyfile, $owner.'/files_encryption/keyfiles/' . $ownerPath . '.key'); // handle share-keys - $ownerShareKey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey'); + $ownerShareKey = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey'); if ($timestamp) { $ownerShareKey .= '.d' . $timestamp; } - $size += $view->filesize($ownerShareKey); + $size += $rootView->filesize($ownerShareKey); // move only owners key - $view->rename($ownerShareKey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext . '.' . $user. '.shareKey'); + $rootView->rename($ownerShareKey, $owner.'/files_encryption/share-keys/' . $ownerPath . '.' . $user. '.shareKey'); // try to re-share if file is shared $filesystemView = new \OC_FilesystemView('/'); @@ -438,7 +443,7 @@ class Trashbin { $util = new \OCA\Encryption\Util($filesystemView, $user); // fix the file size - $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $user . '/files/'. $location. '/' .$filename); + $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $owner . '/files/'. $ownerPath); $util->fixFileSize($absolutePath); // get current sharing state -- cgit v1.2.3 From 8a1223181bb330442aa3d641c4d081b1dd4888c7 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 3 May 2013 15:18:05 +0200 Subject: disable proxys before copying files to the trash bin --- apps/files_trashbin/lib/trash.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'apps/files_trashbin') diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 221c32f553d..661d5f7bba4 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -73,8 +73,12 @@ class Trashbin { if ( $trashbinSize === false || $trashbinSize < 0 ) { $trashbinSize = 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); + \OC_FileProxy::$enabled = $proxyStatus; if ( $view->file_exists('files_trashbin/files/'.$filename.'.d'.$timestamp) ) { $trashbinSize += $sizeOfAddedFiles; -- cgit v1.2.3 From 050258f003a5b2314890b2cc81963b68df2d987c Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 3 May 2013 16:33:18 +0200 Subject: remove encryption keys if a file gets deleted permanently --- apps/files_trashbin/lib/trash.php | 72 +++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'apps/files_trashbin') diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 661d5f7bba4..3e8a6f7885b 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -496,7 +496,25 @@ class Trashbin { $file = $filename; } + $size += self::deleteVersions($view, $file, $filename, $timestamp); + $size += self::deleteEncryptionKeys($view, $file, $filename, $timestamp); + + if ($view->is_dir('/files_trashbin/files/'.$file)) { + $size += self::calculateSize(new \OC\Files\View('/'.$user.'/files_trashbin/files/'.$file)); + } else { + $size += $view->filesize('/files_trashbin/files/'.$file); + } + $view->unlink('/files_trashbin/files/'.$file); + $trashbinSize -= $size; + self::setTrashbinSize($user, $trashbinSize); + + return $size; + } + + private static function deleteVersions($view, $file, $filename, $timestamp) { + $size = 0; if ( \OCP\App::isEnabled('files_versions') ) { + $user = \OCP\User::getUser(); if ($view->is_dir('files_trashbin/versions/'.$file)) { $size += self::calculateSize(new \OC\Files\view('/'.$user.'/files_trashbin/versions/'.$file)); $view->unlink('files_trashbin/versions/'.$file); @@ -512,35 +530,37 @@ class Trashbin { } } } - - // Take care of encryption keys - $parts = pathinfo($file); - if ( $view->is_dir('/files_trashbin/files/'.$file) ) { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename); - } else { - $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename.'.key'); - } - if ($timestamp) { - $keyfile .= '.d'.$timestamp; - } - if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) { - if ( $view->is_dir($keyfile) ) { - $size += self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile)); + return $size; + } + + private static function deleteEncryptionKeys($view, $file, $filename, $timestamp) { + $size = 0; + if (\OCP\App::isEnabled('files_encryption')) { + $user = \OCP\User::getUser(); + + if ($view->is_dir('/files_trashbin/files/' . $file)) { + $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename); + $sharekeys = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename); } else { - $size += $view->filesize($keyfile); + $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename . '.key'); + $sharekeys = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename . '.' . $user . '.shareKey'); + } + if ($timestamp) { + $keyfile .= '.d' . $timestamp; + $sharekeys .= '.d' . $timestamp; + } + if ($view->file_exists($keyfile)) { + if ($view->is_dir($keyfile)) { + $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile)); + $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys)); + } else { + $size += $view->filesize($keyfile); + $size += $view->filesize($sharekeys); + } + $view->unlink($keyfile); + $view->unlink($sharekeys); } - $view->unlink($keyfile); - } - - if ($view->is_dir('/files_trashbin/files/'.$file)) { - $size += self::calculateSize(new \OC\Files\View('/'.$user.'/files_trashbin/files/'.$file)); - } else { - $size += $view->filesize('/files_trashbin/files/'.$file); } - $view->unlink('/files_trashbin/files/'.$file); - $trashbinSize -= $size; - self::setTrashbinSize($user, $trashbinSize); - return $size; } -- cgit v1.2.3 From d649f77898b04a0215f16cfee7f26a40e5c1f8d1 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 3 May 2013 17:14:43 +0200 Subject: make sure to find the correct path for shared files --- apps/files_trashbin/lib/trash.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'apps/files_trashbin') diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 3e8a6f7885b..d61ac433d02 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -125,13 +125,17 @@ class Trashbin { \OC_FileProxy::$enabled = false; $user = \OCP\User::getUser(); - if ($view->is_dir('files_versions/' . $file_path)) { - $size += self::calculateSize(new \OC\Files\View('/' . $user . '/files_versions/' . $file_path)); - $view->rename('files_versions/' . $file_path, 'files_trashbin/versions/' . $filename . '.d' . $timestamp); - } else if ($versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path)) { + $rootView = new \OC\Files\View('/'); + + list($owner, $ownerPath) = self::getUidAndFilename($file_path); + + if ($rootView->is_dir($owner.'/files_versions/' . $ownerPath)) { + $size += self::calculateSize(new \OC\Files\View('/' . $owner . '/files_versions/' . $ownerPath)); + $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 += $view->filesize('files_versions' . $v['path'] . '.v' . $v['version']); - $view->rename('files_versions' . $v['path'] . '.v' . $v['version'], 'files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); + $size += $rootView->filesize($owner.'/files_versions' . $v['path'] . '.v' . $v['version']); + $rootView->rename($owner.'/files_versions' . $v['path'] . '.v' . $v['version'], $user.'/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp); } } @@ -336,6 +340,12 @@ class Trashbin { \OC_FileProxy::$enabled = false; $user = \OCP\User::getUser(); + $rootView = new \OC\Files\View('/'); + + $target = \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext); + + list($owner, $ownerPath) = self::getUidAndFilename($target); + if ($timestamp) { $versionedFile = $filename; } else { @@ -344,15 +354,15 @@ class Trashbin { if ($view->is_dir('/files_trashbin/versions/'.$file)) { $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . 'files_trashbin/versions/' . $file)); - $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath('files_versions/' . $location . '/' . $filename . $ext)); + $rootView->rename(\OC\Files\Filesystem::normalizePath($user.'/files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath($owner.'/files_versions/' . $ownerPath)); } else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp)) { foreach ($versions as $v) { if ($timestamp) { $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp); - $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); + $rootView->rename($user.'/files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, $owner.'/files_versions/' . $ownerPath . '.v' . $v); } else { $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v); - $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v); + $rootView->rename($user.'/files_trashbin/versions/' . $versionedFile . '.v' . $v, $owner.'/files_versions/' . $ownerPath . '.v' . $v); } } } -- cgit v1.2.3