Skip to content

Commit

Permalink
fix: Correctly create NonExistingFolder during copy
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Nov 20, 2024
1 parent c39bf71 commit 68c6018
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Exception;
use OC\Files\Node\NonExistingFile;
use OC\Files\Node\NonExistingFolder;
use OCA\Files_Versions\Versions\IVersionBackend;
use OCA\Files_Versions\Versions\IVersionManager;
use OCA\Files_Versions\Versions\IVersionsImporterBackend;
Expand Down Expand Up @@ -130,7 +131,7 @@ private function handleMoveOrCopy(Event $event, IUser $user, File $source, File
}

private function getNodeStorage(Node $node): IStorage {
if ($node instanceof NonExistingFile) {
if ($node instanceof NonExistingFile || $node instanceof NonExistingFolder) {
return $node->getParent()->getStorage();
} else {
return $node->getStorage();
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/Node/HookConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function postRename($arguments) {

public function copy($arguments) {
$source = $this->getNodeForPath($arguments['oldpath']);
$target = $this->getNodeForPath($arguments['newpath']);
$target = $this->getNodeForPath($arguments['newpath'], $source instanceof Folder);
$this->root->emit('\OC\Files', 'preCopy', [$source, $target]);
$this->dispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target]));

Expand Down Expand Up @@ -203,7 +203,7 @@ public function read($arguments) {
$this->dispatcher->dispatchTyped($event);
}

private function getNodeForPath(string $path): Node {
private function getNodeForPath(string $path, bool $isDir = false): Node {
$info = Filesystem::getView()->getFileInfo($path);
if (!$info) {
$fullPath = Filesystem::getView()->getAbsolutePath($path);
Expand All @@ -212,7 +212,7 @@ private function getNodeForPath(string $path): Node {
} else {
$info = null;
}
if (Filesystem::is_dir($path)) {
if ($isDir || Filesystem::is_dir($path)) {
return new NonExistingFolder($this->root, $this->view, $fullPath, $info);
} else {
return new NonExistingFile($this->root, $this->view, $fullPath, $info);
Expand Down

0 comments on commit 68c6018

Please sign in to comment.