Renamed Fragments to Cache
authorPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 24 Oct 2011 17:05:06 +0000 (20:05 +0300)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 24 Oct 2011 17:05:06 +0000 (20:05 +0300)
trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
trunk/Pithos.Core.Test/NetworkAgentTest.cs
trunk/Pithos.Core/Agents/BlockUpdater.cs
trunk/Pithos.Core/Agents/FileAgent.cs
trunk/Pithos.Core/Agents/NetworkAgent.cs
trunk/Pithos.Core/Agents/StatusAgent.cs
trunk/Pithos.Core/Agents/WorkflowAgent.cs
trunk/Pithos.Core/PithosMonitor.cs
trunk/Pithos.Core/PithosWorkflow.cs
trunk/Pithos.Network/FolderConstants.cs

index 43a949d..38afd74 100644 (file)
@@ -17,16 +17,16 @@ namespace Pithos.Client.WPF.SelectiveSynch
         private IEventAggregator _events ;
 
         private string _rootPath;
-        private string _fragmentsPath;
+        private string _cachePath;
         public string RootPath
         {
             get { return _rootPath; }
             set
             {
                 _rootPath = value;
-                _fragmentsPath = Path.Combine(_rootPath, FolderConstants.FragmentsFolder);
+                _cachePath = Path.Combine(_rootPath, FolderConstants.CacheFolder);
                 _pithosDirectory = new ObservableCollection<DirectoryRecord>{
-                        new DirectoryRecord(_fragmentsPath) {Info = new DirectoryInfo(value)}};
+                        new DirectoryRecord(_cachePath) {Info = new DirectoryInfo(value)}};
                 NotifyOfPropertyChange(() => RootPath);
                 NotifyOfPropertyChange(()=>PithosDirectory);
             }
index 4889515..ac85e89 100644 (file)
@@ -70,7 +70,7 @@ namespace Pithos.Core.Test
         [Test]
         public void TestDownload()
         {
-            var fileAgent = new FileAgent {FragmentsPath = @"e:\pithos\Fragments"};
+            var fileAgent = new FileAgent {CachePath = @"e:\pithos\.pithos.cache"};
 
             var agent = new NetworkAgent();
 
index 42d4e0d..91d8b97 100644 (file)
@@ -16,7 +16,7 @@ namespace Pithos.Core.Agents
         public string FilePath { get; private set; }
         public string RelativePath { get; private set; }
 
-        public string FragmentsPath { get; private set; }
+        public string CachePath { get; private set; }
 
         public TreeHash ServerHash { get; private set; }
 
@@ -33,7 +33,7 @@ namespace Pithos.Core.Agents
         [ContractInvariantMethod]
         private void Invariants()
         {
-            Contract.Invariant(Path.IsPathRooted(FragmentsPath));
+            Contract.Invariant(Path.IsPathRooted(CachePath));
             Contract.Invariant(Path.IsPathRooted(FilePath));
             Contract.Invariant(Path.IsPathRooted(TempPath));
             Contract.Invariant(!Path.IsPathRooted(RelativePath));
@@ -42,12 +42,12 @@ namespace Pithos.Core.Agents
             Contract.Invariant(ServerHash!=null);
         }
 
-        public BlockUpdater(string fragmentsPath, string filePath, string relativePath,TreeHash serverHash)
+        public BlockUpdater(string cachePath, string filePath, string relativePath,TreeHash serverHash)
         {   
-            if (String.IsNullOrWhiteSpace(fragmentsPath))
-                throw new ArgumentNullException("fragmentsPath");
-            if (!Path.IsPathRooted(fragmentsPath))
-                throw new ArgumentException("The fragmentsPath must be rooted", "fragmentsPath");
+            if (String.IsNullOrWhiteSpace(cachePath))
+                throw new ArgumentNullException("cachePath");
+            if (!Path.IsPathRooted(cachePath))
+                throw new ArgumentException("The cachePath must be rooted", "cachePath");
             
             if (string.IsNullOrWhiteSpace(filePath))
                 throw new ArgumentNullException("filePath");
@@ -63,19 +63,19 @@ namespace Pithos.Core.Agents
                 throw new ArgumentNullException("serverHash");
             Contract.EndContractBlock();
 
-            FragmentsPath=fragmentsPath;
+            CachePath=cachePath;
             FilePath = filePath;
             RelativePath=relativePath;
             ServerHash = serverHash;
             //The file will be stored in a temporary location while downloading with an extension .download
-            TempPath = Path.Combine(FragmentsPath, RelativePath + ".download");
+            TempPath = Path.Combine(CachePath, RelativePath + ".download");
             
             //Need to calculate the directory path because RelativePath may include folders
             var directoryPath = Path.GetDirectoryName(TempPath);            
             //directoryPath CAN be null if TempPath is a root path
             if (String.IsNullOrWhiteSpace(directoryPath))
                 throw new ArgumentException("TempPath");
-            //FragmentsPath was absolute so directoryPath is absolute too
+            //CachePath was absolute so directoryPath is absolute too
             Contract.Assume(Path.IsPathRooted(directoryPath));
             
             if (!Directory.Exists(directoryPath))
index ef24ba2..cfb5367 100644 (file)
@@ -132,7 +132,7 @@ namespace Pithos.Core.Agents
             }
         }
 
