diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index f0843924..f3b51328 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -302,6 +302,7 @@ class Install(AtomicOperation): if changed: config_changed.append(fpath) + self.historydb.save_config(fpath) if os.path.exists(fpath + '.old'): os.unlink(fpath + '.old') os.rename(fpath, fpath + '.old') @@ -502,6 +503,7 @@ class Remove(AtomicOperation): fpath = pisi.util.join_path(ctx.config.dest_dir(), fileinfo.path) + historydb = pisi.db.historydb.HistoryDB() filesdb = pisi.db.filesdb.FilesDB() # we should check if the file belongs to another # package (this can legitimately occur while upgrading @@ -519,6 +521,9 @@ class Remove(AtomicOperation): try: if pisi.util.sha1_file(fpath) == fileinfo.hash: os.unlink(fpath) + else: + # keep changed file in history + historydb.save_config(fpath) except pisi.util.FileError: pass else: diff --git a/pisi/db/historydb.py b/pisi/db/historydb.py index bea956cc..39204274 100644 --- a/pisi/db/historydb.py +++ b/pisi/db/historydb.py @@ -27,7 +27,7 @@ class HistoryDB(lazydb.LazyDB): self.__logs = self.__generate_history() def __generate_history(self): - logs = os.listdir(ctx.config.history_dir()) + logs = filter(lambda x:x.endswith(".xml"), os.listdir(ctx.config.history_dir())) logs.sort() logs.reverse() return logs @@ -43,6 +43,21 @@ class HistoryDB(lazydb.LazyDB): def add_package(self, pkgBefore=None, pkgAfter=None, operation=None): self.history.add(pkgBefore, pkgAfter, operation) + def load_config(self, operation): + hist_dir = os.path.join(ctx.config.history_dir(), str(operation)) + if os.path.exists(hist_dir): + import distutils.dir_util as dir_util + dir_util.copy_tree(hist_dir, "/") + + def save_config(self, config_file): + hist_dir = os.path.join(ctx.config.history_dir(), self.history.operation.no) + if os.path.isdir(config_file): + os.makedirs(os.path.join(hist_dir, config_file)) + return + + destdir = os.path.join(hist_dir, config_file[1:]) + pisi.util.copy_file(config_file, destdir); + def update_history(self): self.history.update() diff --git a/pisi/history.py b/pisi/history.py index c43fbd14..ffce86fb 100644 --- a/pisi/history.py +++ b/pisi/history.py @@ -79,12 +79,14 @@ class History(xmlfile.XmlFile): if operation not in ["upgrade", "remove", "emerge", "install", "snapshot", "takeback"]: raise Exception("Unknown package operation") - self.histfile = "%s_%s.xml" % (self._get_latest(), operation) + opno = self._get_latest() + self.histfile = "%s_%s.xml" % (opno, operation) year, month, day, hour, minute = time.localtime()[0:5] self.operation.type = operation self.operation.date = "%s-%02d-%02d" % (year, month, day) self.operation.time = "%02d:%02d" % (hour, minute) + self.operation.no = opno def add(self, pkgBefore=None, pkgAfter=None, operation=None): diff --git a/pisi/operations/history.py b/pisi/operations/history.py index 136a94ea..3ce8de5b 100644 --- a/pisi/operations/history.py +++ b/pisi/operations/history.py @@ -144,3 +144,7 @@ def takeback(operation): if beremoved: pisi.operations.remove.remove(beremoved) + + historydb.load_config(operation) + +