Modifications to allow synchronization of shared files:
authorPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 30 Jan 2012 19:19:48 +0000 (21:19 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 30 Jan 2012 19:19:48 +0000 (21:19 +0200)
- Ensure shared files are stored in the proper local directory
- Ensure only writable files are uploaded
- Filter file events for the shared folder and the accounts and containers in it
- Change PutWithHashMap to account for a modified server content (proper json instead of hashes per line)

trunk/Pithos.Client.WPF/Preferences/GroupsView.xaml
trunk/Pithos.Client.WPF/Preferences/GroupsViewModel.cs
trunk/Pithos.Core/Agents/FileAgent.cs
trunk/Pithos.Core/Agents/NetworkAgent.cs
trunk/Pithos.Interfaces/ObjectInfo.cs
trunk/Pithos.Interfaces/Pithos.Interfaces.csproj
trunk/Pithos.Network/CloudFilesClient.cs
trunk/Pithos.Network/FolderConstants.cs [deleted file]
trunk/Pithos.Network/Pithos.Network.csproj

index 47ba7b8..7689c48 100644 (file)
@@ -6,6 +6,20 @@
              mc:Ignorable="d" \r
              d:DesignHeight="300" d:DesignWidth="300">\r
     <Grid>\r
-            \r
+        <DataGrid ItemsSource="{Binding Groups}" \r
+                AutoGenerateColumns="False" CanUserAddRows="True">\r
+            <DataGrid.Columns>\r
+                <DataGridTemplateColumn >\r
+                    <DataGridTemplateColumn.CellTemplate>\r
+                        <DataTemplate>\r
+                            <Button Content=" - " Command="DataGrid.DeleteCommand"/>\r
+                        </DataTemplate>\r
+                    </DataGridTemplateColumn.CellTemplate>\r
+                </DataGridTemplateColumn>\r
+                <DataGridTextColumn Binding="{Binding UserName}" Header="Name"  />\r
+                <DataGridCheckBoxColumn Binding="{Binding Read}" Header="Read"/>\r
+                <DataGridCheckBoxColumn Binding="{Binding Write}" Header="Write"/>\r
+            </DataGrid.Columns>\r
+        </DataGrid>\r
     </Grid>\r
 </UserControl>\r
index 77223e2..1ac8146 100644 (file)
@@ -10,11 +10,24 @@ namespace Pithos.Client.WPF.Preferences
     using System.Collections.Generic;\r
     using System.Linq;\r
     using System.Text;\r
+    using Caliburn.Micro;\r
 \r
     /// <summary>\r
     /// TODO: Update summary.\r
     /// </summary>\r
-    public class GroupsViewModel\r
+    public class GroupsViewModel:PropertyChangedBase\r
     {\r
+\r
+        private List<string> _groups;\r
+\r
+        public List<string> Groups\r
+        {\r
+            get { return _groups; }\r
+            set\r
+            {\r
+                _groups = value;\r
+                NotifyOfPropertyChange(() => Groups);\r
+            }\r
+        }\r
     }\r
 }\r
index 09d22b0..6f540bd 100644 (file)
@@ -205,9 +205,21 @@ namespace Pithos.Core.Agents
 
         private bool Ignore(string filePath)
         {
-            var pithosPath = Path.Combine(RootPath, "pithos");
-            if (pithosPath.Equals(filePath, StringComparison.InvariantCultureIgnoreCase))
-                return true;
+            //Ignore all first-level directories and files            
+            if (FoundBelowRoot(filePath, RootPath,1))
+                return true;            
+
+            //Ignore first-level items under the "others" folder.
+            var othersPath = Path.Combine(RootPath, FolderConstants.OthersFolder);
+            if (FoundBelowRoot(filePath, othersPath,1))
+                return true;            
+
+            //Ignore second-level (container) folders under the "others" folder. 
+            if (FoundBelowRoot(filePath, othersPath,2))
+                return true;            
+
+
+            //Ignore anything happening in the cache path
             if (filePath.StartsWith(CachePath))
                 return true;
             if (_ignoreFiles.ContainsKey(filePath.ToLower()))
@@ -215,6 +227,50 @@ namespace Pithos.Core.Agents
             return false;
         }
 
+/*        private static bool FoundInRoot(string filePath, string rootPath)
+        {
+            //var rootDirectory = new DirectoryInfo(rootPath);
+
+            //If the paths are equal, return true
+            if (filePath.Equals(rootPath, StringComparison.InvariantCultureIgnoreCase))
+                return true;
+
+            //If the filepath is below the root path
+            if (filePath.StartsWith(rootPath,StringComparison.InvariantCulture))
+            {
+                //Get the relative path
+                var relativePath = filePath.Substring(rootPath.Length + 1);
+                //If the relativePath does NOT contains a path separator, we found a match
+                return (!relativePath.Contains(@"\"));
+            }
+
+            //If the filepath is not under the root path, return false
+            return false;            
+        }*/
+
+
+        private static bool FoundBelowRoot(string filePath, string rootPath,int level)
+        {
+            //var rootDirectory = new DirectoryInfo(rootPath);
+
+            //If the paths are equal, return true
+            if (filePath.Equals(rootPath, StringComparison.InvariantCultureIgnoreCase))
+                return true;
+
+            //If the filepath is below the root path
+            if (filePath.StartsWith(rootPath,StringComparison.InvariantCulture))
+            {
+                //Get the relative path
+                var relativePath = filePath.Substring(rootPath.Length + 1);
+                //If the relativePath does NOT contains a path separator, we found a match
+                var levels=relativePath.ToCharArray().Count(c=>c=='\\')+1;                
+                return levels==level;
+            }
+
+            //If the filepath is not under the root path, return false
+            return false;            
+        }
+
         //Post a Change message for all events except rename
         void OnFileEvent(object sender, FileSystemEventArgs e)
         {
index 17f150c..d9d62d0 100644 (file)
@@ -674,24 +674,21 @@ namespace Pithos.Core.Agents
                             &&
                             state.FilePath.StartsWith(accountInfo.AccountPath)).ToList();*/
 
