Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cross storage move when renaming the part file during webdav put #16159

Merged
merged 1 commit into from
May 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/private/connector/sabre/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public function put($data) {
return $this->createFileChunked($data);
}

list($storage) = $this->fileView->resolvePath($this->path);
$needsPartFile = $this->needsPartFile($storage) && (strlen($this->path) > 1);
list($partStorage) = $this->fileView->resolvePath($this->path);
$needsPartFile = $this->needsPartFile($partStorage) && (strlen($this->path) > 1);

if ($needsPartFile) {
// mark file as partial while uploading (ignored by the scanner)
Expand All @@ -110,14 +110,16 @@ public function put($data) {
$partFilePath = $this->path;
}

// the part file and target file might be on a different storage in case of a single file storage (e.g. single file share)
/** @var \OC\Files\Storage\Storage $partStorage */
list($partStorage, $internalPartPath) = $this->fileView->resolvePath($partFilePath);
/** @var \OC\Files\Storage\Storage $storage */
list($storage, $internalPartPath) = $this->fileView->resolvePath($partFilePath);
list(, $internalPath) = $this->fileView->resolvePath($this->path);
list($storage, $internalPath) = $this->fileView->resolvePath($this->path);
try {
$target = $storage->fopen($internalPartPath, 'wb');
$target = $partStorage->fopen($internalPartPath, 'wb');
if ($target === false) {
\OC_Log::write('webdav', '\OC\Files\Filesystem::fopen() failed', \OC_Log::ERROR);
$storage->unlink($internalPartPath);
$partStorage->unlink($internalPartPath);
// because we have no clue about the cause we can only throw back a 500/Internal Server Error
throw new Exception('Could not write file contents');
}
Expand All @@ -130,7 +132,7 @@ public function put($data) {
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] !== 'LOCK') {
$expected = $_SERVER['CONTENT_LENGTH'];
if ($count != $expected) {
$storage->unlink($internalPartPath);
$partStorage->unlink($internalPartPath);
throw new BadRequest('expected filesize ' . $expected . ' got ' . $count);
}
}
Expand Down Expand Up @@ -162,11 +164,11 @@ public function put($data) {
if ($needsPartFile) {
// rename to correct path
try {
$renameOkay = $storage->rename($internalPartPath, $internalPath);
$renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, clever 😄

$fileExists = $storage->file_exists($internalPath);
if ($renameOkay === false || $fileExists === false) {
\OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
$storage->unlink($internalPartPath);
$partStorage->unlink($internalPartPath);
throw new Exception('Could not rename part file to final file');
}
} catch (\OCP\Files\LockNotAcquiredException $e) {
Expand All @@ -176,7 +178,7 @@ public function put($data) {
}

// since we skipped the view we need to scan and emit the hooks ourselves
$storage->getScanner()->scanFile($internalPath);
$partStorage->getScanner()->scanFile($internalPath);

$view = \OC\Files\Filesystem::getView();
if ($view) {
Expand Down