conduit r1397 - in trunk: . conduit conduit/dataproviders conduit/datatypes test/python-tests
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1397 - in trunk: . conduit conduit/dataproviders conduit/datatypes test/python-tests
- Date: Thu, 27 Mar 2008 11:39:12 +0000 (GMT)
Author: jstowers
Date: Thu Mar 27 11:39:11 2008
New Revision: 1397
URL: http://svn.gnome.org/viewvc/conduit?rev=1397&view=rev
Log:
2008-03-28 John Stowers <john stowers gmail com>
* conduit/DeltaProvider.py: Only convert LUIDs to unicode if they
are not allready.
* conduit/Synchronization.py:
* conduit/datatypes/DataType.py:
* conduit/datatypes/File.py:
* conduit/datatypes/__init__.py:
* test/python-tests/TestCoreSyncLogic.py: Remove COMPARISON_UNEQUAL, it was
not used. Use COMPARISON_UNKNOWN instead
* conduit/dataproviders/File.py: Refactor put() to raise a conflict any time
we try to modify a file that not both known, and older than the file being
put. Fixes #520785
Modified:
trunk/ChangeLog
trunk/conduit/DeltaProvider.py
trunk/conduit/Synchronization.py
trunk/conduit/dataproviders/File.py
trunk/conduit/datatypes/DataType.py
trunk/conduit/datatypes/File.py
trunk/conduit/datatypes/__init__.py
trunk/test/python-tests/TestCoreSyncLogic.py
Modified: trunk/conduit/DeltaProvider.py
==============================================================================
--- trunk/conduit/DeltaProvider.py (original)
+++ trunk/conduit/DeltaProvider.py Thu Mar 27 11:39:11 2008
@@ -30,11 +30,11 @@
"""
allItems = []
for i in self.me.module.get_all():
- #Maybe we should be unicode....
- assert type(i) in [str,unicode], "LUID Must be str not %s" % type(i)
- #Make sure the are in unicode to assure good comparison with mapping UID's
- #FIXME: Replace or ignore non unicode chars?
- allItems.append(unicode(i,errors='replace'))
+ #Make sure the are in unicode to assure a
+ #good comparison with mapping UID's
+ if type(i) != unicode:
+ i = unicode(i,errors='replace')
+ allItems.append(i)
log.debug("Delta: Got %s items\n%s" % (len(allItems), allItems))
Modified: trunk/conduit/Synchronization.py
==============================================================================
--- trunk/conduit/Synchronization.py (original)
+++ trunk/conduit/Synchronization.py Thu Mar 27 11:39:11 2008
@@ -370,43 +370,38 @@
Applies user policy when a put() has failed. This may mean emitting
the conflict up to the GUI or skipping altogether
"""
- if comparison == COMPARISON_EQUAL or comparison == COMPARISON_UNKNOWN or comparison == COMPARISON_OLDER:
- if self.cond.get_policy("conflict") == "skip":
- log.debug("Conflict Policy: Skipping")
- elif self.cond.get_policy("conflict") == "ask":
- log.debug("Conflict Policy: Ask")
- self.sinkErrors[sinkWrapper] = DataProvider.STATUS_DONE_SYNC_CONFLICT
-
- if sourceWrapper.module_type in ["twoway", "sink"]:
- #in twoway case the user can copy back
- avail = (CONFLICT_SKIP,CONFLICT_COPY_SOURCE_TO_SINK,CONFLICT_COPY_SINK_TO_SOURCE)
- else:
- avail = (CONFLICT_SKIP,CONFLICT_COPY_SOURCE_TO_SINK)
+ if self.cond.get_policy("conflict") == "skip":
+ log.debug("Conflict Policy: Skipping")
+ elif self.cond.get_policy("conflict") == "ask":
+ log.debug("Conflict Policy: Ask")
+ self.sinkErrors[sinkWrapper] = DataProvider.STATUS_DONE_SYNC_CONFLICT
+
+ if sourceWrapper.module_type in ["twoway", "sink"]:
+ #in twoway case the user can copy back
+ avail = (CONFLICT_SKIP,CONFLICT_COPY_SOURCE_TO_SINK,CONFLICT_COPY_SINK_TO_SOURCE)
+ else:
+ avail = (CONFLICT_SKIP,CONFLICT_COPY_SOURCE_TO_SINK)
+
+ c = Conflict(
+ sourceWrapper,
+ fromData,
+ fromDataRid,
+ sinkWrapper,
+ toData,
+ toDataRid,
+ avail,
+ False
+ )
+ self.cond.emit("sync-conflict", c)
+
+ elif self.cond.get_policy("conflict") == "replace":
+ log.debug("Conflict Policy: Replace")
+ self.sinkErrors[sinkWrapper] = DataProvider.STATUS_DONE_SYNC_CONFLICT
- c = Conflict(
- sourceWrapper,
- fromData,
- fromDataRid,
- sinkWrapper,
- toData,
- toDataRid,
- avail,
- False
- )
- self.cond.emit("sync-conflict", c)
-
- elif self.cond.get_policy("conflict") == "replace":
- log.debug("Conflict Policy: Replace")
- self.sinkErrors[sinkWrapper] = DataProvider.STATUS_DONE_SYNC_CONFLICT
-
- try:
- put_data(sourceWrapper, sinkWrapper, fromData, fromDataRid, True)
- except:
- log.warn("Forced Put Failed\n%s" % traceback.format_exc())
- #This should not happen...
- else:
- log.warn("UNKNOWN COMPARISON\n%s" % traceback.format_exc())
- self.sinkErrors[sinkWrapper] = DataProvider.STATUS_DONE_SYNC_ERROR
+ try:
+ put_data(sourceWrapper, sinkWrapper, fromData, fromDataRid, True)
+ except:
+ log.warn("Forced Put Failed\n%s" % traceback.format_exc())
def check_thread_not_cancelled(self, dataprovidersToCancel):
"""
Modified: trunk/conduit/dataproviders/File.py
==============================================================================
--- trunk/conduit/dataproviders/File.py (original)
+++ trunk/conduit/dataproviders/File.py Thu Mar 27 11:39:11 2008
@@ -230,6 +230,12 @@
self.fstype = None
self.files = []
+ def _transfer_file(self, vfsFile, newURI, overwrite):
+ try:
+ vfsFile.transfer(newURI, overwrite)
+ except File.FileTransferError:
+ raise Exceptions.SyncronizeFatalError("Transfer Cancelled")
+
def initialize(self):
return True
@@ -287,17 +293,27 @@
#escape illegal filesystem characters
if self.fstype:
newURI = Vfs.uri_sanitize_for_filesystem(newURI, self.fstype)
-
- destFile = File.File(URI=newURI)
- comp = vfsFile.compare(
- destFile,
- sizeOnly=self.compareIgnoreMtime
- )
- if overwrite or comp == DataType.COMPARISON_NEWER:
- try:
- vfsFile.transfer(newURI, True)
- except File.FileTransferError:
- raise Exceptions.SyncronizeFatalError("Transfer Cancelled")
+
+ #overwrite is the easy case, as for it to be true, requires specific user
+ #interaction
+ if overwrite == True:
+ self._transfer_file(vfsFile, newURI, overwrite)
+ else:
+ #check for conflicts
+ destFile = File.File(URI=newURI)
+ if destFile.exists():
+ comp = vfsFile.compare(
+ destFile,
+ sizeOnly=self.compareIgnoreMtime
+ )
+ if LUID != None and comp == DataType.COMPARISON_NEWER:
+ self._transfer_file(vfsFile, newURI, overwrite)
+ elif comp == DataType.COMPARISON_EQUAL:
+ pass
+ else:
+ raise Exceptions.SynchronizeConflictError(comp, vfsFile, destFile)
+ else:
+ self._transfer_file(vfsFile, newURI, overwrite)
return self.get(newURI).get_rid()
Modified: trunk/conduit/datatypes/DataType.py
==============================================================================
--- trunk/conduit/datatypes/DataType.py (original)
+++ trunk/conduit/datatypes/DataType.py Thu Mar 27 11:39:11 2008
@@ -50,7 +50,6 @@
- C{conduit.datatypes.COMPARISON_NEWER} This means the I am newer than B
- C{conduit.datatypes.COMPARISON_EQUAL} This means the we are equal
- L{conduit.datatypes.COMPARISON_OLDER} This means the I am older than B
- - L{conduit.datatypes.COMPARISON_UNEQUAL} This means that I know I am different, but I don't know wny
- L{conduit.datatypes.COMPARISON_UNKNOWN} This means we were unable to determine
which was newer than the other so its up to the user to decide
"""
@@ -63,7 +62,7 @@
mtime2 = B.get_mtime()
if mtime1 == None or mtime2 == None:
- return conduit.datatypes.COMPARISON_UNEQUAL
+ return conduit.datatypes.COMPARISON_UNKNOWN
if mtime1 > mtime2:
return conduit.datatypes.COMPARISON_NEWER
Modified: trunk/conduit/datatypes/File.py
==============================================================================
--- trunk/conduit/datatypes/File.py (original)
+++ trunk/conduit/datatypes/File.py Thu Mar 27 11:39:11 2008
@@ -425,16 +425,13 @@
"""
return self._get_text_uri().replace(self.basePath,"")
- def compare(self, B, sizeOnly=False, existOnly=False):
+ def compare(self, B, sizeOnly=False):
"""
Compare me with B based upon their modification times, or optionally
based on size only
"""
- if not gnomevfs.exists(B.URI):
+ if gnomevfs.exists(B.URI) == False:
return conduit.datatypes.COMPARISON_NEWER
- else:
- if existOnly:
- return conduit.datatypes.COMPARISON_OLDER
#Compare based on size only?
if sizeOnly:
Modified: trunk/conduit/datatypes/__init__.py
==============================================================================
--- trunk/conduit/datatypes/__init__.py (original)
+++ trunk/conduit/datatypes/__init__.py Thu Mar 27 11:39:11 2008
@@ -10,8 +10,7 @@
COMPARISON_EQUAL = 0
COMPARISON_NEWER = 1
COMPARISON_OLDER = 2
-COMPARISON_UNEQUAL = 3
-COMPARISON_UNKNOWN = 4
+COMPARISON_UNKNOWN = 3
import datetime
import logging
Modified: trunk/test/python-tests/TestCoreSyncLogic.py
==============================================================================
--- trunk/test/python-tests/TestCoreSyncLogic.py (original)
+++ trunk/test/python-tests/TestCoreSyncLogic.py Thu Mar 27 11:39:11 2008
@@ -2,7 +2,7 @@
from common import *
import conduit
-from conduit.datatypes import DataType,COMPARISON_OLDER,COMPARISON_NEWER,COMPARISON_EQUAL,COMPARISON_UNEQUAL
+from conduit.datatypes import DataType,COMPARISON_OLDER,COMPARISON_NEWER,COMPARISON_EQUAL, COMPARISON_UNKNOWN
from conduit.dataproviders.DataProvider import TwoWay
import datetime
@@ -147,7 +147,7 @@
d = TestDataType('99')
d.set_mtime(None)
-ok("Prep: Test d unequal to a", a.compare(d) == COMPARISON_UNEQUAL)
+ok("Prep: Test d unknown comparison with a", a.compare(d) == COMPARISON_UNKNOWN)
################################################################################
# TWO WAY SYNC WITH ONE SOURCE AND ONE SINK
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]