chiark / gitweb /
agpl.py: Fix up symbolic links between directories being dumped.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 27 Mar 2013 21:26:39 +0000 (21:26 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 27 Mar 2013 21:29:54 +0000 (21:29 +0000)
This should make deployment from generated tarballs easier.

agpl.py

diff --git a/agpl.py b/agpl.py
index 734be25..43eba82 100644 (file)
--- a/agpl.py
+++ b/agpl.py
@@ -101,10 +101,24 @@ def dump_dir(name, dir, dirmap, tf, root):
     raise U.ExpectedError, (500, "no dumper for `%s'" % dir)
   tf.add(dir, OS.path.join(root, name), recursive = False)
   for lister in listers:
-    base = OS.path.basename(dir)
     for file in lister(dir):
-      tf.add(OS.path.join(dir, file), OS.path.join(root, base, file),
-             recursive = False)
+      full = OS.path.join(dir, file)
+      tarname = OS.path.join(root, name, file)
+      skip = False
+      if OS.path.islink(full):
+        dest = OS.path.realpath(full)
+        for d, local in dirmap:
+          if dest.startswith(d):
+            fix = OS.path.relpath(OS.path.join('/', local, dest[len(d):]),
+                                  OS.path.join('/', name,
+                                               OS.path.dirname(file)))
+            st = OS.stat(full)
+            ti = tf.gettarinfo(full, tarname)
+            ti.linkname = fix
+            tf.addfile(ti)
+            skip = True
+      if not skip:
+        tf.add(full, tarname, recursive = False)
 
 def source(out):
   if SYS.version_info >= (2, 6):