diff options
Diffstat (limited to 'apps/files_versions/lib/versions.php')
-rw-r--r-- | apps/files_versions/lib/versions.php | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 3ad73284ef2..65ed33fe2a0 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -21,6 +21,9 @@ class Storage { const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota const VERSIONS_ROOT = 'files_versions/'; + // files for which we can remove the versions after the delete operation was successful + private static $deletedFiles = array(); + private static $max_versions_per_interval = array( //first 10sec, one version every 2sec 1 => array('intervalEndsAfter' => 10, 'step' => 2), @@ -142,25 +145,44 @@ class Storage { /** + * @brief mark file as deleted so that we can remove the versions if the file is gone + * @param string $path + */ + public static function markDeletedFile($path) { + list($uid, $filename) = self::getUidAndFilename($path); + self::$deletedFiles[$path] = array( + 'uid' => $uid, + 'filename' => $filename); + } + + /** * Delete versions of a file */ - public static function delete($filename) { - list($uid, $filename) = self::getUidAndFilename($filename); - $versions_fileview = new \OC\Files\View('/'.$uid .'/files_versions'); + public static function delete($path) { - $abs_path = $versions_fileview->getLocalFile($filename.'.v'); - if( ($versions = self::getVersions($uid, $filename)) ) { - $versionsSize = self::getVersionsSize($uid); - if ( $versionsSize === false || $versionsSize < 0 ) { - $versionsSize = self::calculateSize($uid); - } - foreach ($versions as $v) { - unlink($abs_path . $v['version']); - \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $abs_path . $v['version'])); - $versionsSize -= $v['size']; + $deletedFile = self::$deletedFiles[$path]; + $uid = $deletedFile['uid']; + $filename = $deletedFile['filename']; + + if (!\OC\Files\Filesystem::file_exists($path)) { + + $versions_fileview = new \OC\Files\View('/' . $uid . '/files_versions'); + + $abs_path = $versions_fileview->getLocalFile($filename . '.v'); + if (($versions = self::getVersions($uid, $filename))) { + $versionsSize = self::getVersionsSize($uid); + if ($versionsSize === false || $versionsSize < 0) { + $versionsSize = self::calculateSize($uid); + } + foreach ($versions as $v) { + unlink($abs_path . $v['version']); + \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $abs_path . $v['version'])); + $versionsSize -= $v['size']; + } + self::setVersionsSize($uid, $versionsSize); } - self::setVersionsSize($uid, $versionsSize); } + unset(self::$deletedFiles[$path]); } /** |