conduit r1501 - in trunk: . conduit conduit/dataproviders test/python-tests



Author: jstowers
Date: Wed Jun  4 12:33:11 2008
New Revision: 1501
URL: http://svn.gnome.org/viewvc/conduit?rev=1501&view=rev

Log:
2008-06-05  John Stowers  <john stowers gmail com>

	* conduit/Synchronization.py: If we are older, then the dp should not
	have raised the conflict, so this test can be removed.
	
	* conduit/dataproviders/File.py: If we are newer then we can
	overwrite the file. Fixes #532545
	
	* test/python-tests/TestSyncFolderFolder2.py: More exhaustive tests for
	folder sync.



Added:
   trunk/test/python-tests/TestSyncFolderFolder2.py
Modified:
   trunk/ChangeLog
   trunk/conduit/Synchronization.py
   trunk/conduit/dataproviders/File.py

Modified: trunk/conduit/Synchronization.py
==============================================================================
--- trunk/conduit/Synchronization.py	(original)
+++ trunk/conduit/Synchronization.py	Wed Jun  4 12:33:11 2008
@@ -335,9 +335,7 @@
                 self.sinkErrors[sink] = DataProvider.STATUS_DONE_SYNC_ERROR
             except Exceptions.SynchronizeConflictError, err:
                 comp = err.comparison
-                if comp == COMPARISON_OLDER:
-                    log.info("Skipping %s (Older)" % sourceData)
-                elif comp == COMPARISON_EQUAL:
+                if comp == COMPARISON_EQUAL:
                     log.info("Skipping %s (Equal)" % sourceData)
                 else:
                     assert(err.fromData == sourceData)

Modified: trunk/conduit/dataproviders/File.py
==============================================================================
--- trunk/conduit/dataproviders/File.py	(original)
+++ trunk/conduit/dataproviders/File.py	Wed Jun  4 12:33:11 2008
@@ -309,9 +309,17 @@
                             destFile, 
                             sizeOnly=self.compareIgnoreMtime
                             )
+
                 if LUID != None and comp == DataType.COMPARISON_NEWER:
-                    self._transfer_file(vfsFile, newURI, overwrite)
+                    #we were expecting an existing file, we found it, but
+                    #we are newer, so overwrite it
+                    self._transfer_file(vfsFile, newURI, True)
                 elif comp == DataType.COMPARISON_EQUAL:
+                    #in File.compare, the files are compared based on size, if
+                    #their mtimes are the same, so this case is true when
+                    # 1) The sizes are the same, and the user told us
+                    #    to ignore the mtimes
+                    # 2) The mtimes and size is the same, and we checked both
                     pass
                 else:
                     raise Exceptions.SynchronizeConflictError(comp, vfsFile, destFile)

