From 1263511a179fb1508f41207d61d76739e087b239 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= <jfd@butonic.de>
Date: Sun, 10 Feb 2013 14:16:45 +0100
Subject: [PATCH] append .part to put files

---
 lib/connector/sabre/file.php |  8 +++++++-
 lib/files/cache/scanner.php  | 18 +++++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php
index 1c18a39174..521c5f0571 100644
--- a/lib/connector/sabre/file.php
+++ b/lib/connector/sabre/file.php
@@ -45,7 +45,13 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
 	 */
 	public function put($data) {
 
-		\OC\Files\Filesystem::file_put_contents($this->path,$data);
+		// mark file as partial while uploading (ignored by the scanner)
+		$partpath = $this->path . '.part';
+		
+		\OC\Files\Filesystem::file_put_contents($partpath, $data);
+		
+		// rename to correct path
+		\OC\Files\Filesystem::rename($partpath, $this->path);
 
 		return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
 	}
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 9a5546dce3..5a9a119458 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -97,7 +97,7 @@ class Scanner {
 		if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
 			\OC_DB::beginTransaction();
 			while ($file = readdir($dh)) {
-				if ($file !== '.' and $file !== '..') {
+				if (!$this->isIgnoredFile($file)) {
 					$child = ($path) ? $path . '/' . $file : $file;
 					$data = $this->scanFile($child);
 					if ($data) {
@@ -133,6 +133,22 @@ class Scanner {
 		}
 		return $size;
 	}
+	
+	/**
+	 * @brief check if the file should be ignored when scanning
+	 * NOTE: files with a '.part' extension are ignored as well!
+	 *       prevents unfinished put requests to be scanned
+	 * @param String $file
+	 * @return boolean
+	 */
+	private function isIgnoredFile($file) {
+		if ($file === '.' || $file === '..'
+		 || pathinfo($file,PATHINFO_EXTENSION) === 'part')
+		{
+			return true;
+		}
+		return false;
+	}
 
 	/**
 	 * walk over any folders that are not fully scanned yet and scan them
-- 
GitLab