[Pkg-owncloud-commits] [owncloud] 102/134: Fixed chunking and insufficient storage check

David Prévot taffit at moszumanska.debian.org
Fri Apr 18 21:44:06 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 be30728bc2b7d11b7e3912870bcbf4bd01687153
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Wed Mar 12 16:57:39 2014 +0100

    Fixed chunking and insufficient storage check
    
    - fixed free space detection based on the already uploaded chunks
    - now deleting chunks as soon as it is read out before writing it into
      the part file, which reduces the space needed when assembling part
    files
    
    Backport of 4033eba from master
---
 lib/private/connector/sabre/quotaplugin.php | 11 ++++++++
 lib/private/filechunking.php                | 41 +++++++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/lib/private/connector/sabre/quotaplugin.php b/lib/private/connector/sabre/quotaplugin.php
index ea2cb81..9ca4406 100644
--- a/lib/private/connector/sabre/quotaplugin.php
+++ b/lib/private/connector/sabre/quotaplugin.php
@@ -56,8 +56,19 @@ class OC_Connector_Sabre_QuotaPlugin extends Sabre_DAV_ServerPlugin {
 				$uri='/'.$uri;
 			}
 			list($parentUri, $newName) = Sabre_DAV_URLUtil::splitPath($uri);
+			$req = $this->server->httpRequest;
+			if ($req->getHeader('OC-Chunked')) {
+				$info = OC_FileChunking::decodeName($newName);
+				$chunkHandler = new OC_FileChunking($info);
+				// substract the already uploaded size to see whether
+				// there is still enough space for the remaining chunks
+				$length -= $chunkHandler->getCurrentSize();
+			}
 			$freeSpace = $this->getFreeSpace($parentUri);
 			if ($freeSpace !== \OC\Files\SPACE_UNKNOWN && $length > $freeSpace) {
+				if (isset($chunkHandler)) {
+					$chunkHandler->cleanup();
+				}
 				throw new Sabre_DAV_Exception_InsufficientStorage();
 			}
 		}
diff --git a/lib/private/filechunking.php b/lib/private/filechunking.php
index aa4f73c..76aa3e0 100644
--- a/lib/private/filechunking.php
+++ b/lib/private/filechunking.php
@@ -61,20 +61,46 @@ class OC_FileChunking {
 		return $parts == $this->info['chunkcount'];
 	}
 
+	/**
+	 * Assembles the chunks into the file specified by the path.
+	 * Chunks are deleted afterwards.
+	 *
+	 * @param string $f target path
+	 *
+	 * @return assembled file size
+	 *
+	 * @throws \OC\InsufficientStorageException when file could not be fully
+	 * assembled due to lack of free space
+	 */
 	public function assemble($f) {
 		$cache = $this->getCache();
 		$prefix = $this->getPrefix();
 		$count = 0;
-		for($i=0; $i < $this->info['chunkcount']; $i++) {
+		for ($i = 0; $i < $this->info['chunkcount']; $i++) {
 			$chunk = $cache->get($prefix.$i);
+			// remove after reading to directly save space
+			$cache->remove($prefix.$i);
 			$count += fwrite($f, $chunk);
 		}
 
-		$this->cleanup();
 		return $count;
 	}
 
 	/**
+	 * Returns the size of the chunks already present
+	 * @return size in bytes
+	 */
+	public function getCurrentSize() {
+		$cache = $this->getCache();
+		$prefix = $this->getPrefix();
+		$total = 0;
+		for ($i = 0; $i < $this->info['chunkcount']; $i++) {
+			$total += $cache->size($prefix.$i);
+		}
+		return $total;
+	}
+
+	/**
 	 * Removes all chunks which belong to this transmission
 	 */
 	public function cleanup() {
@@ -124,6 +150,17 @@ class OC_FileChunking {
 		);
 	}
 
+	/**
+	 * Assembles the chunks into the file specified by the path.
+	 * Also triggers the relevant hooks and proxies.
+	 *
+	 * @param string $path target path
+	 *
+	 * @return assembled file size or false if file could not be created
+	 *
+	 * @throws \OC\InsufficientStorageException when file could not be fully
+	 * assembled due to lack of free space
+	 */
 	public function file_assemble($path) {
 		$absolutePath = \OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getView()->getAbsolutePath($path));
 		$data = '';

-- 
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