ignore files in scanFile instead of scan to catch all occurences.

This commit is contained in:
Jörn Friedrich Dreyer 2013-03-22 13:52:07 +01:00
parent 7098bcd4b7
commit 4a70315ad1

View file

@ -62,32 +62,36 @@ 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->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 (!$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 ($checkExisting and $cacheData) {
if ($data['size'] === -1) {
$data['size'] = $cacheData['size'];
}
}
$this->cache->put($file, $data);
}
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'];
}
}
$this->cache->put($file, $data);
return $data;
}
return $data;
\OCP\Util::writeLog('scanner', 'Ignoring '.$file.' and not triggering scan_file hook.', \OCP\Util::DEBUG);
return null;
}
/**
@ -109,8 +113,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) {
@ -144,6 +148,20 @@ class Scanner {
return $size;
}
/**
* @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 === '..'
|| \OC\Files\Filesystem::isFileBlacklisted($file)
) {
return true;
}
return false;
}
/**
* @brief check if the file should be ignored when scanning
* NOTE: files with a '.part' extension are ignored as well!
@ -152,8 +170,7 @@ class Scanner {
* @return boolean
*/
private function isIgnoredFile($file) {
if ($file === '.' || $file === '..'
|| pathinfo($file, PATHINFO_EXTENSION) === 'part'
if (pathinfo($file, PATHINFO_EXTENSION) === 'part'
|| \OC\Files\Filesystem::isFileBlacklisted($file)
) {
return true;