Selective Sync fixes
[pithos-ms-client] / trunk / Pithos.Core / Agents / Uploader.cs
index 87c4dc3..67e6db1 100644 (file)
@@ -47,14 +47,16 @@ namespace Pithos.Core.Agents
                         return;
                     }
 
+                    var latestState = action.FileState;
+
                     //Do not upload files in conflict
-                    if (action.FileState.FileStatus == FileStatus.Conflict)
+                    if (latestState.FileStatus == FileStatus.Conflict)
                     {
                         Log.InfoFormat("Skipping file in conflict [{0}]", fileInfo.FullName);
                         return;
                     }
                     //Do not upload files when we have no permission
-                    if (action.FileState.FileStatus == FileStatus.Forbidden)
+                    if (latestState.FileStatus == FileStatus.Forbidden)
                     {
                         Log.InfoFormat("Skipping forbidden file [{0}]", fileInfo.FullName);
                         return;
@@ -85,7 +87,7 @@ namespace Pithos.Core.Agents
                             var cloudInfo = client.GetObjectInfo(account, cloudFile.Container, cloudFile.Name);
 
                             //If this is a read-only file, do not upload changes
-                            if (cloudInfo.AllowedTo == "read")
+                            if (!cloudInfo.IsWritable(action.AccountInfo.UserName))
                                 return;
 
                             if (fileInfo is DirectoryInfo)
@@ -129,7 +131,7 @@ namespace Pithos.Core.Agents
                                 await UploadWithHashMap(accountInfo, cloudFile, fileInfo as FileInfo, cloudFile.Name, treeHash);
                             }
                             //If everything succeeds, change the file and overlay status to normal
-                            StatusKeeper.SetFileState(fullFileName, FileStatus.Unchanged, FileOverlayStatus.Normal);
+                            StatusKeeper.SetFileState(fullFileName, FileStatus.Unchanged, FileOverlayStatus.Normal, "");
                         }
                         catch (WebException exc)
                         {
@@ -138,11 +140,12 @@ namespace Pithos.Core.Agents
                                 throw;
                             if (response.StatusCode == HttpStatusCode.Forbidden)
                             {
-                                StatusKeeper.SetFileState(fileInfo.FullName, FileStatus.Forbidden, FileOverlayStatus.Conflict);
+                                StatusKeeper.SetFileState(fileInfo.FullName, FileStatus.Forbidden, FileOverlayStatus.Conflict, "Forbidden");
+                                
                             }
-
-                            //In any other case, propagate the error
-                            throw;
+                            else
+                                //In any other case, propagate the error
+                                throw;
                         }
                     }
                     //Notify the Shell to update the overlays
@@ -274,7 +277,7 @@ namespace Pithos.Core.Agents
             {
                 Log.Error("Not allowed to upload file", exc);
                 var message = String.Format("Not allowed to uplad file {0}", action.LocalFile.FullName);
-                StatusKeeper.SetFileState(action.LocalFile.FullName, FileStatus.Unchanged, FileOverlayStatus.Normal);
+                StatusKeeper.SetFileState(action.LocalFile.FullName, FileStatus.Unchanged, FileOverlayStatus.Normal, "");
                 StatusNotification.NotifyChange(message, TraceLevel.Warning);
                 return true;
             }