summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2013-04-03 01:38:18 -0700
committerJörn Friedrich Dreyer <jfd@butonic.de>2013-04-03 01:38:18 -0700
commit7eef64360000ad0ea2e48c548cb1def51ac98bf0 (patch)
treec961860982c0c137bcfce1bdbdd9dd5529824553
parent10e37e155339a0643be62fcd2ba721d0c90bfb5c (diff)
parentaa103bd5b32fc45e5594976c59cd7680bff60d2d (diff)
downloadnextcloud-server-7eef64360000ad0ea2e48c548cb1def51ac98bf0.tar.gz
nextcloud-server-7eef64360000ad0ea2e48c548cb1def51ac98bf0.zip
Merge pull request #2594 from owncloud/fix_part_file_ignoring
Fix part file ignoring
-rw-r--r--lib/files/cache/scanner.php66
-rw-r--r--lib/files/view.php6
2 files changed, 43 insertions, 29 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 661ece5b120..f019d4fc608 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -62,32 +62,35 @@ class Scanner {
* @return array with metadata of the scanned file
*/
public function scanFile($file, $checkExisting = false) {
- \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
- $data = $this->getData($file);
- if ($data) {
- if ($file) {
- $parent = dirname($file);
- if ($parent === '.') {
- $parent = '';
- }
- if (!$this->cache->inCache($parent)) {
- $this->scanFile($parent);
+ if (!self::isIgnoredFile($file)) {
+ \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
+ $data = $this->getData($file);
+ if ($data) {
+ if ($file) {
+ $parent = dirname($file);
+ if ($parent === '.') {
+ $parent = '';
+ }
+ if (!$this->cache->inCache($parent)) {
+ $this->scanFile($parent);
+ }
}
- }
- if($cacheData = $this->cache->get($file)) {
- if ($data['mtime'] === $cacheData['mtime'] &&
- $data['size'] === $cacheData['size']) {
- $data['etag'] = $cacheData['etag'];
+ if($cacheData = $this->cache->get($file)) {
+ if ($data['mtime'] === $cacheData['mtime'] &&
+ $data['size'] === $cacheData['size']) {
+ $data['etag'] = $cacheData['etag'];
+ }
}
- }
- if ($checkExisting and $cacheData) {
- if ($data['size'] === -1) {
- $data['size'] = $cacheData['size'];
+ if ($checkExisting and $cacheData) {
+ if ($data['size'] === -1) {
+ $data['size'] = $cacheData['size'];
+ }
}
+ $this->cache->put($file, $data);
}
- $this->cache->put($file, $data);
+ return $data;
}
- return $data;
+ return null;
}
/**
@@ -109,8 +112,8 @@ class Scanner {
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
- if (!$this->isIgnoredFile($file)) {
- $child = ($path) ? $path . '/' . $file : $file;
+ $child = ($path) ? $path . '/' . $file : $file;
+ if (!$this->isIgnoredDir($file)) {
$data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) {
if ($data['size'] === -1) {
@@ -145,15 +148,26 @@ class Scanner {
}
/**
+ * @brief check if the directory should be ignored when scanning
+ * NOTE: the special directories . and .. would cause never ending recursion
+ * @param String $dir
+ * @return boolean
+ */
+ private function isIgnoredDir($dir) {
+ if ($dir === '.' || $dir === '..') {
+ return true;
+ }
+ return false;
+ }
+ /**
* @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'
+ public static function isIgnoredFile($file) {
+ if (pathinfo($file, PATHINFO_EXTENSION) === 'part'
|| \OC\Files\Filesystem::isFileBlacklisted($file)
) {
return true;
diff --git a/lib/files/view.php b/lib/files/view.php
index 19f33ad64a2..e811fb093cc 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -267,7 +267,7 @@ class View {
$path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path);
$run = true;
- if ($this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
@@ -295,7 +295,7 @@ class View {
list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
- if ($this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
@@ -627,7 +627,7 @@ class View {
private function runHooks($hooks, $path, $post = false) {
$prefix = ($post) ? 'post_' : '';
$run = true;
- if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot()) {
+ if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && ! Cache\Scanner::isIgnoredFile($path) ) {
foreach ($hooks as $hook) {
if ($hook != 'read') {
\OC_Hook::emit(