Selective Sync fixes
[pithos-ms-client] / trunk / Pithos.Interfaces / ObjectInfo.cs
index 4c43701..484a39a 100644 (file)
@@ -328,6 +328,25 @@ namespace Pithos.Interfaces
                    && (this.Name == null || other.Name.StartsWith(this.Name));
         }
 
+        public bool IsWritable(string account)
+        {
+            //If the Allowed To header has no value, try to determine the Share permissions
+            if (AllowedTo == null)
+            {
+                //If this file has no permissions defined, we can probably write it
+                //This case should occur only when the info comes from a listing of the user's own files
+                if (Permissions == null || Permissions.Count == 0)
+                    return true;
+                string perms;
+
+                //Do we have an explicit write share to this account?
+                return Permissions.TryGetValue(account, out perms) 
+                    && perms.Equals("write",StringComparison.InvariantCultureIgnoreCase);
+                
+            }
+            //Otherwise return the permissions specified by AllowedTo
+            return AllowedTo.Equals("write",StringComparison.InvariantCultureIgnoreCase) ;
+        }
 
         public ObjectInfo Previous { get; private set; }
 
@@ -335,6 +354,8 @@ namespace Pithos.Interfaces
         {
             get
             {
+                if (Content_Type == null)
+                    return false;
                 if (Content_Type.StartsWith(@"application/directory",StringComparison.InvariantCultureIgnoreCase))
                     return true;
                 if (Content_Type.StartsWith(@"application/folder",StringComparison.InvariantCultureIgnoreCase))