]> code.delx.au - offlineimap/blobdiff - src/Data/Syncable.hs
TESTS PASS
[offlineimap] / src / Data / Syncable.hs
index ffa75eefa87ca4f55bbe6b973a6a4189e52b7faf..69841c44d58da1a6fb4340b0958140ee85d455bc 100644 (file)
@@ -118,16 +118,19 @@ syncBiDir masterstate childstate lastchildstate =
                           findAdded masterstate childstate $ lastchildstate)
                          ++ (map (pairToFunc ModifyContent) . Map.toList $ childPayloadChanges)
           masterPayloadChanges = 
-              Map.union (findModified masterstate childstate childstate lastchildstate)
-                 (findModified masterstate childstate childstate masterstate)
+              Map.union 
+                 (findModified masterstate childstate childstate lastchildstate)
+                 (findModified masterstate childstate reducedChildState masterstate)
+              where reducedChildState = 
+                        Map.difference childstate lastchildstate
                  
           -- The child's payload takes precedence, so we are going to
           -- calculate the changes made on the master to apply to the client,
           -- then subtract out any items in the master changes that have the
           -- same key.
           childPayloadChanges = 
-              Map.union (findModified childstate childstate masterstate lastchildstate)
-                 (findModified childstate childstate childstate lastchildstate)
+              Map.difference (findModified childstate masterstate masterstate lastchildstate)
+                 (findModified masterstate childstate childstate lastchildstate)
 
 {- | Compares two SyncCollections, and returns the commands that, when
 applied to the first collection, would yield the second. -}
@@ -137,7 +140,18 @@ diffCollection :: (Ord k, Show k, Eq v, Show v) =>
                -> [SyncCommand k v]
 diffCollection coll1 coll2 = 
     (map DeleteItem . findDeleted coll2 coll1 $ coll1) ++
-    (map (pairToFunc CopyItem) . findAdded coll2 coll1 $ coll1)
+    (map (pairToFunc CopyItem) . findAdded coll2 coll1 $ coll1) ++
+    modifiedData
+    where modifiedData = 
+              map (pairToFunc ModifyContent) .
+              Map.toList . 
+              Map.mapMaybe id .
+              Map.intersectionWith compareFunc coll1 $ coll2
+          compareFunc v1 v2
+              | v1 /= v2 = Just v2
+              | otherwise = Nothing
+              
+                         
     {-
     (map (pairToFunc ModifyContent) . Map.toList .
          findModified coll1 coll2 $ coll1)
@@ -184,7 +198,9 @@ findModified basestate authoritativestate comparisonstate laststate =
                         (Just basev, Just authv) ->
                             if (authv /= lastv) && (authv /= basev)
                                then Just authv
-                               else Nothing
+                               else if compv /= basev && (authv /= basev)
+                                    then Just compv
+                                    else Nothing
 
 {- | Apply the specified changes to the given SyncCollection.  Returns
 a new SyncCollection with the changes applied.  If changes are specified