+
             var deleteCandidates = FileState.Queryable
                 .Where(state => state.Modified <= pollTime
                             &&
                             state.FilePath.StartsWith(accountInfo.AccountPath)
                             && state.FileStatus != FileStatus.Conflict).ToList();
-/*
-            var deleteCandidates = (from state in FileState.Queryable
-                                   where 
-                                        state.Modified <= pollTime 
-                                        && state.FilePath.StartsWith(accountInfo.AccountPath)
-                                        && state.FileStatus != FileStatus.Conflict
-                                   select state).ToList();
-*/
 
+            //TODO: filesToDelete must take into account the Others container
             var filesToDelete = (from deleteCandidate in deleteCandidates 
                          let localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath) 
                          let relativeFilePath = localFile.AsRelativeTo(accountInfo.AccountPath) 
-                         where !cloudFiles.Any(r => Path.Combine(r.Container, r.Name) == relativeFilePath) 
+                         where !cloudFiles.Any(r => 
+                             Path.Combine(r.Container, r.Name) == relativeFilePath ||                   //Own file
+                             Path.Combine(FolderConstants.OthersFolder,r.Account, r.Container, r.Name) == relativeFilePath  //Shared file
+                             ) 
                          select localFile).ToList();
 
             //On the first run
@@ -709,7 +706,15 @@ namespace Pithos.Core.Agents
             {
                 foreach (var item in filesToDelete)
                 {
-                    item.Delete();
+                    if (item.Exists)
+                    {
+                        if ((item.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
+                        {
+                            item.Attributes = item.Attributes & ~FileAttributes.ReadOnly;
+
+                        }
+                        item.Delete();
+                    }
                     StatusKeeper.ClearFileStatus(item.FullName);
                 }
                 StatusNotification.NotifyForFiles(filesToDelete, String.Format("{0} files were deleted",filesToDelete.Count),TraceLevel.Info);
index fb48a95..7aed652 100644 (file)
@@ -204,7 +204,7 @@ namespace Pithos.Interfaces
                 if (Account != null)
                 {
                     pathParts.Push(Account);
-                    pathParts.Push("others");
+                    pathParts.Push(FolderConstants.OthersFolder);
                 }
             }
             var finalPath=Path.Combine(pathParts.ToArray());
index e611977..4728e04 100644 (file)
   <ItemGroup>
     <Compile Include="AccountSettings.cs" />
     <Compile Include="FileInfoExtensions.cs" />
+    <Compile Include="FolderConstants.cs" />
     <Compile Include="IPithosSettings.cs" />
     <Compile Include="IStatusChecker.cs" />
     <Compile Include="PermissionConverter.cs" />
index 63d4211..c75975b 100644 (file)
@@ -1042,15 +1042,14 @@ namespace Pithos.Network
                         using(var reader=new StreamReader(stream))
                         {
                             Debug.Assert(stream.Position == 0);
-                            //We need to cleanup the content before returning it because it contains
+                            //We used to have to cleanup the content before returning it because it contains
                             //error content after the list of hashes
-                            var hashes = new List<string>();
-                            string line=null;
-                            //All lines up to the first empty line are hashes
-                            while(!String.IsNullOrWhiteSpace(line=reader.ReadLine()))
-                            {
-                                hashes.Add(line);
-                            }
+                            //
+                            //As of 30/1/2012, the result is a proper Json array so we don't need to read the content
+                            //line by line
+                            
+                            var serializer = new JsonSerializer();                            
+                            var hashes=(List<string>)serializer.Deserialize(reader, typeof (List<string>));
 
                             return hashes;
                         }                        
diff --git a/trunk/Pithos.Network/FolderConstants.cs b/trunk/Pithos.Network/FolderConstants.cs
deleted file mode 100644 (file)
index 65a62f7..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Pithos.Network
-{
-    public static class FolderConstants
-    {
-        public static readonly string OthersFolder="others-shared";
-        public static readonly string PithosContainer = "pithos";
-        public static readonly string TrashContainer = "trash";
-
-        public static readonly string CacheFolder = ".pithos.cache";
-    }
-}
index 32a05d8..f2930f3 100644 (file)
     <Compile Include="AccountInfo.cs" />
     <Compile Include="CloudFilesClient.cs" />
     <Compile Include="ContainerInfo.cs" />
-    <Compile Include="FolderConstants.cs" />
     <Compile Include="ICloudClient.cs" />
     <Compile Include="RestClient.cs">
       <SubType>Component</SubType>