throw new ArgumentNullException("cloudFiles");
Contract.EndContractBlock();
- if (_firstPoll) return;
-
- var deleteCandidates = from state in FileState.Queryable
- let stateUrl = FileInfoExtensions.FromPath(state.FilePath)
- .AsRelativeUrlTo(accountInfo.AccountPath)
- where state.Modified <= pollTime &&
- !cloudFiles.Any(r => r.Name == stateUrl)
- 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)
+ {
+ //Set the status of missing files to Conflict
+ foreach (var item in filesToDelete)
+ {
+ 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
{
- File.Delete(deleteCandidate.FilePath);
- StatusKeeper.ClearFileStatus(deleteCandidate.FilePath);
+ 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)