Merge pull request #14113 from owncloud/chunking-chunkpartfiles
Added part files for when writing chunks
This commit is contained in:
commit
9f58097e4d
|
@ -33,6 +33,7 @@ namespace OC\Cache;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\View;
|
use OC\Files\View;
|
||||||
|
use OCP\Security\ISecureRandom;
|
||||||
|
|
||||||
class File {
|
class File {
|
||||||
protected $storage;
|
protected $storage;
|
||||||
|
@ -101,12 +102,22 @@ class File {
|
||||||
$storage = $this->getStorage();
|
$storage = $this->getStorage();
|
||||||
$result = false;
|
$result = false;
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
|
// unique id to avoid chunk collision, just in case
|
||||||
|
$uniqueId = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
|
||||||
|
16,
|
||||||
|
ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
|
||||||
|
);
|
||||||
|
|
||||||
|
// use part file to prevent hasKey() to find the key
|
||||||
|
// while it is being written
|
||||||
|
$keyPart = $key . '.' . $uniqueId . '.part';
|
||||||
\OC_FileProxy::$enabled = false;
|
\OC_FileProxy::$enabled = false;
|
||||||
if ($storage and $storage->file_put_contents($key, $value)) {
|
if ($storage and $storage->file_put_contents($keyPart, $value)) {
|
||||||
if ($ttl === 0) {
|
if ($ttl === 0) {
|
||||||
$ttl = 86400; // 60*60*24
|
$ttl = 86400; // 60*60*24
|
||||||
}
|
}
|
||||||
$result = $storage->touch($key, time() + $ttl);
|
$result = $storage->touch($keyPart, time() + $ttl);
|
||||||
|
$result &= $storage->rename($keyPart, $key);
|
||||||
}
|
}
|
||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
return $result;
|
return $result;
|
||||||
|
|
Loading…
Reference in New Issue