Merge pull request #7624 from owncloud/enc-encryptedusedspacefix
[master] Fixed used space to be based on unencrypted size
This commit is contained in:
commit
26513bc17b
|
@ -340,6 +340,13 @@ class Proxy extends \OC_FileProxy {
|
||||||
|
|
||||||
// if path is a folder do nothing
|
// if path is a folder do nothing
|
||||||
if ($view->is_dir($path)) {
|
if ($view->is_dir($path)) {
|
||||||
|
$proxyState = \OC_FileProxy::$enabled;
|
||||||
|
\OC_FileProxy::$enabled = false;
|
||||||
|
$fileInfo = $view->getFileInfo($path);
|
||||||
|
\OC_FileProxy::$enabled = $proxyState;
|
||||||
|
if ($fileInfo['unencrypted_size'] > 0) {
|
||||||
|
return $fileInfo['unencrypted_size'];
|
||||||
|
}
|
||||||
return $size;
|
return $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,4 +112,24 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testPostFileSizeWithDirectory() {
|
||||||
|
|
||||||
|
$this->view->file_put_contents($this->filename, $this->data);
|
||||||
|
|
||||||
|
\OC_FileProxy::$enabled = false;
|
||||||
|
|
||||||
|
// get root size, must match the file's unencrypted size
|
||||||
|
$unencryptedSize = $this->view->filesize('');
|
||||||
|
|
||||||
|
\OC_FileProxy::$enabled = true;
|
||||||
|
|
||||||
|
$encryptedSize = $this->view->filesize('');
|
||||||
|
|
||||||
|
$this->assertTrue($encryptedSize !== $unencryptedSize);
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
$this->view->unlink($this->filename);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,15 +24,20 @@ class HomeCache extends Cache {
|
||||||
$entry = $this->get($path);
|
$entry = $this->get($path);
|
||||||
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
|
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
|
||||||
$id = $entry['fileid'];
|
$id = $entry['fileid'];
|
||||||
$sql = 'SELECT SUM(`size`) FROM `*PREFIX*filecache` ' .
|
$sql = 'SELECT SUM(`size`) AS f1, ' .
|
||||||
|
'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' .
|
||||||
'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
|
'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
|
||||||
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
|
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
|
||||||
if ($row = $result->fetchRow()) {
|
if ($row = $result->fetchRow()) {
|
||||||
list($sum) = array_values($row);
|
list($sum, $unencryptedSum) = array_values($row);
|
||||||
$totalSize = (int)$sum;
|
$totalSize = (int)$sum;
|
||||||
|
$unencryptedSize = (int)$unencryptedSum;
|
||||||
if ($entry['size'] !== $totalSize) {
|
if ($entry['size'] !== $totalSize) {
|
||||||
$this->update($id, array('size' => $totalSize));
|
$this->update($id, array('size' => $totalSize));
|
||||||
}
|
}
|
||||||
|
if ($entry['unencrypted_size'] !== $unencryptedSize) {
|
||||||
|
$this->update($id, array('unencrypted_size' => $unencryptedSize));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $totalSize;
|
return $totalSize;
|
||||||
|
|
|
@ -36,6 +36,11 @@ class Quota extends Wrapper {
|
||||||
$cache = $this->getCache();
|
$cache = $this->getCache();
|
||||||
$data = $cache->get($path);
|
$data = $cache->get($path);
|
||||||
if (is_array($data) and isset($data['size'])) {
|
if (is_array($data) and isset($data['size'])) {
|
||||||
|
if (isset($data['unencrypted_size'])
|
||||||
|
&& $data['unencrypted_size'] > 0
|
||||||
|
) {
|
||||||
|
return $data['unencrypted_size'];
|
||||||
|
}
|
||||||
return $data['size'];
|
return $data['size'];
|
||||||
} else {
|
} else {
|
||||||
return \OC\Files\SPACE_NOT_COMPUTED;
|
return \OC\Files\SPACE_NOT_COMPUTED;
|
||||||
|
|
|
@ -53,6 +53,22 @@ class Quota extends \Test\Files\Storage\Storage {
|
||||||
$this->assertEquals(9, $instance->free_space(''));
|
$this->assertEquals(9, $instance->free_space(''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFreeSpaceWithUsedSpace() {
|
||||||
|
$instance = $this->getLimitedStorage(9);
|
||||||
|
$instance->getCache()->put(
|
||||||
|
'', array('size' => 3, 'unencrypted_size' => 0)
|
||||||
|
);
|
||||||
|
$this->assertEquals(6, $instance->free_space(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFreeSpaceWithUsedSpaceAndEncryption() {
|
||||||
|
$instance = $this->getLimitedStorage(9);
|
||||||
|
$instance->getCache()->put(
|
||||||
|
'', array('size' => 7, 'unencrypted_size' => 3)
|
||||||
|
);
|
||||||
|
$this->assertEquals(6, $instance->free_space(''));
|
||||||
|
}
|
||||||
|
|
||||||
public function testFWriteNotEnoughSpace() {
|
public function testFWriteNotEnoughSpace() {
|
||||||
$instance = $this->getLimitedStorage(9);
|
$instance = $this->getLimitedStorage(9);
|
||||||
$stream = $instance->fopen('foo', 'w+');
|
$stream = $instance->fopen('foo', 'w+');
|
||||||
|
|
Loading…
Reference in New Issue