Added: trunk/test/python-tests/TestSyncFolderFolder2.py
==============================================================================
--- (empty file)
+++ trunk/test/python-tests/TestSyncFolderFolder2.py	Wed Jun  4 12:33:11 2008
@@ -0,0 +1,156 @@
+#common sets up the conduit environment
+from common import *
+
+import conduit.datatypes.File as File
+
+import os
+import tempfile
+
+#test overwriting older files with newer ones
+FILENAME = "%s/testfile"
+CONTENTS = "foo"
+CONTENTS_NEW = "foo bar"
+SLEEP_TIME = 1
+
+def setup_folder_dps():
+    frmdir = tempfile.mkdtemp()
+    todir = tempfile.mkdtemp()
+
+    test = SimpleSyncTest()
+    test.prepare(
+            test.get_dataprovider("FolderTwoWay"),
+            test.get_dataprovider("FolderTwoWay"))
+    test.set_two_way_policy({"conflict":"ask","deleted":"ask"})
+
+    config = {}
+    config["folderGroupName"] = "TestGroup"
+    config["folder"] = "file://"+frmdir
+    config["includeHidden"] = False
+    config["followSymlinks"] = False
+    test.configure(source=config)
+
+    config["folder"] = "file://"+todir
+    test.configure(sink=config)
+    return test, frmdir, todir
+
+########################################
+# Test overwrite an older file with an updated one
+########################################
+test, frmdir, todir = setup_folder_dps()
+
+#write test file
+fa = open(FILENAME % frmdir, 'w')
+fa.write(CONTENTS)
+fa.close()
+
+test.sync()
+time.sleep(SLEEP_TIME)
+abort,error,conflict = test.get_sync_result()
+ok("Sync OK", abort == False and error == False and conflict == False)
+
+fb = open(FILENAME % todir, 'r')
+ok("File transferred", fb.read() == CONTENTS)
+fb.close()
+
+#mod test file
+time.sleep(SLEEP_TIME)
+fa = open(FILENAME % frmdir, 'w')
+fa.write(CONTENTS_NEW)
+fa.close()
+
+test.sync()
+time.sleep(SLEEP_TIME)
+abort,error,conflict = test.get_sync_result()
+ok("Sync OK", abort == False and error == False and conflict == False)
+
+fb = open(FILENAME % todir, 'r')
+ok("Updated File transferred", fb.read() == CONTENTS_NEW)
+fb.close()
+
+########################################
+# Putting an older file over an unknown new one shoud conflict
+########################################
+test, frmdir, todir = setup_folder_dps()
+
+#write test files
+fa = open(FILENAME % frmdir, 'w')
+fa.write(CONTENTS)
+fa.close()
+
+#diff mtime
+time.sleep(SLEEP_TIME*2)
+
+fa = open(FILENAME % todir, 'w')
+fa.write(CONTENTS)
+fa.close()
+
+test.sync()
+abort,error,conflict = test.get_sync_result()
+ok("Detected conflict on existing file", abort == False and error == False and conflict == True)
+
+########################################
+# Putting a file over an unknown new one with the same mtime, but diff size
+# should conflict
+########################################
+test, frmdir, todir = setup_folder_dps()
+
+#write test files
+faName = FILENAME % frmdir
+fa = open(faName, 'w')
+fa.write(CONTENTS)
+fa.close()
+
+fbName = FILENAME % todir
+fb = open(fbName, 'w')
+fb.write(CONTENTS_NEW)
+fb.close()
+
+#make fb same mtime as fa, yuck!
+os.system("touch %s -r %s" % (fbName, faName))
+
+a = File.File(URI=faName)
+b = File.File(URI=fbName)
+compSize = a.compare(b, sizeOnly=True)
+ok("Files different size", compSize == conduit.datatypes.COMPARISON_UNKNOWN)
+
+compSize = a.compare(b, sizeOnly=False)
+ok("Files same mtime, and different size", compSize == conduit.datatypes.COMPARISON_UNKNOWN)
+
+test.sync(debug=False)
+abort,error,conflict = test.get_sync_result()
+ok("Detected conflict on existing file, same mtime, diff size", abort == False and error == False and conflict == True)
+
+########################################
+# Putting a file over an unknown new one with the same mtime, and same size
+# wont conflict, we cant do any stronger tests without hashing
+########################################
+test, frmdir, todir = setup_folder_dps()
+
+#write test files
+faName = FILENAME % frmdir
+fa = open(faName, 'w')
+fa.write(CONTENTS)
+fa.close()
+
+fbName = FILENAME % todir
+fb = open(fbName, 'w')
+fb.write(CONTENTS)
+fb.close()
+
+#make fb same mtime as fa, yuck!
+os.system("touch %s -r %s" % (fbName, faName))
+
+a = File.File(URI=faName)
+b = File.File(URI=fbName)
+compSize = a.compare(b, sizeOnly=True)
+ok("Files same size", compSize == conduit.datatypes.COMPARISON_EQUAL)
+
+compSize = a.compare(b, sizeOnly=False)
+ok("Files same mtime, and same size", compSize == conduit.datatypes.COMPARISON_EQUAL)
+
+test.sync(debug=False)
+abort,error,conflict = test.get_sync_result()
+ok("No conflict for existing same files", abort == False and error == False and conflict == False)
+
+finished()
+



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