Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions apps/files_versions/lib/Command/Expire.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public function handle() {
return;
}

\OC_Util::setupFS($this->user);
Storage::expire($this->fileName);
\OC_Util::tearDownFS();
Storage::expire($this->fileName, $this->user);
}
}
21 changes: 15 additions & 6 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,30 +688,39 @@ private static function scheduleExpire($uid, $fileName) {
}

/**
* Expire versions which exceed the quota
* Expire versions which exceed the quota.
*
* @param string $filename
* This will setup the filesystem for the given user but will not
* tear it down afterwards.
*
* @param string $filename path to file to expire
* @param string $uid user for which to expire the version
* @return bool|int|null
*/
public static function expire($filename) {
public static function expire($filename, $uid) {
$config = \OC::$server->getConfig();
$expiration = self::getExpiration();

if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
// get available disk space for user
$user = \OC::$server->getUserManager()->get($uid);
if (is_null($user)) {
\OCP\Util::writeLog('files_versions', 'Backends provided no user object for ' . $uid, \OCP\Util::ERROR);
throw new \OC\User\NoUserException('Backends provided no user object for ' . $uid);
}

\OC_Util::setupFS($uid);

if (!Filesystem::file_exists($filename)) {
return false;
}

list($uid, $filename) = self::getUidAndFilename($filename);
if (empty($filename)) {
// file maybe renamed or deleted
return false;
}
$versionsFileview = new View('/'.$uid.'/files_versions');

// get available disk space for user
$user = \OC::$server->getUserManager()->get($uid);
$softQuota = true;
$quota = $user->getQuota();
if ( $quota === null || $quota === 'none' ) {
Expand Down
14 changes: 13 additions & 1 deletion apps/files_versions/tests/VersioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,19 @@ public function testExpireNonexistingFile() {
// needed to have a FS setup (the background job does this)
\OC_Util::setupFS(self::TEST_VERSIONS_USER);

$this->assertFalse(\OCA\Files_Versions\Storage::expire('/void/unexist.txt'));
$this->assertFalse(\OCA\Files_Versions\Storage::expire('/void/unexist.txt', self::TEST_VERSIONS_USER));
}

/**
* @expectedException \OC\User\NoUserException
*/
public function testExpireNonexistingUser() {
$this->logout();
// needed to have a FS setup (the background job does this)
\OC_Util::setupFS(self::TEST_VERSIONS_USER);
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");

$this->assertFalse(\OCA\Files_Versions\Storage::expire('test.txt', 'unexist'));
}

public function testRestoreSameStorage() {
Expand Down