summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-06-12 12:18:19 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-06-18 12:53:20 +0200
commit87aaf39259f3c81d1b2386919c1bfbe247a5649f (patch)
treee1521d516ee5a2f3a809938f7f2f53506e6038e3 /lib
parenteca536d8b49ed6a51e54040cd8104397f05defb3 (diff)
downloadnextcloud-server-87aaf39259f3c81d1b2386919c1bfbe247a5649f.tar.gz
nextcloud-server-87aaf39259f3c81d1b2386919c1bfbe247a5649f.zip
fix checking unset array values, deduplicate code, remove file from cache if it could not be stored in the objectstore
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/objectstore/abstractobjectstore.php69
1 files changed, 30 insertions, 39 deletions
diff --git a/lib/private/files/objectstore/abstractobjectstore.php b/lib/private/files/objectstore/abstractobjectstore.php
index 8d65e18b6cc..2ef2f38bf40 100644
--- a/lib/private/files/objectstore/abstractobjectstore.php
+++ b/lib/private/files/objectstore/abstractobjectstore.php
@@ -126,7 +126,7 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common {
}
public function __construct($params) {
- if (is_object($params['user'])) {
+ if (isset($params['user']) && is_object($params['user'])) {
$this->user = $params['user'];
} else {
$this->user = null;
@@ -136,7 +136,7 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common {
$this->mkdir('/');
}
- if (is_object($params['user'])) {
+ if (isset($params['user']) && is_object($params['user'])) {
//create the files folder in the cache when mounting the objectstore for a user
if ( ! $this->is_dir('files') ) {
$this->mkdir('files');
@@ -154,37 +154,26 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common {
$dirName = dirname($path);
$parentExists = $this->is_dir($dirName);
- $mtime = time();
+ $mTime = time();
+
+ $data = array(
+ 'mimetype' => 'httpd/unix-directory',
+ 'size' => 0,
+ 'mtime' => $mTime,
+ 'storage_mtime' => $mTime,
+ 'permissions' => \OCP\PERMISSION_ALL,
+ );
if ($dirName === '.' && ! $parentExists ) {
//create root on the fly
-
- $data = array(
- 'etag' => $this->getETag($dirName),
- 'mimetype' => 'httpd/unix-directory',
- 'size' => 0,
- 'mtime' => $mtime,
- 'storage_mtime' => $mtime,
- 'permissions' => \OCP\PERMISSION_ALL,
- );
+ $data['etag'] = $this->getETag($dirName);
$this->getCache()->put('', $data);
$parentExists = true;
-
}
if ($parentExists) {
-
- $data = array(
- 'etag' => $this->getETag($path),
- 'mimetype' => 'httpd/unix-directory',
- 'size' => 0,
- 'mtime' => $mtime,
- 'storage_mtime' => $mtime,
- 'permissions' => \OCP\PERMISSION_ALL,
- );
-
+ $data['etag'] = $this->getETag($path);
$this->getCache()->put($path, $data);
-
return true;
}
return false;
@@ -274,8 +263,12 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common {
try {
$this->deleteObject($this->getURN($stat['fileid']));
} catch (\Exception $ex) {
- \OCP\Util::writeLog('objectstore', 'Could not delete object: '.$ex->getMessage(), \OCP\Util::ERROR);
- return false;
+ if ($ex->getCode() !== 404) {
+ \OCP\Util::writeLog('objectstore', 'Could not delete object: '.$ex->getMessage(), \OCP\Util::ERROR);
+ return false;
+ } else {
+ //removing from cache is ok as it does not exist in the objectstore anyway
+ }
}
$this->getCache()->remove($path);
return true;
@@ -403,6 +396,7 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common {
try {
$this->createObject($this->getURN($fileId));
} catch (\Exception $ex) {
+ $this->getCache()->remove($path);
\OCP\Util::writeLog('objectstore', 'Could not create object: '.$ex->getMessage(), \OCP\Util::ERROR);
return false;
}
@@ -430,30 +424,27 @@ abstract class AbstractObjectStore extends \OC\Files\Storage\Common {
}
$path = self::$tmpFiles[$tmpFile];
- $mimeType = \OC_Helper::getMimeType($tmpFile);
- $size = filesize($tmpFile);
- $mtime = time();
$stat = $this->stat($path);
- if (is_array($stat)) {
- // update existing db entry
- $stat['size'] = $size;
- $stat['mtime'] = $mtime;
- $stat['mimetype'] = $mimeType;
- } else {
+ if (empty($stat)) {
// create new file
$stat = array(
'etag' => $this->getETag($path),
- 'size' => $size,
- 'mtime' => $mtime,
- 'mimetype' => $mimeType,
- 'storage_mtime' => $mtime,
'permissions' => \OCP\PERMISSION_ALL,
);
}
+ // update stat with new data
+ $mTime = time();
+ $stat['size'] = filesize($tmpFile);
+ $stat['mtime'] = $mTime;
+ $stat['storage_mtime'] = $mTime;
+ $stat['mimetype'] = \OC_Helper::getMimeType($tmpFile);
+
$fileId = $this->getCache()->put($path, $stat);
try {
+ //upload to object storage
$this->createObject($this->getURN($fileId), $tmpFile);
} catch (\Exception $ex) {
+ $this->getCache()->remove($path);
\OCP\Util::writeLog('objectstore', 'Could not create object: '.$ex->getMessage(), \OCP\Util::ERROR);
return false;
}