Browse Source

Some more cleanup for getFIleInfo/getDirectoryContent

remotes/origin/fix-delete-homeidr-on-userdelete
Robin Appelman 10 years ago
parent
commit
1736c70075
  1. 11
      lib/private/files/fileinfo.php
  2. 70
      lib/private/files/view.php

11
lib/private/files/fileinfo.php

@ -285,4 +285,15 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
public function getOwner() { public function getOwner() {
return $this->owner; return $this->owner;
} }
/**
* Add a cache entry which is the child of this folder
*
* Sets the size, etag and size to for cross-storage childs
*
* @param array $data cache entry for the child
*/
public function addSubEntry($data) {
$this->data['size'] += isset($data['size']) ? $data['size'] : 0;
}
} }

70
lib/private/files/view.php

@ -1226,9 +1226,8 @@ class View {
*/ */
public function getFileInfo($path, $includeMountPoints = true) { public function getFileInfo($path, $includeMountPoints = true) {
$this->assertPathLength($path); $this->assertPathLength($path);
$data = array();
if (!Filesystem::isValidPath($path)) { if (!Filesystem::isValidPath($path)) {
return $data;
return false;
} }
if (Cache\Scanner::isPartialFile($path)) { if (Cache\Scanner::isPartialFile($path)) {
return $this->getPartFileInfo($path); return $this->getPartFileInfo($path);
@ -1239,10 +1238,16 @@ class View {
$mount = Filesystem::getMountManager()->find($path); $mount = Filesystem::getMountManager()->find($path);
$storage = $mount->getStorage(); $storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($path); $internalPath = $mount->getInternalPath($path);
$data = null;
if ($storage) { if ($storage) {
$data = $this->getCacheEntry($storage, $internalPath, $relativePath); $data = $this->getCacheEntry($storage, $internalPath, $relativePath);
if ($mount instanceof MoveableMount && $internalPath === '') {
$data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
}
$owner = $this->getUserObjectForOwner($storage->getOwner($internalPath));
$info = new FileInfo($path, $storage, $internalPath, $data, $mount, $owner);
if ($data and isset($data['fileid'])) { if ($data and isset($data['fileid'])) {
if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') { if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
//add the sizes of other mount points to the folder //add the sizes of other mount points to the folder
@ -1257,22 +1262,16 @@ class View {
} }
$subCache = $subStorage->getCache(''); $subCache = $subStorage->getCache('');
$rootEntry = $subCache->get(''); $rootEntry = $subCache->get('');
$data['size'] += isset($rootEntry['size']) ? $rootEntry['size'] : 0;
$info->addSubEntry($rootEntry);
} }
} }
} }
} }
}
if (!$data) {
return false;
}
if ($mount instanceof MoveableMount && $internalPath === '') {
$data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
return $info;
} }
$owner = $this->getUserObjectForOwner($storage->getOwner($internalPath));
return new FileInfo($path, $storage, $internalPath, $data, $mount, $owner);
return false;
} }
/** /**
@ -1284,9 +1283,8 @@ class View {
*/ */
public function getDirectoryContent($directory, $mimetype_filter = '') { public function getDirectoryContent($directory, $mimetype_filter = '') {
$this->assertPathLength($directory); $this->assertPathLength($directory);
$result = array();
if (!Filesystem::isValidPath($directory)) { if (!Filesystem::isValidPath($directory)) {
return $result;
return [];
} }
$path = $this->getAbsolutePath($directory); $path = $this->getAbsolutePath($directory);
$path = Filesystem::normalizePath($path); $path = Filesystem::normalizePath($path);
@ -1297,11 +1295,6 @@ class View {
$cache = $storage->getCache($internalPath); $cache = $storage->getCache($internalPath);
$user = \OC_User::getUser(); $user = \OC_User::getUser();
/**
* @var \OC\Files\FileInfo[] $files
*/
$files = [];
$data = $this->getCacheEntry($storage, $internalPath, $directory); $data = $this->getCacheEntry($storage, $internalPath, $directory);
if (!is_array($data) || !isset($data['fileid'])) { if (!is_array($data) || !isset($data['fileid'])) {
@ -1311,18 +1304,16 @@ class View {
$folderId = $data['fileid']; $folderId = $data['fileid'];
$contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
foreach ($contents as $content) {
if ($content['permissions'] === 0) {
$content['permissions'] = $storage->getPermissions($content['path']);
$cache->update($content['fileid'], array('permissions' => $content['permissions']));
}
// if sharing was disabled for the user we remove the share permissions
/**
* @var \OC\Files\FileInfo[] $files
*/
$files = array_map(function (array $content) use ($path, $storage, $mount) {
if (\OCP\Util::isSharingDisabledForUser()) { if (\OCP\Util::isSharingDisabledForUser()) {
$content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE; $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
} }
$owner = $this->getUserObjectForOwner($storage->getOwner($content['path'])); $owner = $this->getUserObjectForOwner($storage->getOwner($content['path']));
$files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
}
return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
}, $contents);
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
$mounts = Filesystem::getMountManager()->findIn($path); $mounts = Filesystem::getMountManager()->findIn($path);
@ -1333,7 +1324,8 @@ class View {
if ($subStorage) { if ($subStorage) {
$subCache = $subStorage->getCache(''); $subCache = $subStorage->getCache('');
if ($subCache->getStatus('') === Cache\Cache::NOT_FOUND) {
$rootEntry = $subCache->get('');
if (!$rootEntry) {
$subScanner = $subStorage->getScanner(''); $subScanner = $subStorage->getScanner('');
try { try {
$subScanner->scanFile(''); $subScanner->scanFile('');
@ -1351,17 +1343,17 @@ class View {
); );
continue; continue;
} }
$rootEntry = $subCache->get('');
} }
$rootEntry = $subCache->get('');
if ($rootEntry) { if ($rootEntry) {
$relativePath = trim(substr($mountPoint, $dirLength), '/'); $relativePath = trim(substr($mountPoint, $dirLength), '/');
if ($pos = strpos($relativePath, '/')) { if ($pos = strpos($relativePath, '/')) {
//mountpoint inside subfolder add size to the correct folder //mountpoint inside subfolder add size to the correct folder
$entryName = substr($relativePath, 0, $pos); $entryName = substr($relativePath, 0, $pos);
foreach ($files as &$entry) { foreach ($files as &$entry) {
if ($entry['name'] === $entryName) {
$entry['size'] += $rootEntry['size'];
if ($entry->getName() === $entryName) {
$entry->addSubEntry($rootEntry);
} }
} }
} else { //mountpoint in this folder, add an entry for it } else { //mountpoint in this folder, add an entry for it
@ -1398,23 +1390,23 @@ class View {
} }
if ($mimetype_filter) { if ($mimetype_filter) {
foreach ($files as $file) {
$files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
if (strpos($mimetype_filter, '/')) { if (strpos($mimetype_filter, '/')) {
if ($file['mimetype'] === $mimetype_filter) {
if ($file->getMimetype() === $mimetype_filter) {
$result[] = $file; $result[] = $file;
} }
} else { } else {
if ($file['mimepart'] === $mimetype_filter) {
if ($file->getMimePart() === $mimetype_filter) {
$result[] = $file; $result[] = $file;
} }
} }
}
} else {
$result = $files;
});
} }
}
return $result;
return $files;
} else {
return [];
}
} }
/** /**

Loading…
Cancel
Save