Fix to upload both folder and file contents, when uploading a new unselected root...
authorpkanavos <pkanavos@gmail.com>
Thu, 24 May 2012 19:03:51 +0000 (22:03 +0300)
committerpkanavos <pkanavos@gmail.com>
Thu, 24 May 2012 19:03:51 +0000 (22:03 +0300)
Folders are uploaded first to ensure the selective folders are updated first

trunk/Pithos.Core/Agents/NetworkAgent.cs
trunk/Pithos.Core/EnumerableExtensions.cs

index 6431ffe..f292299 100644 (file)
@@ -305,24 +305,32 @@ namespace Pithos.Core.Agents
             var dirInfo = uploadAction.LocalFile as DirectoryInfo;
 
             var account = uploadAction.AccountInfo;
-            var actions = from file in dirInfo.EnumerateFiles("*", SearchOption.AllDirectories)
+            var folderActions = from info in dirInfo.EnumerateDirectories("*", SearchOption.AllDirectories)                          
                           select
-                              new CloudUploadAction(account, file, null, account.BlockSize, account.BlockHash,
+                              new CloudUploadAction(account, info, null, account.BlockSize, account.BlockHash,
                                                     uploadAction, true);
-            foreach (var action in actions)
-            {
-                var state=StatusKeeper.GetStateByFilePath(action.LocalFile.FullName);
-                if (state!=null)
-                    state.Delete();
-                //StatusKeeper.SetFileState(action.LocalFile.FullName,FileStatus.Created,FileOverlayStatus.Normal,String.Empty);
-                state=FileState.CreateFor(action.LocalFile);
-                //StatusKeeper.SetFileStatus();
-                state.FileStatus = FileStatus.Created;
-                state.OverlayStatus=FileOverlayStatus.Normal;
-                state.Create();
-                action.FileState = state;
-                Post(action);
-            }
+            var fileActions = from info in dirInfo.EnumerateFiles("*", SearchOption.AllDirectories)                          
+                          select
+                              new CloudUploadAction(account, info, null, account.BlockSize, account.BlockHash,
+                                                    uploadAction, true);            
+            //Post folder actions first, to ensure the selective folders are updated
+            folderActions.ApplyAction(PostUploadAction);
+            fileActions.ApplyAction(PostUploadAction);            
+        }
+
+        private void PostUploadAction(CloudUploadAction action)
+        {
+            var state = StatusKeeper.GetStateByFilePath(action.LocalFile.FullName);
+            if (state != null)
+                state.Delete();
+            //StatusKeeper.SetFileState(action.LocalFile.FullName,FileStatus.Created,FileOverlayStatus.Normal,String.Empty);
+            state = FileState.CreateFor(action.LocalFile);
+            //StatusKeeper.SetFileStatus();
+            state.FileStatus = FileStatus.Created;
+            state.OverlayStatus = FileOverlayStatus.Normal;
+            state.Create();
+            action.FileState = state;
+            Post(action);
         }
 
         private CancellationToken CurrentOperationCancelToken
index 19e71c3..2c459fe 100644 (file)
@@ -66,6 +66,17 @@ namespace Pithos.Core
                 yield return array[i];
         }
 
+        public static void ApplyAction<T>(this IEnumerable<T> list,Action<T> action)
+        {
+            if (list == null)
+                return;
+
+            foreach (var item in list)
+            {
+                action(item);
+            }
+        }
+
       
     }
 }