[PATCH] Enable --force and --backup arguments in copyfile module

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

 



        This patch enables two options to copyfile: --force and --backup.  My 
earlier patch from the e-mail entitled "[PATCH] Add checksumming feature to 
copyfile module" must be applied to the func source before this patch is 
applied.

        My earlier patch caused func to calculate a checksum for the source 
and target files (the latter only if it exists).  If the checksums are 
identical then the target file is not overwritten.  The --force options skips 
this check.  The checksum is not calculated on either the overlord or minion 
and the target file will be overwritten even if it is identical to the source 
file.

        The --backup option creates a dated backup of the target file before 
it is overwritten.  This takes advantage of the already-present _backuplocal 
function in the CopyFile class.  The backup is only created prior to 
overwriting the target file, e.g if the source and target checksums differ or 
if --force is enabled.

        It looks as though the original copyfile function of the CopyFile 
class automatically did a backup every time.  Making a backup is not the 
default in my code.

--
Marcus
diff -rupN func/func//minion/modules/copyfile.py func.new/func//minion/modules/copyfile.py
--- func/func//minion/modules/copyfile.py	2010-12-14 19:16:55.000000000 -0500
+++ func.new/func//minion/modules/copyfile.py	2010-12-14 20:16:18.000000000 -0500
@@ -59,16 +59,20 @@ class CopyFile(func_module.FuncModule):
         hexdig = thissum.hexdigest()
         return hexdig
 
-    def open(self, filepath, remote_sum, mode=None, uid=-1, gid=-1):
+    def open(self, filepath, remote_sum, mode=None, uid=-1, gid=-1, backup=False, force=False):
         dirpath = os.path.dirname(filepath)
         if not os.path.exists(dirpath):
             os.makedirs(dirpath)
 
         if os.path.exists(filepath):
-            local_sum = self.checksum(filepath)
+	    if not force:
+                local_sum = self.checksum(filepath)
+                if remote_sum == local_sum:
+                    return 0
 
-	    if remote_sum == local_sum:
-                return 0
+	    if backup:
+                if not self._backuplocal(filepath):
+                    return -1
 
         # Create empty file
         try:
diff -rupN func/func//overlord/cmd_modules/copyfile.py func.new/func//overlord/cmd_modules/copyfile.py
--- func/func//overlord/cmd_modules/copyfile.py	2010-12-14 19:16:37.000000000 -0500
+++ func.new/func//overlord/cmd_modules/copyfile.py	2010-12-14 19:09:38.000000000 -0500
@@ -34,6 +34,8 @@ class CopyFile(base_command.BaseCommand)
                                action="store")
         self.parser.add_option("", "--remotepath", dest="remotepath",
                                 action="store")
+        self.parser.add_option("", "--backup", dest="backup",
+                               action="store_true")
         self.parser.add_option("", "--force", dest="force",
                                action="store_true")
         self.parser.add_option("-v", "--verbose", dest="verbose",
@@ -50,4 +52,4 @@ class CopyFile(base_command.BaseCommand)
         self.server_spec = self.parentCommand.server_spec
         self.getOverlord()
 
-        return self.overlord_obj.local.copyfile.send(self.options.filename, self.options.remotepath)
+        return self.overlord_obj.local.copyfile.send(self.options.filename, self.options.remotepath, self.options.backup, self.options.force)
diff -rupN func/func//overlord/modules/copyfile.py func.new/func//overlord/modules/copyfile.py
--- func/func//overlord/modules/copyfile.py	2010-12-14 19:16:55.000000000 -0500
+++ func.new/func//overlord/modules/copyfile.py	2010-12-14 20:17:23.000000000 -0500
@@ -38,7 +38,7 @@ class copyfile(overlord_module.BaseModul
         hexdig = thissum.hexdigest()
         return hexdig
 
-    def send(self, localpath, remotepath, bufsize=60000):
+    def send(self, localpath, remotepath, backup=None, force=None, bufsize=60000):
         try:
             f = open(localpath, "r")
         except IOError, e:
@@ -49,9 +49,13 @@ class copyfile(overlord_module.BaseModul
         mode = stat.S_IMODE(st.st_mode)
         uid = st.st_uid
         gid = st.st_gid
-	local_sum = self.checksum(localpath)
 
-        open_result = self.parent.run("copyfile", "open", [remotepath, local_sum, mode, uid, gid])
+	if force:
+            local_sum = -1
+        else:
+            local_sum = self.checksum(localpath)
+
+        open_result = self.parent.run("copyfile", "open", [remotepath, local_sum, mode, uid, gid, backup, force])
 
         while True:
             data=f.read(bufsize)
_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list

[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux