From 8376a360ccafe43f83b86b8b3c480fb7a0698a61 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Tue, 2 Jun 2020 13:46:57 +1000 Subject: [PATCH] Check if symbolic link is relative to location path (#942) * If a symbolic link is 'relative', it is relative to the path where the symbolic link exists, not the current working directory. Test if the failed symbolic link read is due to the link being relative, and advise accordingly. --- src/sync.d | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/sync.d b/src/sync.d index b2a6ab3f..daf8b7ff 100644 --- a/src/sync.d +++ b/src/sync.d @@ -2855,8 +2855,30 @@ final class SyncEngine } // skip unexisting symbolic links else if (!exists(readLink(path))) { - log.log("Skipping item - invalid symbolic link: ", path); - return; + // reading the symbolic link failed - is the link a relative symbolic link + // drwxrwxr-x. 2 alex alex 46 May 30 09:16 . + // drwxrwxr-x. 3 alex alex 35 May 30 09:14 .. + // lrwxrwxrwx. 1 alex alex 61 May 30 09:16 absolute.txt -> /home/alex/OneDrivePersonal/link_tests/intercambio/prueba.txt + // lrwxrwxrwx. 1 alex alex 13 May 30 09:16 relative.txt -> ../prueba.txt + // + // absolute links will be able to be read, but 'relative' links will fail, because they cannot be read based on the current working directory 'sync_dir' + string currentSyncDir = getcwd(); + string fullLinkPath = buildNormalizedPath(absolutePath(path)); + string fileName = baseName(fullLinkPath); + string parentLinkPath = dirName(fullLinkPath); + // test if this is a 'relative' symbolic link + chdir(parentLinkPath); + auto relativeLink = readLink(fileName); + auto relativeLinkTest = exists(readLink(fileName)); + // reset back to our 'sync_dir' + chdir(currentSyncDir); + // results + if (relativeLinkTest) { + log.vdebug("Not skipping item - symbolic link is a 'relative link' to target ('", relativeLink, "') which can be supported: ", path); + } else { + log.log("Skipping item - invalid symbolic link: ", path); + return; + } } }