Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,19 @@ private function init() {
$this->initialized = true;
try {
Filesystem::initMountPoints($this->superShare->getShareOwner());
$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath);
$this->storage = new PermissionsMask([
'storage' => $this->nonMaskedStorage,
'mask' => $this->superShare->getPermissions()
]);
$this->rootPath = $this->getSourceRootInfo()->getPath();
$mounts = $this->ownerView->getMountByNumericId($this->getSourceRootInfo()->getStorageId());
if(!$mounts) {
$this->storage = new FailedStorage(['exception' => new \Exception('Mount for source storage not found')]);
$this->cache = new FailedCache();
$this->rootPath = '';
} else {
$this->nonMaskedStorage = $mounts[0]->getStorage();
$this->storage = new PermissionsMask([
'storage' => $this->nonMaskedStorage,
'mask' => $this->superShare->getPermissions()
]);
}
} catch (NotFoundException $e) {
// original file not accessible or deleted, set FailedStorage
$this->storage = new FailedStorage(['exception' => $e]);
Expand Down
35 changes: 18 additions & 17 deletions lib/private/Files/Mount/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ public function __construct() {
$this->inPathCache = new CappedMemoryCache();
}

private function invalidateCaches() {
$this->pathCache->clear();
$this->inPathCache->clear();
}

/**
* @param IMountPoint $mount
*/
public function addMount(IMountPoint $mount) {
$this->mounts[$mount->getMountPoint()] = $mount;
$this->pathCache->clear();
$this->inPathCache->clear();
$this->invalidateCaches();
}

/**
Expand All @@ -64,8 +68,7 @@ public function removeMount(string $mountPoint) {
$mountPoint .= '/';
}
unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
$this->inPathCache->clear();
$this->invalidateCaches();
}

/**
Expand All @@ -75,8 +78,7 @@ public function removeMount(string $mountPoint) {
public function moveMount(string $mountPoint, string $target) {
$this->mounts[$target] = $this->mounts[$mountPoint];
unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
$this->inPathCache->clear();
$this->invalidateCaches();
}

/**
Expand Down Expand Up @@ -141,8 +143,7 @@ public function findIn(string $path): array {

public function clear() {
$this->mounts = [];
$this->pathCache->clear();
$this->inPathCache->clear();
$this->invalidateCaches();
}

/**
Expand All @@ -156,13 +157,10 @@ public function findByStorageId(string $id): array {
if (\strlen($id) > 64) {
$id = md5($id);
}
$result = [];
foreach ($this->mounts as $mount) {
if ($mount->getStorageId() === $id) {
$result[] = $mount;
}
}
return $result;
$mounts = array_filter($this->mounts, function(IMountPoint $mountPoint) use ($id) {
return $mountPoint->getStorageId() === $id;
});
return array_values($mounts);
}

/**
Expand All @@ -179,8 +177,11 @@ public function getAll(): array {
* @return MountPoint[]
*/
public function findByNumericId(int $id): array {
$storageId = \OC\Files\Cache\Storage::getStorageId($id);
return $this->findByStorageId($storageId);
\OC_Util::setupFS();
$mounts = array_filter($this->mounts, function(IMountPoint $mountPoint) use ($id) {
return $mountPoint->getNumericStorageId() === $id;
});
return array_values($mounts);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ public function getMount($path) {
return Filesystem::getMountManager()->find($this->getAbsolutePath($path));
}

/**
* @param int $id
* @return IMountPoint[]
*/
public function getMountByNumericId($id) {
$mounts = Filesystem::getMountByNumericId($id);
return array_values(array_filter($mounts, function(IMountPoint $mountPoint) {
return $this->getRelativePath($mountPoint->getMountPoint()) || $mountPoint->getInternalPath($this->fakeRoot);
}));
}

/**
* resolve a path to a storage and internal path
*
Expand Down