From d0fa3f461064367087e36e0fb0f47a84a0fa94d8 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Fri, 10 Jun 2022 11:18:07 +0200 Subject: [PATCH] Use blunt force to drop keys on windows This is a rather draconian workaround: Instead of dropping the repoannex keys, it wipes out the entire object tree of the local repoannex utility repo. This addresses https://git-annex.branchable.com/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/?updated which is still happing with today's git-annex snapshot. This approach possible, because this utility repo is constructed on the fly from the URL specification, and only contains the two keys that need to be dropped. However, given the bluntness of the approach, it is limited to the platform on which the original issue is happening: windows. Closes datalad/datalad-next#26 --- datalad_next/gitremote/datalad_annex.py | 22 ++++++++++++++++--- .../gitremote/tests/test_datalad_annex.py | 4 ---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/datalad_next/gitremote/datalad_annex.py b/datalad_next/gitremote/datalad_annex.py index 077737cf..2d35e425 100755 --- a/datalad_next/gitremote/datalad_annex.py +++ b/datalad_next/gitremote/datalad_annex.py @@ -208,7 +208,10 @@ from datalad.support.gitrepo import GitRepo from datalad.support.constraints import EnsureInt from datalad.ui import ui -from datalad.utils import rmtree +from datalad.utils import ( + on_windows, + rmtree, +) from datalad_next.credman import CredentialManager from datalad_next.utils import ( @@ -744,7 +747,20 @@ def replace_remote_deposit_from_mirrorrepo(self): # update the repo state keys # it is critical to drop the local keys first, otherwise # `setkey` below will not replace them with new content - self.log(repoannex.call_annex(['drop', '--force', '--all'])) + # however, git-annex fails to do so in some edge cases + # https://git-annex.branchable.com/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/?updated + # no regular `drop` works, nor does `dropkeys` + #self.log(repoannex.call_annex(['drop', '--force', '--all'])) + # nuclear option remains, luckily possible in this utility repo + if on_windows: + objdir = self.repoannex.dot_git / 'annex' / 'objects' + if objdir.exists(): + rmtree(str(objdir), ignore_errors=True) + objdir.mkdir() + else: + # more surgical for the rest + self.log(repoannex.call_annex([ + 'dropkey', '--force', self.refs_key, self.repo_export_key])) # use our zipfile wrapper to get an LZMA compressed archive # via the shutil convenience layer @@ -763,7 +779,7 @@ def replace_remote_deposit_from_mirrorrepo(self): # hand over archive to annex repoannex.call_annex([ 'setkey', - 'XDLRA--repo-export', + self.repo_export_key, archive_file ]) # generate a list of refs diff --git a/datalad_next/gitremote/tests/test_datalad_annex.py b/datalad_next/gitremote/tests/test_datalad_annex.py index 014a0a7b..69b8cb4f 100644 --- a/datalad_next/gitremote/tests/test_datalad_annex.py +++ b/datalad_next/gitremote/tests/test_datalad_annex.py @@ -28,8 +28,6 @@ neq_, rmtree, serve_path_via_http, - skip_if_on_windows, - SkipTest, with_tempfile, ) from datalad.utils import on_windows @@ -60,8 +58,6 @@ def eq_dla_branch_state(state, path, branch=DEFAULT_BRANCH): assert None, f'Could not find state for branch {branch} at {path}' -# https://git-annex.branchable.com/bugs/Fails_to_drop_key_on_windows___40__Access_denied__41__/?updated -@skip_if_on_windows @with_tempfile @with_tempfile(mkdir=True) def test_annex_remote(dspath, remotepath):