Add checks for storage object

This commit is contained in:
Michael Gapczynski 2012-11-24 16:42:54 -05:00
parent 555dec2d92
commit c47bf9bbce
2 changed files with 127 additions and 109 deletions

View File

@ -20,13 +20,14 @@ $mountPoints = array_reverse($mountPoints); //start with the mount point of $dir
foreach ($mountPoints as $mountPoint) { foreach ($mountPoints as $mountPoint) {
$storage = \OC\Files\Filesystem::getStorage($mountPoint); $storage = \OC\Files\Filesystem::getStorage($mountPoint);
error_log('scanning mp '.$mountPoint); if ($storage) {
ScanListener::$mountPoints[$storage->getId()] = $mountPoint; ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
$scanner = $storage->getScanner(); $scanner = $storage->getScanner();
if ($force) { if ($force) {
$scanner->scan(''); $scanner->scan('');
} else { } else {
$scanner->backgroundScan(); $scanner->backgroundScan();
}
} }
} }

View File

@ -671,39 +671,41 @@ class View {
* - versioned * - versioned
*/ */
public function getFileInfo($path) { public function getFileInfo($path) {
$data = array();
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
/** /**
* @var \OC\Files\Storage\Storage $storage * @var \OC\Files\Storage\Storage $storage
* @var string $internalPath * @var string $internalPath
*/ */
list($storage, $internalPath) = Filesystem::resolvePath($path); list($storage, $internalPath) = Filesystem::resolvePath($path);
$cache = $storage->getCache(); if ($storage) {
$cache = $storage->getCache();
if (!$cache->inCache($internalPath)) { if (!$cache->inCache($internalPath)) {
$scanner = $storage->getScanner(); $scanner = $storage->getScanner();
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
} else { } else {
$watcher = new \OC\Files\Cache\Watcher($storage); $watcher = new \OC\Files\Cache\Watcher($storage);
$watcher->checkUpdate($internalPath); $watcher->checkUpdate($internalPath);
}
$data = $cache->get($internalPath);
if ($data['mimetype'] === 'httpd/unix-directory') {
//add the sizes of other mountpoints to the folder
$mountPoints = Filesystem::getMountPoints($path);
foreach ($mountPoints as $mountPoint) {
$subStorage = Filesystem::getStorage($mountPoint);
$subCache = $subStorage->getCache();
$rootEntry = $subCache->get('');
$data['size'] += $rootEntry['size'];
} }
$data = $cache->get($internalPath);
if ($data['mimetype'] === 'httpd/unix-directory') {
//add the sizes of other mountpoints to the folder
$mountPoints = Filesystem::getMountPoints($path);
foreach ($mountPoints as $mountPoint) {
$subStorage = Filesystem::getStorage($mountPoint);
$subCache = $subStorage->getCache();
$rootEntry = $subCache->get('');
$data['size'] += $rootEntry['size'];
}
}
$permissionsCache = $storage->getPermissionsCache();
$data['permissions'] = $permissionsCache->get($data['fileid'], \OC_User::getUser());
} }
$permissionsCache = $storage->getPermissionsCache();
$data['permissions'] = $permissionsCache->get($data['fileid'], \OC_User::getUser());
return $data; return $data;
} }
@ -714,75 +716,79 @@ class View {
* @return array * @return array
*/ */
public function getDirectoryContent($directory, $mimetype_filter = '') { public function getDirectoryContent($directory, $mimetype_filter = '') {
$result = array();
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory); $path = Filesystem::normalizePath($this->fakeRoot . '/' . $directory);
/** /**
* @var \OC\Files\Storage\Storage $storage * @var \OC\Files\Storage\Storage $storage
* @var string $internalPath * @var string $internalPath
*/ */
list($storage, $internalPath) = Filesystem::resolvePath($path); list($storage, $internalPath) = Filesystem::resolvePath($path);
$cache = $storage->getCache(); if ($storage) {
$cache = $storage->getCache();
if (!$cache->inCache($internalPath)) { if (!$cache->inCache($internalPath)) {
$scanner = $storage->getScanner(); $scanner = $storage->getScanner();
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
} else { } else {
$watcher = new \OC\Files\Cache\Watcher($storage); $watcher = new \OC\Files\Cache\Watcher($storage);
$watcher->checkUpdate($internalPath); $watcher->checkUpdate($internalPath);
}
$files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
$mountPoints = Filesystem::getMountPoints($path);
$dirLength = strlen($path);
foreach ($mountPoints as $mountPoint) {
$subStorage = Filesystem::getStorage($mountPoint);
$subCache = $subStorage->getCache();
$rootEntry = $subCache->get('');
$relativePath = trim(substr($mountPoint, $dirLength), '/');
if ($pos = strpos($relativePath, '/')) { //mountpoint inside subfolder add size to the correct folder
$entryName = substr($relativePath, 0, $pos);
foreach ($files as &$entry) {
if ($entry['name'] === $entryName) {
$entry['size'] += $rootEntry['size'];
}
}
} else { //mountpoint in this folder, add an entry for it
$rootEntry['name'] = $relativePath;
$files[] = $rootEntry;
} }
}
$ids = array(); $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
foreach ($files as $i => $file) { //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
$files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file'; $mountPoints = Filesystem::getMountPoints($path);
$ids[] = $file['fileid']; $dirLength = strlen($path);
} foreach ($mountPoints as $mountPoint) {
$permissionsCache = $storage->getPermissionsCache(); $subStorage = Filesystem::getStorage($mountPoint);
if ($subStorage) {
$subCache = $subStorage->getCache();
$rootEntry = $subCache->get('');
$permissions = $permissionsCache->getMultiple($ids, \OC_User::getUser()); $relativePath = trim(substr($mountPoint, $dirLength), '/');
foreach ($files as $i => $file) { if ($pos = strpos($relativePath, '/')) { //mountpoint inside subfolder add size to the correct folder
$files[$i]['permissions'] = $permissions[$file['fileid']]; $entryName = substr($relativePath, 0, $pos);
} foreach ($files as &$entry) {
if ($entry['name'] === $entryName) {
if ($mimetype_filter) { $entry['size'] += $rootEntry['size'];
foreach ($files as $file) { }
if (strpos($mimetype_filter, '/')) { }
if ($file['mimetype'] === $mimetype_filter) { } else { //mountpoint in this folder, add an entry for it
$result[] = $file; $rootEntry['name'] = $relativePath;
} $files[] = $rootEntry;
} else {
if ($file['mimepart'] === $mimetype_filter) {
$result[] = $file;
} }
} }
} }
} else {
$result = $files;
}
$ids = array();
foreach ($files as $i => $file) {
$files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$ids[] = $file['fileid'];
}
$permissionsCache = $storage->getPermissionsCache();
$permissions = $permissionsCache->getMultiple($ids, \OC_User::getUser());
foreach ($files as $i => $file) {
$files[$i]['permissions'] = $permissions[$file['fileid']];
}
if ($mimetype_filter) {
foreach ($files as $file) {
if (strpos($mimetype_filter, '/')) {
if ($file['mimetype'] === $mimetype_filter) {
$result[] = $file;
}
} else {
if ($file['mimepart'] === $mimetype_filter) {
$result[] = $file;
}
}
}
} else {
$result = $files;
}
}
return $result; return $result;
} }
@ -802,14 +808,18 @@ class View {
* @var string $internalPath * @var string $internalPath
*/ */
list($storage, $internalPath) = Filesystem::resolvePath($path); list($storage, $internalPath) = Filesystem::resolvePath($path);
$cache = $storage->getCache(); if ($storage) {
$cache = $storage->getCache();
if (!$cache->inCache($internalPath)) { if (!$cache->inCache($internalPath)) {
$scanner = $storage->getScanner(); $scanner = $storage->getScanner();
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
}
return $cache->put($internalPath, $data);
} else {
return -1;
} }
return $cache->put($internalPath, $data);
} }
/** /**
@ -843,29 +853,32 @@ class View {
$mountPoint = Filesystem::getMountPoint($this->fakeRoot); $mountPoint = Filesystem::getMountPoint($this->fakeRoot);
$storage = Filesystem::getStorage($mountPoint); $storage = Filesystem::getStorage($mountPoint);
$cache = $storage->getCache(); if ($storage) {
$results = $cache->$method($query);
foreach ($results as $result) {
if (substr($mountPoint . $result['path'], 0, $rootLength) === $this->fakeRoot) {
$result['path'] = substr($mountPoint . $result['path'], $rootLength);
$files[] = $result;
}
}
$mountPoints = Filesystem::getMountPoints($this->fakeRoot);
foreach ($mountPoints as $mountPoint) {
$storage = Filesystem::getStorage($mountPoint);
$cache = $storage->getCache(); $cache = $storage->getCache();
$relativeMountPoint = substr($mountPoint, $rootLength);
$results = $cache->$method($query); $results = $cache->$method($query);
foreach ($results as $result) { foreach ($results as $result) {
$result['path'] = $relativeMountPoint . $result['path']; if (substr($mountPoint . $result['path'], 0, $rootLength) === $this->fakeRoot) {
$files[] = $result; $result['path'] = substr($mountPoint . $result['path'], $rootLength);
$files[] = $result;
}
}
$mountPoints = Filesystem::getMountPoints($this->fakeRoot);
foreach ($mountPoints as $mountPoint) {
$storage = Filesystem::getStorage($mountPoint);
if ($storage) {
$cache = $storage->getCache();
$relativeMountPoint = substr($mountPoint, $rootLength);
$results = $cache->$method($query);
foreach ($results as $result) {
$result['path'] = $relativeMountPoint . $result['path'];
$files[] = $result;
}
}
} }
} }
return $files; return $files;
} }
@ -881,6 +894,10 @@ class View {
* @var string $internalPath * @var string $internalPath
*/ */
list($storage, $internalPath) = $this->resolvePath($path); list($storage, $internalPath) = $this->resolvePath($path);
return $storage->getETag($internalPath); if ($storage) {
return $storage->getETag($internalPath);
} else {
return null;
}
} }
} }