Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle version folders for file spaces #301

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 24 additions & 2 deletions lib/Crypto/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function getDisplayName() {
* or if no additional data is needed return a empty array
*/
public function begin($path, $user, $mode, array $header, array $accessList, $sourceFileOfRename = null) {
$this->path = $this->getPathToRealFile($path);
$this->path = $this->getPathToRealFile($path, $user);
$this->accessList = $accessList;
$this->user = $user;
$this->isWriteOperation = false;
Expand Down Expand Up @@ -545,7 +545,7 @@ public function prepareDecryptAll(InputInterface $input, OutputInterface $output
* @param string $path
* @return string
*/
protected function getPathToRealFile($path) {
protected function getPathToRealFile($path, $user) {
$realPath = $path;
$parts = \explode('/', $path);
if ($parts[2] === 'files_versions') {
Expand All @@ -554,6 +554,28 @@ protected function getPathToRealFile($path) {
$realPath = \substr($realPath, 0, $length);
}

// handle versions for file spaces
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use a similar as we use in the core patch:

  • get the storage
  • call a new method getPathToRealFile
  • default implementation returns the logic above
  • file spaces return the logic below

if ($parts[1] === 'files_spaces' && $parts[3] === 'versions') {
$fileId = (int)$parts[4];
$cache = \OC::$server->getMountProviderCollection()->getMountCache();
$mounts = $cache->getMountsForFileId($fileId);
$filePath = $mounts[0]->getMountPoint();

$view = new View();
$fileInfo = $view->getFileInfo($path);
$storage = $fileInfo->getStorage();

$cache = $storage->getCache();
$fileName = $cache->get($fileId)->getPath();
$pathParts = \explode("/", $filePath);
if ($pathParts[1] !== $user) {
$pathParts[1] = $user;
$filePath = \implode("/", $pathParts);
}

return $filePath . $fileName;
}

return $realPath;
}

Expand Down