From: Scott Worley Date: Thu, 18 Jun 2020 08:19:53 +0000 (-0700) Subject: Factor out symlink_archive() X-Git-Tag: 2.1.0~3 X-Git-Url: http://git.scottworley.com/pinch/commitdiff_plain/96063a5164fcd9e6ec72c1912d41d77856fa980f?ds=sidebyside;hp=9ee71b8de80b57ed5851203b581ac09b3792d2c8 Factor out symlink_archive() --- diff --git a/pinch.py b/pinch.py index b5e3b81..8c9e976 100644 --- a/pinch.py +++ b/pinch.py @@ -127,6 +127,15 @@ def copy_to_nix_store(v: Verification, filename: str) -> str: return process.stdout.decode().strip() # type: ignore # (for old mypy) +def symlink_archive(v: Verification, path: str) -> str: + with tempfile.TemporaryDirectory() as td: + archive_filename = os.path.join(td, 'link.tar.gz') + os.symlink(path, os.path.join(td, 'link')) + with tarfile.open(archive_filename, mode='x:gz') as t: + t.add(os.path.join(td, 'link'), arcname='link') + return copy_to_nix_store(v, archive_filename) + + class AliasSearchPath(NamedTuple): alias_of: str @@ -143,12 +152,7 @@ class SymlinkSearchPath(NamedTuple): return SymlinkPin() def fetch(self, v: Verification, _: Pin) -> str: - with tempfile.TemporaryDirectory() as td: - archive_filename = os.path.join(td, 'link.tar.gz') - os.symlink(self.path, os.path.join(td, 'link')) - with tarfile.open(archive_filename, mode='x:gz') as t: - t.add(os.path.join(td, 'link'), arcname='link') - return copy_to_nix_store(v, archive_filename) + return symlink_archive(v, self.path) class GitSearchPath(NamedTuple):