summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/ObjectStore/Azure.php13
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php18
-rw-r--r--lib/private/Files/ObjectStore/S3ObjectTrait.php4
-rw-r--r--lib/private/Files/ObjectStore/StorageObjectStore.php3
-rw-r--r--lib/private/Files/ObjectStore/Swift.php3
5 files changed, 38 insertions, 3 deletions
diff --git a/lib/private/Files/ObjectStore/Azure.php b/lib/private/Files/ObjectStore/Azure.php
index 899c826ec19..e162c510b98 100644
--- a/lib/private/Files/ObjectStore/Azure.php
+++ b/lib/private/Files/ObjectStore/Azure.php
@@ -115,4 +115,17 @@ class Azure implements IObjectStore {
public function deleteObject($urn) {
$this->getBlobClient()->deleteBlob($this->containerName, $urn);
}
+
+ public function objectExists($urn) {
+ try {
+ $this->getBlobClient()->getBlobMetadata($this->containerName, $urn);
+ return true;
+ } catch (ServiceException $e) {
+ if ($e->getCode() === 404) {
+ return false;
+ } else {
+ throw $e;
+ }
+ }
+ }
}
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index d8649129d90..12e47d76aa9 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -413,18 +413,30 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$stat['mimetype'] = $mimetype;
$stat['etag'] = $this->getETag($path);
- $fileId = $this->getCache()->put($path, $stat);
+ $exists = $this->getCache()->inCache($path);
+ $uploadPath = $exists ? $path : $path . '.part';
+ $fileId = $this->getCache()->put($uploadPath, $stat);
+ $urn = $this->getURN($fileId);
try {
//upload to object storage
$this->objectStore->writeObject($this->getURN($fileId), fopen($tmpFile, 'r'));
} catch (\Exception $ex) {
- $this->getCache()->remove($path);
+ $this->getCache()->remove($uploadPath);
$this->logger->logException($ex, [
'app' => 'objectstore',
- 'message' => 'Could not create object ' . $this->getURN($fileId) . ' for ' . $path,
+ 'message' => 'Could not create object ' . $urn . ' for ' . $path,
]);
throw $ex; // make this bubble up
}
+
+ if (!$exists) {
+ if ($this->objectStore->objectExists($urn)) {
+ $this->getCache()->move($uploadPath, $path);
+ } else {
+ $this->getCache()->remove($uploadPath);
+ throw new \Exception("Object not found after writing (urn: $urn, path: $path)", 404);
+ }
+ }
}
/**
diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php
index 280a8efa81c..a1110d87c8f 100644
--- a/lib/private/Files/ObjectStore/S3ObjectTrait.php
+++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php
@@ -90,4 +90,8 @@ trait S3ObjectTrait {
'Key' => $urn
]);
}
+
+ public function objectExists($urn) {
+ return $this->getConnection()->doesObjectExist($this->bucket, $urn);
+ }
}
diff --git a/lib/private/Files/ObjectStore/StorageObjectStore.php b/lib/private/Files/ObjectStore/StorageObjectStore.php
index 0d35ba2ed7a..f9fc1b5a4aa 100644
--- a/lib/private/Files/ObjectStore/StorageObjectStore.php
+++ b/lib/private/Files/ObjectStore/StorageObjectStore.php
@@ -89,4 +89,7 @@ class StorageObjectStore implements IObjectStore {
$this->storage->unlink($urn);
}
+ public function objectExists($urn) {
+ return $this->storage->file_exists($urn);
+ }
}
diff --git a/lib/private/Files/ObjectStore/Swift.php b/lib/private/Files/ObjectStore/Swift.php
index 667b92bd1d6..39de41869a3 100644
--- a/lib/private/Files/ObjectStore/Swift.php
+++ b/lib/private/Files/ObjectStore/Swift.php
@@ -127,4 +127,7 @@ class Swift implements IObjectStore {
$this->getContainer()->delete();
}
+ public function objectExists($urn) {
+ return $this->getContainer()->objectExists($urn);
+ }
}