Merge pull request #16727 from owncloud/file-put-content-lock
add proper locking to file_put_contents when using streams
This commit is contained in:
commit
911c43e5f9
|
@ -535,25 +535,40 @@ class View {
|
||||||
) {
|
) {
|
||||||
$path = $this->getRelativePath($absolutePath);
|
$path = $this->getRelativePath($absolutePath);
|
||||||
|
|
||||||
|
$this->lockFile($path, ILockingProvider::LOCK_SHARED);
|
||||||
|
|
||||||
$exists = $this->file_exists($path);
|
$exists = $this->file_exists($path);
|
||||||
$run = true;
|
$run = true;
|
||||||
if ($this->shouldEmitHooks($path)) {
|
if ($this->shouldEmitHooks($path)) {
|
||||||
$this->emit_file_hooks_pre($exists, $path, $run);
|
$this->emit_file_hooks_pre($exists, $path, $run);
|
||||||
}
|
}
|
||||||
if (!$run) {
|
if (!$run) {
|
||||||
|
$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
|
||||||
return false;
|
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) {
|
if ($target) {
|
||||||
list ($count, $result) = \OC_Helper::streamCopy($data, $target);
|
list (, $result) = \OC_Helper::streamCopy($data, $target);
|
||||||
fclose($target);
|
fclose($target);
|
||||||
fclose($data);
|
fclose($data);
|
||||||
|
|
||||||
|
$this->changeLock($path, ILockingProvider::LOCK_SHARED);
|
||||||
|
|
||||||
$this->updater->update($path);
|
$this->updater->update($path);
|
||||||
|
|
||||||
|
$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
|
||||||
|
|
||||||
if ($this->shouldEmitHooks($path) && $result !== false) {
|
if ($this->shouldEmitHooks($path) && $result !== false) {
|
||||||
$this->emit_file_hooks_post($exists, $path);
|
$this->emit_file_hooks_post($exists, $path);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
|
$this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue