summaryrefslogtreecommitdiffstats
path: root/ipapython/sysrestore.py
diff options
context:
space:
mode:
Diffstat (limited to 'ipapython/sysrestore.py')
-rw-r--r--ipapython/sysrestore.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py
index 7720fd6e3..2c4741f3d 100644
--- a/ipapython/sysrestore.py
+++ b/ipapython/sysrestore.py
@@ -143,18 +143,26 @@ class FileStore:
break
return result
- def restore_file(self, path):
+ def restore_file(self, path, new_path = None):
"""Restore the copy of a file at @path to its original
location and delete the copy.
+ Takes optional parameter @new_path which specifies the
+ location where the file is to be restored.
+
Returns #True if the file was restored, #False if there
was no backup file to restore
"""
- root_logger.debug("Restoring system configuration file '%s'", path)
+ if new_path is None:
+ root_logger.debug("Restoring system configuration file '%s'", path)
+ else:
+ root_logger.debug("Restoring system configuration file '%s' to '%s'", path, new_path)
if not os.path.isabs(path):
raise ValueError("Absolute path required")
+ if new_path is not None and not os.path.isabs(new_path):
+ raise ValueError("Absolute new path required")
mode = None
uid = None
@@ -175,6 +183,9 @@ class FileStore:
root_logger.debug(" -> Not restoring - '%s' doesn't exist", backup_path)
return False
+ if new_path is not None:
+ path = new_path
+
shutil.move(backup_path, path)
os.chown(path, int(uid), int(gid))
os.chmod(path, int(mode))