[Pkg-owncloud-commits] [owncloud] 14/273: fix checking unset array values, deduplicate code, remove file from cache if it could not be stored in the objectstore

David Prévot taffit at moszumanska.debian.org
Fri Jul 4 03:12:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 87aaf39259f3c81d1b2386919c1bfbe247a5649f
Author: Jörn Friedrich Dreyer <jfd at butonic.de>
Date:   Thu Jun 12 12:18:19 2014 +0200

    fix checking unset array values, deduplicate code, remove file from cache if it could not be stored in the objectstore
---
 .../files/objectstore/abstractobjectstore.php      | 69 ++++++++++------------
 1 file changed, 30 insertions(+), 39 deletions(-)

diff --git a/lib/private/files/objectstore/abstractobjectstore.php b/lib/private/files/objectstore/abstractobjectstore.php
index 8d65e18..2ef2f38 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;
 		}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list