diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-02 18:15:27 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-02 18:15:27 +0200 |
commit | 9f58097e4dc6fce20ba8995a9f82951d4dc3a80e (patch) | |
tree | 3353800139826bfd6f8d0229e73e472f47ae280a /lib | |
parent | 4a215cad3c1b601a291535560a5e0505f2119054 (diff) | |
parent | b495ca492408c3560e654e0137fcae35ff35a576 (diff) | |
download | nextcloud-server-9f58097e4dc6fce20ba8995a9f82951d4dc3a80e.tar.gz nextcloud-server-9f58097e4dc6fce20ba8995a9f82951d4dc3a80e.zip |
Merge pull request #14113 from owncloud/chunking-chunkpartfiles
Added part files for when writing chunks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/cache/file.php | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/private/cache/file.php b/lib/private/cache/file.php index a2f229fb89c..8874acbb1e5 100644 --- a/lib/private/cache/file.php +++ b/lib/private/cache/file.php @@ -33,6 +33,7 @@ namespace OC\Cache; use OC\Files\Filesystem; use OC\Files\View; +use OCP\Security\ISecureRandom; class File { protected $storage; @@ -101,12 +102,22 @@ class File { $storage = $this->getStorage(); $result = false; $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; - if ($storage and $storage->file_put_contents($key, $value)) { + if ($storage and $storage->file_put_contents($keyPart, $value)) { if ($ttl === 0) { $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; return $result; |