chunked files are assembled into a part file on the target storage followed by an atomic rename operation.

This commit is contained in:
Thomas Müller 2013-10-21 13:21:39 +02:00
parent f5a6d6b43e
commit 3cb666ad77
1 changed files with 16 additions and 3 deletions

View File

@ -223,9 +223,22 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
}
if ($chunk_handler->isComplete()) {
$newPath = $path . '/' . $info['name'];
$chunk_handler->file_assemble($newPath);
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
// we first assembly the target file as a part file
$partFile = $path . '/' . $info['name'] . '-' . $info['transferid'] . '.part';
$chunk_handler->file_assemble($partFile);
// here is the final atomic rename
$fs = $this->getFS();
$targetPath = $path . '/' . $info['name'];
$renameOkay = $fs->rename($partFile, $targetPath);
$fileExists = $fs->file_exists($targetPath);
if ($renameOkay === false || $fileExists === false) {
\OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
$fs->unlink($targetPath);
throw new Sabre_DAV_Exception();
}
return OC_Connector_Sabre_Node::getETagPropertyForPath($targetPath);
}
return null;