-        public string FragmentsPath { get; set; }
+        public string CachePath { get; set; }
 
         private List<string> _selectivePaths = new List<string>();
         public List<string> SelectivePaths
@@ -200,7 +200,7 @@ namespace Pithos.Core.Agents
 
         private bool Ignore(string filePath)
         {
-            if (filePath.StartsWith(FragmentsPath))
+            if (filePath.StartsWith(CachePath))
                 return true;
             if (_ignoreFiles.ContainsKey(filePath.ToLower()))
                 return true;
@@ -210,7 +210,7 @@ namespace Pithos.Core.Agents
         //Post a Change message for all events except rename
         void OnFileEvent(object sender, FileSystemEventArgs e)
         {
-            //Ignore events that affect the Fragments folder
+            //Ignore events that affect the cache folder
             var filePath = e.FullPath;
             if (Ignore(filePath)) 
                 return;           
index 5a76056..a65484b 100644 (file)
@@ -352,7 +352,7 @@ namespace Pithos.Core.Agents
                         var remote = from info in remoteObjects.Union(sharedObjects)
                                      let name = info.Name
                                      where !name.EndsWith(".ignore", StringComparison.InvariantCultureIgnoreCase) &&
-                                           !name.StartsWith("fragments/", StringComparison.InvariantCultureIgnoreCase)
+                                           !name.StartsWith(FolderConstants.CacheFolder +"/", StringComparison.InvariantCultureIgnoreCase)
                                      select info;
 
                         //Create a list of actions from the remote files
@@ -557,7 +557,7 @@ namespace Pithos.Core.Agents
                 if (gate.Failed)
                     yield break;
                 //The file's hashmap will be stored in the same location with the extension .hashmap
-                //var hashPath = Path.Combine(FileAgent.FragmentsPath, relativePath + ".hashmap");
+                //var hashPath = Path.Combine(FileAgent.CachePath, relativePath + ".hashmap");
                 
                 var client = new CloudFilesClient(accountInfo);
                 var account = cloudFile.Account;
@@ -623,7 +623,7 @@ namespace Pithos.Core.Agents
             //Calculate the relative file path for the new file
             var relativePath = relativeUrl.RelativeUriToFilePath();
             //The file will be stored in a temporary location while downloading with an extension .download
-            var tempPath = Path.Combine(fileAgent.FragmentsPath, relativePath + ".download");
+            var tempPath = Path.Combine(fileAgent.CachePath, relativePath + ".download");
             //Make sure the target folder exists. DownloadFileTask will not create the folder
             var tempFolder = Path.GetDirectoryName(tempPath);
             if (!Directory.Exists(tempFolder))
@@ -689,7 +689,7 @@ namespace Pithos.Core.Agents
             
             //Calculate the relative file path for the new file
             var relativePath = relativeUrl.RelativeUriToFilePath();
-            var blockUpdater = new BlockUpdater(fileAgent.FragmentsPath, localPath, relativePath, serverHash);
+            var blockUpdater = new BlockUpdater(fileAgent.CachePath, localPath, relativePath, serverHash);
 
             
                         
index bd50851..c29aa2f 100644 (file)
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
 using Castle.ActiveRecord;
 using Castle.ActiveRecord.Framework.Config;
 using Pithos.Interfaces;
+using Pithos.Network;
 using log4net;
 using log4net.Appender;
 using log4net.Config;
@@ -56,9 +57,9 @@ namespace Pithos.Core.Agents
         private void CleanupStaleStates()
         {
             /*var stales = from state in FileState.Queryable
-                         where state.FilePath.StartsWith(@"e:\pithos\fragments")
+                         where state.FilePath.StartsWith(@"e:\pithos\cache")
                          select state.Id;*/
-            FileState.DeleteAll(@"FilePath like 'e:\pithos\fragments%'");
+            FileState.DeleteAll(@"FilePath like 'e:\pithos\.pithos.cache%'");
             ;
         }
 
@@ -295,7 +296,7 @@ namespace Pithos.Core.Agents
                 throw new ArgumentNullException("setter");
             Contract.EndContractBlock();
 
-            Debug.Assert(!path.Contains("fragments"));
+            Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
             Debug.Assert(!path.EndsWith(".ignore"));
 
             if (String.IsNullOrWhiteSpace(path))
index 0d828a0..1580b28 100644 (file)
@@ -22,10 +22,6 @@ namespace Pithos.Core.Agents
         [Import]
         public IStatusKeeper StatusKeeper { get; set; }
 
-        //We should avoid processing files stored in the Fragments folder
-        //The Full path to the fragments folder is stored in FragmentsPath
-        //public string FragmentsPath { get; set; }
-
         [Import]
         public NetworkAgent NetworkAgent { get; set; }
 
@@ -110,13 +106,13 @@ namespace Pithos.Core.Agents
                 if (Log.IsDebugEnabled)
                     Log.Debug("Starting interrupted files");
 
-                var fragmentsPath = Path.Combine(accountInfo.AccountPath, FolderConstants.FragmentsFolder)
+                var cachePath = Path.Combine(accountInfo.AccountPath, FolderConstants.CacheFolder)
                     .ToLower();
 
 
                 var pendingEntries = from state in FileState.Queryable
                                      where state.FileStatus != FileStatus.Unchanged &&
-                                           !state.FilePath.StartsWith(fragmentsPath) &&
+                                           !state.FilePath.StartsWith(cachePath) &&
                                            !state.FilePath.EndsWith(".ignore") &&
                                            state.FilePath.StartsWith(accountInfo.AccountPath)
                                      select state;
index fc356b6..0deb452 100644 (file)
@@ -124,6 +124,9 @@ namespace Pithos.Core
             _accountInfo = CloudClient.Authenticate();
             _accountInfo.AccountPath = RootPath;
 
+            //Create the cache folder and ensure it is hidden
+            CreateHiddenFolder(RootPath, FolderConstants.CacheFolder);
+
             var policy=CloudClient.GetAccountPolicies(_accountInfo);
 
             StatusNotification.NotifyAccount(policy);
@@ -191,11 +194,11 @@ namespace Pithos.Core
                 Log.Info("START");
                 try
                 {
-                    var fragmentsPath = Path.Combine(RootPath, FolderConstants.FragmentsFolder);
+                    var cachePath = Path.Combine(RootPath, FolderConstants.CacheFolder);
                     var directory = new DirectoryInfo(RootPath);
                     var files =
                         from file in directory.EnumerateFiles("*", SearchOption.AllDirectories)
-                        where !file.FullName.StartsWith(fragmentsPath, StringComparison.InvariantCultureIgnoreCase) &&
+                        where !file.FullName.StartsWith(cachePath, StringComparison.InvariantCultureIgnoreCase) &&
                               !file.Extension.Equals("ignore", StringComparison.InvariantCultureIgnoreCase)
                         select file;
                     StatusKeeper.ProcessExistingFiles(files);
@@ -291,7 +294,7 @@ namespace Pithos.Core
             NetworkAgent.ProcessRemoteFiles();
         }
 
-        //Make sure a hidden fragments folder exists to store partial downloads
+        //Make sure a hidden cache folder exists to store partial downloads
         private static string CreateHiddenFolder(string rootPath, string folderName)
         {
             if (String.IsNullOrWhiteSpace(rootPath))
@@ -308,7 +311,16 @@ namespace Pithos.Core
                 var info = Directory.CreateDirectory(folder);
                 info.Attributes |= FileAttributes.Hidden;
 
-                Log.InfoFormat("Created Fragments Folder: {0}", folder);
+                Log.InfoFormat("Created cache Folder: {0}", folder);
+            }
+            else
+            {
+                var info = new DirectoryInfo(folder);
+                if ((info.Attributes & FileAttributes.Hidden) == 0)
+                {
+                    info.Attributes |= FileAttributes.Hidden;
+                    Log.InfoFormat("Reset cache folder to hidden: {0}", folder);
+                }                                
             }
             return folder;
         }
@@ -322,7 +334,7 @@ namespace Pithos.Core
 
             FileAgent.StatusKeeper = StatusKeeper;
             FileAgent.Workflow = Workflow;
-            FileAgent.FragmentsPath = Path.Combine(RootPath, FolderConstants.FragmentsFolder);
+            FileAgent.CachePath = Path.Combine(RootPath, FolderConstants.CacheFolder);
             FileAgent.Start(_accountInfo, RootPath);
         }
 
index 1badcc1..4bcde1e 100644 (file)
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
 using Pithos.Interfaces;
 using System.IO;
 using System.Diagnostics;
+using Pithos.Network;
 
 namespace Pithos.Core
 {
@@ -23,7 +24,7 @@ namespace Pithos.Core
 
         public FileStatus SetFileStatus(string path, FileStatus status)
         {
-            Debug.Assert(!path.Contains("fragments"));
+            Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
             Debug.Assert(!path.EndsWith(".ignore",StringComparison.InvariantCultureIgnoreCase));
 
             if (String.IsNullOrWhiteSpace(path))
index 6ae13d5..9180359 100644 (file)
@@ -6,6 +6,6 @@
         public static readonly string PithosContainer = "pithos";
         public static readonly string TrashContainer = "trash";
 
-        public static readonly string FragmentsFolder = "fragments";
+        public static readonly string CacheFolder = ".pithos.cache";
     }
 }