[jhbuild] packagedb: store relative paths in manifest



commit 4b838a41e750092984e7ba00cc6377a05f0347a8
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Jan 18 12:13:22 2015 -0500

    packagedb: store relative paths in manifest
    
    This change does not actually touch any packagedb code, but rather
    changes its users to assume that the 'manifest' property is populated
    with relative pathnames.
    
    All readers pass the list through fileutils.filter_files_by_prefix() so
    modify that to take either paths relative to the given prefix or
    absolute paths (which will be filtered to limit them to the prefix).
    
    The code in process_install() is the only writer, so simply modify it to
    use relative paths.
    
    Although much of the software that jhbuild builds does not like to have
    its install prefix moved (due to hardcoding of paths), this change means
    that jhbuild itself theoretically has no problem with it.
    
    It also makes the process of generating tar files using the manifest
    slightly cleaner.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=743127

 jhbuild/modtypes/__init__.py |   33 ++++++++++++++++-----------------
 jhbuild/utils/fileutils.py   |    5 ++++-
 2 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/jhbuild/modtypes/__init__.py b/jhbuild/modtypes/__init__.py
index b7a06cc..664ce3c 100644
--- a/jhbuild/modtypes/__init__.py
+++ b/jhbuild/modtypes/__init__.py
@@ -291,18 +291,11 @@ them into the prefix."""
         prefix_without_drive = os.path.splitdrive(buildscript.config.prefix)[1]
         stripped_prefix = prefix_without_drive[1:]
 
-        previous_entry = buildscript.moduleset.packagedb.get(self.name)
-        if previous_entry:
-            previous_contents = previous_entry.get_manifest()
-        else:
-            previous_contents = None
-
-        new_contents = fileutils.accumulate_dirtree_contents(destdir)
-
         install_succeeded = False
         save_broken_tree = False
         broken_name = destdir + '-broken'
         destdir_prefix = os.path.join(destdir, stripped_prefix)
+        new_contents = fileutils.accumulate_dirtree_contents(destdir_prefix)
         errors = []
         if os.path.isdir(destdir_prefix):
             destdir_install = True
@@ -348,14 +341,20 @@ them into the prefix."""
         if not install_succeeded:
             raise CommandError(_("Module failed to install into DESTDIR %(dest)r") % {'dest': broken_name})
         else:
-            absolute_new_contents = map(lambda x: '/' + x, new_contents)
-            to_delete = []
-            if previous_contents is not None:
-                for path in previous_contents:
-                    if path not in absolute_new_contents:
-                        to_delete.append(path)
-                # Ensure we're only attempting to delete files in the prefix
-                to_delete = fileutils.filter_files_by_prefix(self.config, to_delete)
+            to_delete = set()
+            previous_entry = buildscript.moduleset.packagedb.get(self.name)
+            if previous_entry:
+                previous_contents = previous_entry.get_manifest()
+                if previous_contents:
+                    to_delete.update(fileutils.filter_files_by_prefix(self.config, previous_contents))
+
+            for filename in new_contents:
+                to_delete.discard (os.path.join(self.config.prefix, filename))
+
+            if to_delete:
+                # paranoid double-check
+                assert to_delete == set(fileutils.filter_files_by_prefix(self.config, to_delete))
+
                 logging.info(_('%d files remaining from previous build') % (len(to_delete),))
                 for (path, was_deleted, error_string) in fileutils.remove_files_and_dirs(to_delete, 
allow_nonempty_dirs=True):
                     if was_deleted:
@@ -368,7 +367,7 @@ them into the prefix."""
                                                                                                           
'msg': error_string})
 
             buildscript.moduleset.packagedb.add(self.name, revision or '',
-                                                absolute_new_contents,
+                                                new_contents,
                                                 self.configure_cmd)
 
         if errors:
diff --git a/jhbuild/utils/fileutils.py b/jhbuild/utils/fileutils.py
index 7842d29..e06fb4a 100644
--- a/jhbuild/utils/fileutils.py
+++ b/jhbuild/utils/fileutils.py
@@ -79,12 +79,15 @@ Returns a list, where each item is a 2-tuple:
     return results
 
 def filter_files_by_prefix(config, file_paths):
-    """Return the set of files in file_paths that are inside the prefix."""
+    """Return the set of files in file_paths that are inside the prefix.
+
+Turns relative paths into absolute paths, as appropriate."""
     canon_prefix = config.prefix
     if not canon_prefix.endswith(os.sep):
         canon_prefix = canon_prefix + os.sep
     result = []
     for path in file_paths:
+        path = os.path.join(config.prefix, path) # doesn't add the prefix if path is already absolute
         if path == canon_prefix or (not path.startswith(canon_prefix)):
             continue
         result.append(path)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]