Added _lastSeen dictionary to use as log of files, in an attempt to prevent deletion...
authorPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 9 Feb 2012 17:47:54 +0000 (19:47 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Thu, 9 Feb 2012 17:47:54 +0000 (19:47 +0200)
trunk/Pithos.Client.WPF/PithosAccount.cs
trunk/Pithos.Core/Agents/NetworkAgent.cs

index fda2b6d..66bfae6 100644 (file)
@@ -152,12 +152,15 @@ namespace Pithos.Client.WPF
                 using (var client = await listener.AcceptTcpClientAsync()
                                         .WithTimeout(TimeSpan.FromMinutes(5)))
                 {
                 using (var client = await listener.AcceptTcpClientAsync()
                                         .WithTimeout(TimeSpan.FromMinutes(5)))
                 {
-
                     using (var stream = client.GetStream())
                     using (var reader=new StreamReader(stream))
                     {
                         var request = await reader.ReadLineAsync();
                     using (var stream = client.GetStream())
                     using (var reader=new StreamReader(stream))
                     {
                         var request = await reader.ReadLineAsync();
-                        if (request == null)
+                        //BUG
+                        //TODO: Add proper warnings here if the content is empty, don't just throw an exception
+                        //This may be a common occurence 
+
+                        if (String.IsNullOrWhiteSpace(request))
                             throw new Exception("Nothing retrieved");
                         Log.InfoFormat("[RETRIEVE] Got Connection {0}", request);
 
                             throw new Exception("Nothing retrieved");
                         Log.InfoFormat("[RETRIEVE] Got Connection {0}", request);
 
index 152fc34..8665616 100644 (file)
@@ -81,6 +81,7 @@ namespace Pithos.Core.Agents
 
         private bool _firstPoll = true;
         private TaskCompletionSource<bool> _tcs;
 
         private bool _firstPoll = true;
         private TaskCompletionSource<bool> _tcs;
+        private ConcurrentDictionary<string,DateTime> _lastSeen=new ConcurrentDictionary<string, DateTime>();
 
         public void Start()
         {
 
         public void Start()
         {
@@ -678,24 +679,29 @@ namespace Pithos.Core.Agents
             //Consider for deleteion only files modified before the PREVIOUS poll
             //A user may perform a file creation or rename at roughly the same time as a poll. In such a case
             //the new file will appear as deleted
             //Consider for deleteion only files modified before the PREVIOUS poll
             //A user may perform a file creation or rename at roughly the same time as a poll. In such a case
             //the new file will appear as deleted
-            var previousPollTime = pollTime.Subtract(TimeSpan.FromMilliseconds(Settings.PollingInterval));
+            var previousPollTime = pollTime.Subtract(TimeSpan.FromMilliseconds(Settings.PollingInterval));                       
 
 
+            //Only consider files that are not being modified, ie they are in the Unchanged state            
             var deleteCandidates = FileState.Queryable.Where(state => 
                 state.Modified <= previousPollTime
             var deleteCandidates = FileState.Queryable.Where(state => 
                 state.Modified <= previousPollTime
-                && state.FilePath.StartsWith(accountInfo.AccountPath)
-                && state.FileStatus != FileStatus.Conflict).ToList();
+                && state.FilePath.StartsWith(accountInfo.AccountPath)                
+                && state.FileStatus == FileStatus.Unchanged).ToList();
 
 
-            //TODO: filesToDelete must take into account the Others container
+            //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) 
             var filesToDelete = (from deleteCandidate in deleteCandidates 
                          let localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath) 
                          let relativeFilePath = localFile.AsRelativeTo(accountInfo.AccountPath) 
-                         where !cloudFiles.Any(r => r.RelativeUrlToFilePath(accountInfo.UserName) == relativeFilePath ) 
+                         let agentActions = _agent.GetEnumerable()
+                         where 
+                                 !_lastSeen.ContainsKey(localFile.FullName)
+                         && !cloudFiles.Any(r => r.RelativeUrlToFilePath(accountInfo.UserName) == relativeFilePath ) 
                          //Exclude files enqueued for uploading
                          //Large files will not appear on the server for multiple polls. They must not be marked as deleted
                          //Exclude files enqueued for uploading
                          //Large files will not appear on the server for multiple polls. They must not be marked as deleted
-                         && !_agent.GetEnumerable().Any(action => action.LocalFile.WithProperCapitalization().FullName == localFile.FullName)
+                         && !agentActions.Any(action => action.LocalFile.WithProperCapitalization().FullName == localFile.FullName)
                          //Do NOT delete files modified since the previous poll
                                 && localFile.LastAccessTime < previousPollTime
                          select localFile).ToList();
                          //Do NOT delete files modified since the previous poll
                                 && localFile.LastAccessTime < previousPollTime
                          select localFile).ToList();
+            
 
             //On the first run
             if (_firstPoll)
 
             //On the first run
             if (_firstPoll)
@@ -781,6 +787,7 @@ namespace Pithos.Core.Agents
                     using (new SessionScope(FlushAction.Never))
                     {
                         var state =  StatusKeeper.GetStateByFilePath(localFile.FullName);
                     using (new SessionScope(FlushAction.Never))
                     {
                         var state =  StatusKeeper.GetStateByFilePath(localFile.FullName);
+                        _lastSeen[localFile.FullName] = DateTime.Now;
                         //FileState.FindByFilePath(localFile.FullName);
                         //Common files should be checked on a per-case basis to detect differences, which is newer
 
                         //FileState.FindByFilePath(localFile.FullName);
                         //Common files should be checked on a per-case basis to detect differences, which is newer