Using MD5 to quickly check for local modifications before calculating the expensive...
[pithos-ms-client] / trunk / Pithos.Core / Agents / StatusAgent.cs
index 9ec5d00..b95645d 100644 (file)
@@ -350,7 +350,7 @@ namespace Pithos.Core.Agents
                         {
                             var createdState = FileState.CreateFor(FileInfoExtensions.FromPath(path));
                             createdState.FileStatus = status;
-                            _persistenceAgent.Post(createdState.Create);
+                            createdState.Create();
                         }
                         return affected;
                     }
@@ -363,7 +363,7 @@ namespace Pithos.Core.Agents
             }
         }
 
-        private int UpdateStatusDirect(string absolutePath, FileStatus fileStatus, FileOverlayStatus overlayStatus)
+        private int UpdateStatusDirect(string absolutePath, FileStatus fileStatus, FileOverlayStatus overlayStatus, string conflictReason)
         {
             using (log4net.ThreadContext.Stacks["StatusAgent"].Push("UpdateStatusDirect"))
             {
@@ -376,13 +376,14 @@ namespace Pithos.Core.Agents
                     using (
                         var command =
                             new SQLiteCommand(
-                                "update FileState set OverlayStatus= :overlayStatus, FileStatus= :fileStatus where FilePath = :path COLLATE NOCASE ",
+                                "update FileState set OverlayStatus= :overlayStatus, FileStatus= :fileStatus,ConflictReason= :conflictReason where FilePath = :path COLLATE NOCASE ",
                                 connection))
                     {
 
                         command.Parameters.AddWithValue("path", absolutePath);
                         command.Parameters.AddWithValue("fileStatus", fileStatus);
                         command.Parameters.AddWithValue("overlayStatus", overlayStatus);
+                        command.Parameters.AddWithValue("conflictReason", conflictReason);
                         
                         var affected = command.ExecuteNonQuery();
                         if (affected == 0)
@@ -390,7 +391,8 @@ namespace Pithos.Core.Agents
                             var createdState=FileState.CreateFor(FileInfoExtensions.FromPath(absolutePath));
                             createdState.FileStatus = fileStatus;
                             createdState.OverlayStatus = overlayStatus;
-                            _persistenceAgent.Post(createdState.Create);  
+                            createdState.ConflictReason = conflictReason;
+                            createdState.Create();  
                         }
                         return affected;
                     }
@@ -582,7 +584,7 @@ namespace Pithos.Core.Agents
             _persistenceAgent.Post(() =>FileState.RenameState(oldPath, newPath));
         }*/
 
-        public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string localFileMissingFromServer)
+        public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus, string conflictReason)
         {
             if (String.IsNullOrWhiteSpace(path))
                 throw new ArgumentNullException("path");
@@ -593,7 +595,7 @@ namespace Pithos.Core.Agents
             Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
             Debug.Assert(!path.EndsWith(".ignore"));
 
-            _persistenceAgent.Post(() => UpdateStatusDirect(path, fileStatus, overlayStatus));
+            _persistenceAgent.Post(() => UpdateStatusDirect(path, fileStatus, overlayStatus, conflictReason));
         }
 
 /*
@@ -665,19 +667,18 @@ namespace Pithos.Core.Agents
                     else
                     {
                         command.CommandText =
-                            "INSERT INTO FileState (Id,FilePath,Checksum,Version,VersionTimeStamp,ShortHash,FileStatus,OverlayStatus) VALUES (:id,:path,:checksum,:version,:versionTimeStamp,:shortHash,:fileStatus,:overlayStatus)";
+                            "INSERT INTO FileState (Id,FilePath,Checksum,Version,VersionTimeStamp,ShortHash,FileStatus,OverlayStatus,ObjectID) VALUES (:id,:path,:checksum,:version,:versionTimeStamp,:shortHash,:fileStatus,:overlayStatus,:objectID)";
                         command.Parameters.AddWithValue("id", Guid.NewGuid());
                     }
 
                     command.Parameters.AddWithValue("path", path);
-                    command.Parameters.AddWithValue("checksum", objectInfo.Hash);
-                    command.Parameters.AddWithValue("shortHash", "");
+                    command.Parameters.AddWithValue("checksum", objectInfo.X_Object_Hash);
+                    command.Parameters.AddWithValue("shortHash", objectInfo.ETag);
                     command.Parameters.AddWithValue("version", objectInfo.Version);
-                    command.Parameters.AddWithValue("versionTimeStamp",
-                                                    objectInfo.VersionTimestamp);
+                    command.Parameters.AddWithValue("versionTimeStamp", objectInfo.VersionTimestamp);
                     command.Parameters.AddWithValue("fileStatus", FileStatus.Unchanged);
-                    command.Parameters.AddWithValue("overlayStatus",
-                                                    FileOverlayStatus.Normal);
+                    command.Parameters.AddWithValue("overlayStatus", FileOverlayStatus.Normal);
+                    command.Parameters.AddWithValue("objectID",objectInfo.UUID);
 
                     var affected = command.ExecuteNonQuery();
                     return;
@@ -759,7 +760,7 @@ namespace Pithos.Core.Agents
             if (!Path.IsPathRooted(path))
                 throw new ArgumentException("The path must be rooted", "path");
             Contract.EndContractBlock();
-
+            //TODO: May throw if the agent is cleared for some reason. Should never happen
             _persistenceAgent.Post(() => DeleteFolderDirect(path));   
         }