From 4daff73a63870276827cf2e490b28a21b0488249 Mon Sep 17 00:00:00 2001 From: Matt Richards Date: Mon, 15 Feb 2021 20:38:29 +1000 Subject: [PATCH] change link dest function to handle '\?\' links --- .github/workflows/build.yml | 2 -- dotbot/plugins/link.py | 23 +++++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6364cde..f9fd0be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,8 +2,6 @@ name: CI on: push: pull_request: - schedule: - - cron: '0 8 * * 6' jobs: build: runs-on: ubuntu-latest diff --git a/dotbot/plugins/link.py b/dotbot/plugins/link.py index 6f2b562..b52f4b5 100644 --- a/dotbot/plugins/link.py +++ b/dotbot/plugins/link.py @@ -22,6 +22,7 @@ class Link(dotbot.Plugin): return self._process_links(data) def _process_links(self, links): + # print("symlinking\n\t", links) success = True defaults = self._context.defaults().get('link', {}) for destination, source in links.items(): @@ -129,10 +130,28 @@ class Link(dotbot.Plugin): def _link_destination(self, path): ''' - Returns the destination of the symbolic link. + Returns the destination of the symbolic link. Truncates the \\?\ start to a path if it + is present. This is an identifier which allows >255 character file name links to work. + Since this function is for the point of comparison, it is okay to truncate ''' + # path = os.path.normpath(path) path = os.path.expanduser(path) - return os.readlink(path) + try: + read_link = os.readlink(path) + # Read link can return paths starting with \\?\ - this allows over the 255 file name + # limit + except OSError as e: + if "[WinError 4390] The file or directory is not a reparse point" in str(e) and \ + os.path.isdir(path): + return "UNLINKED_DIR" + return "OSERROR_READING_LINK" + except Exception as e: + print(e) + return 'GENERAL_EXCEPTION_READING_LINK' + else: + if read_link.startswith("\\\\?\\"): + read_link = read_link.replace("\\\\?\\", "") + return read_link def _exists(self, path): '''