summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-06-15 14:22:06 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-06-15 14:22:06 +0200
commit911c43e5f910cf2d228ab8225db0c686e1dca436 (patch)
tree4bd893fac35f1a89f3d698d76d0198992910ffce /lib
parent5eb0dace8c680425165e36c0b6d64d0245841c3a (diff)
parentbcf13aff6f9082f87930068ecd9560612e36fc6a (diff)
downloadnextcloud-server-911c43e5f910cf2d228ab8225db0c686e1dca436.tar.gz
nextcloud-server-911c43e5f910cf2d228ab8225db0c686e1dca436.zip
Merge pull request #16727 from owncloud/file-put-content-lock
add proper locking to file_put_contents when using streams
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/view.php19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 99db05f65c2..483dc610523 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -535,25 +535,40 @@ class View {
) {
$path = $this->getRelativePath($absolutePath);
+ $this->lockFile($path, ILockingProvider::LOCK_SHARED);
+
$exists = $this->file_exists($path);
$run = true;
if ($this->shouldEmitHooks($path)) {
$this->emit_file_hooks_pre($exists, $path, $run);
}
if (!$run) {
+ $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
return false;
}
- $target = $this->fopen($path, 'w');
+
+ $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
+
+ /** @var \OC\Files\Storage\Storage $storage */
+ list($storage, $internalPath) = $this->resolvePath($path);
+ $target = $storage->fopen($internalPath, 'w');
if ($target) {
- list ($count, $result) = \OC_Helper::streamCopy($data, $target);
+ list (, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
+
+ $this->changeLock($path, ILockingProvider::LOCK_SHARED);
+
$this->updater->update($path);
+
+ $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
+
if ($this->shouldEmitHooks($path) && $result !== false) {
$this->emit_file_hooks_post($exists, $path);
}
return $result;
} else {
+ $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
return false;
}
} else {