only create the file cache entry after the empty file was created successfully, otherwise file_exists() call on the initial file_put_content() will indicate that the file already exists

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-11-17 11:59:25 +01:00
parent 031bde5c88
commit 83ef3d2411
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
1 changed files with 13 additions and 14 deletions

View File

@ -351,25 +351,24 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$stat['mtime'] = $mtime;
$this->getCache()->update($stat['fileid'], $stat);
} else {
$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
// create new file
$stat = array(
'etag' => $this->getETag($path),
'mimetype' => $mimeType,
'size' => 0,
'mtime' => $mtime,
'storage_mtime' => $mtime,
'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
);
$fileId = $this->getCache()->put($path, $stat);
try {
//read an empty file from memory
//create a empty file, need to have at least on char to make it
// work with all object storage implementations
$this->file_put_contents($path, ' ');
$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
$stat = array(
'etag' => $this->getETag($path),
'mimetype' => $mimeType,
'size' => 0,
'mtime' => $mtime,
'storage_mtime' => $mtime,
'permissions' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
);
$this->getCache()->put($path, $stat);
} catch (\Exception $ex) {
$this->getCache()->remove($path);
$this->logger->logException($ex, [
'app' => 'objectstore',
'message' => 'Could not create object ' . $this->getURN($fileId) . ' for ' . $path,
'message' => 'Could not create object for ' . $path,
]);
return false;
}