]> git.scottworley.com Git - pinch/commitdiff
Factor out symlink_archive()
authorScott Worley <scottworley@scottworley.com>
Thu, 18 Jun 2020 08:19:53 +0000 (01:19 -0700)
committerScott Worley <scottworley@scottworley.com>
Thu, 18 Jun 2020 08:19:53 +0000 (01:19 -0700)
pinch.py

index b5e3b81567894101a9ee0d9cc9de34f253c15dd1..8c9e976583ffd4c2e5d049245ee4dc90db1e3742 100644 (file)
--- 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)
 
 
     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
 
 class AliasSearchPath(NamedTuple):
     alias_of: str
 
@@ -143,12 +152,7 @@ class SymlinkSearchPath(NamedTuple):
         return SymlinkPin()
 
     def fetch(self, v: Verification, _: Pin) -> str:
         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):
 
 
 class GitSearchPath(NamedTuple):