}
+ public void NotifyConflicts(IEnumerable<FileSystemInfo> conflictFiles, string message)
+ {
+ if (conflictFiles == null)
+ return;
+ if (!conflictFiles.Any())
+ return;
+ //TODO: Create a more specific message. For now, just show a warning
+ NotifyForFiles(conflictFiles,message,TraceLevel.Warning);
+
+ }
+
+ public void NotifyForFiles(IEnumerable<FileSystemInfo> files, string message,TraceLevel level=TraceLevel.Info)
+ {
+ if (files == null)
+ return;
+ if (!files.Any())
+ return;
+
+ StatusMessage = message;
+
+ _events.Publish(new Notification { Title = "Pithos", Message = message, Level = level});
+ }
+
- public void RemoveMonitor(string accountName)
+ public void RemoveMonitor(string accountName)
{
if (String.IsNullOrWhiteSpace(accountName))
return;
throw new ArgumentNullException("cloudFiles");
Contract.EndContractBlock();
- if (_firstPoll) return;
- //TODO: Do I need the "Modified" check if I'm not going to delete files that
- //were not found on the server on the first run?
- //TODO: Files that were not found on the server on the first run should be marked IN CONFLICT
- var deleteCandidates = from state in FileState.Queryable
- where state.Modified <= pollTime && state.FilePath.StartsWith(accountInfo.AccountPath)
- select state;
-
- foreach (var deleteCandidate in deleteCandidates)
+ //Check the Modified date to ensure that were just created and haven't been uploaded yet
+ //NOTE: The NHibernate LINQ provider doesn't support custom functions so we need to break the query
+ //in two steps
+ //NOTE: DON'T return files that are already in conflict. The first poll would mark them as
+ //"In Conflict" but subsequent polls would delete them
+ var deleteCandidates = (from state in FileState.Queryable
+ where
+ state.Modified <= pollTime
+ && state.FilePath.StartsWith(accountInfo.AccountPath)
+ && state.FileStatus != FileStatus.Conflict
+ select state).ToList();
+
+ 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)
+ select localFile).ToList();
+
+ //On the first run
+ if (_firstPoll)
{
- var localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath);
- var relativeFilePath=localFile.AsRelativeTo(accountInfo.AccountPath);
- if (!cloudFiles.Any(r => Path.Combine(r.Container, r.Name) == relativeFilePath))
+ //Set the status of missing files to Conflict
+ foreach (var item in filesToDelete)
{
- localFile.Delete();
- StatusKeeper.ClearFileStatus(deleteCandidate.FilePath);
+ StatusKeeper.SetFileState(item.FullName, FileStatus.Conflict, FileOverlayStatus.Deleted);
}
+ StatusNotification.NotifyConflicts(filesToDelete, String.Format("{0} local files are missing from Pithos, possibly because they were deleted",filesToDelete.Count));
}
+ else
+ {
+ foreach (var item in filesToDelete)
+ {
+ item.Delete();
+ StatusKeeper.ClearFileStatus(item.FullName);
+ }
+ StatusNotification.NotifyForFiles(filesToDelete, String.Format("{0} files were deleted",filesToDelete.Count),TraceLevel.Info);
+ }
+
}
private static void CreateContainerFolders(AccountInfo accountInfo, IEnumerable<ContainerInfo> containers)