Keep changed configs in history and load them in takeback operation
This commit is contained in:
@@ -302,6 +302,7 @@ class Install(AtomicOperation):
|
|||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
config_changed.append(fpath)
|
config_changed.append(fpath)
|
||||||
|
self.historydb.save_config(fpath)
|
||||||
if os.path.exists(fpath + '.old'):
|
if os.path.exists(fpath + '.old'):
|
||||||
os.unlink(fpath + '.old')
|
os.unlink(fpath + '.old')
|
||||||
os.rename(fpath, 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)
|
fpath = pisi.util.join_path(ctx.config.dest_dir(), fileinfo.path)
|
||||||
|
|
||||||
|
historydb = pisi.db.historydb.HistoryDB()
|
||||||
filesdb = pisi.db.filesdb.FilesDB()
|
filesdb = pisi.db.filesdb.FilesDB()
|
||||||
# we should check if the file belongs to another
|
# we should check if the file belongs to another
|
||||||
# package (this can legitimately occur while upgrading
|
# package (this can legitimately occur while upgrading
|
||||||
@@ -519,6 +521,9 @@ class Remove(AtomicOperation):
|
|||||||
try:
|
try:
|
||||||
if pisi.util.sha1_file(fpath) == fileinfo.hash:
|
if pisi.util.sha1_file(fpath) == fileinfo.hash:
|
||||||
os.unlink(fpath)
|
os.unlink(fpath)
|
||||||
|
else:
|
||||||
|
# keep changed file in history
|
||||||
|
historydb.save_config(fpath)
|
||||||
except pisi.util.FileError:
|
except pisi.util.FileError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|||||||
+16
-1
@@ -27,7 +27,7 @@ class HistoryDB(lazydb.LazyDB):
|
|||||||
self.__logs = self.__generate_history()
|
self.__logs = self.__generate_history()
|
||||||
|
|
||||||
def __generate_history(self):
|
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.sort()
|
||||||
logs.reverse()
|
logs.reverse()
|
||||||
return logs
|
return logs
|
||||||
@@ -43,6 +43,21 @@ class HistoryDB(lazydb.LazyDB):
|
|||||||
def add_package(self, pkgBefore=None, pkgAfter=None, operation=None):
|
def add_package(self, pkgBefore=None, pkgAfter=None, operation=None):
|
||||||
self.history.add(pkgBefore, pkgAfter, operation)
|
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):
|
def update_history(self):
|
||||||
self.history.update()
|
self.history.update()
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -79,12 +79,14 @@ class History(xmlfile.XmlFile):
|
|||||||
if operation not in ["upgrade", "remove", "emerge", "install", "snapshot", "takeback"]:
|
if operation not in ["upgrade", "remove", "emerge", "install", "snapshot", "takeback"]:
|
||||||
raise Exception("Unknown package operation")
|
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]
|
year, month, day, hour, minute = time.localtime()[0:5]
|
||||||
self.operation.type = operation
|
self.operation.type = operation
|
||||||
self.operation.date = "%s-%02d-%02d" % (year, month, day)
|
self.operation.date = "%s-%02d-%02d" % (year, month, day)
|
||||||
self.operation.time = "%02d:%02d" % (hour, minute)
|
self.operation.time = "%02d:%02d" % (hour, minute)
|
||||||
|
self.operation.no = opno
|
||||||
|
|
||||||
def add(self, pkgBefore=None, pkgAfter=None, operation=None):
|
def add(self, pkgBefore=None, pkgAfter=None, operation=None):
|
||||||
|
|
||||||
|
|||||||
@@ -144,3 +144,7 @@ def takeback(operation):
|
|||||||
|
|
||||||
if beremoved:
|
if beremoved:
|
||||||
pisi.operations.remove.remove(beremoved)
|
pisi.operations.remove.remove(beremoved)
|
||||||
|
|
||||||
|
historydb.load_config(operation)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user