From dfce7845a1e3db40bad74b7b09069f7075c0dc67 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 31 Aug 2022 19:00:03 +0100 Subject: [PATCH] Proper derivation of the visible path and invisible root when downloading folders --- .../core/files/PersisterFolderService.groovy | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy b/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy index f21d91f9..1b889e96 100644 --- a/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/PersisterFolderService.groovy @@ -305,17 +305,21 @@ class PersisterFolderService extends BasePersisterService { * Generates a path with explicit shared parent * @param file that is being shared * @param explicitParent explicit parent - * @return a Path from parent to file + * @return a Path including invisible root suitable for insertion into trees */ private Path explicitSharedParent(File file, File explicitParent) { - File parent = file.getParentFile() - if (parent == explicitParent) - return Path.of(saltHash) - Path toParent = explicitParent.toPath().relativize(parent.toPath()) + String invisibleRoot + File parentOfParent = explicitParent.getParentFile() + if (parentOfParent == null) + invisibleRoot = saltHash + else { + invisibleRoot = cachedRoots.computeIfAbsent(parentOfParent.toPath(), {mac(it)}) + } + + File parent = file.getParentFile() + Path toParent = explicitParent.getCanonicalFile().toPath().relativize(parent.getCanonicalFile().toPath()) Path visible = Path.of(explicitParent.getName(), toParent.toString()) - Path invisible = explicitParent.getParentFile().toPath() - String invisibleRoot = cachedRoots.computeIfAbsent(invisible,{mac(it)}) return Path.of(invisibleRoot, visible.toString()) }