Revision 9c6d3193 trunk/Pithos.Core/Agents/NetworkAgent.cs
b/trunk/Pithos.Core/Agents/NetworkAgent.cs | ||
---|---|---|
627 | 627 |
throw new ArgumentNullException("cloudFiles"); |
628 | 628 |
Contract.EndContractBlock(); |
629 | 629 |
|
630 |
if (_firstPoll) return; |
|
631 |
//TODO: Do I need the "Modified" check if I'm not going to delete files that |
|
632 |
//were not found on the server on the first run? |
|
633 |
//TODO: Files that were not found on the server on the first run should be marked IN CONFLICT |
|
634 |
var deleteCandidates = from state in FileState.Queryable |
|
635 |
where state.Modified <= pollTime && state.FilePath.StartsWith(accountInfo.AccountPath) |
|
636 |
select state; |
|
637 |
|
|
638 |
foreach (var deleteCandidate in deleteCandidates) |
|
630 |
//Check the Modified date to ensure that were just created and haven't been uploaded yet |
|
631 |
//NOTE: The NHibernate LINQ provider doesn't support custom functions so we need to break the query |
|
632 |
//in two steps |
|
633 |
//NOTE: DON'T return files that are already in conflict. The first poll would mark them as |
|
634 |
//"In Conflict" but subsequent polls would delete them |
|
635 |
var deleteCandidates = (from state in FileState.Queryable |
|
636 |
where |
|
637 |
state.Modified <= pollTime |
|
638 |
&& state.FilePath.StartsWith(accountInfo.AccountPath) |
|
639 |
&& state.FileStatus != FileStatus.Conflict |
|
640 |
select state).ToList(); |
|
641 |
|
|
642 |
var filesToDelete = (from deleteCandidate in deleteCandidates |
|
643 |
let localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath) |
|
644 |
let relativeFilePath = localFile.AsRelativeTo(accountInfo.AccountPath) |
|
645 |
where !cloudFiles.Any(r => Path.Combine(r.Container, r.Name) == relativeFilePath) |
|
646 |
select localFile).ToList(); |
|
647 |
|
|
648 |
//On the first run |
|
649 |
if (_firstPoll) |
|
639 | 650 |
{ |
640 |
var localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath); |
|
641 |
var relativeFilePath=localFile.AsRelativeTo(accountInfo.AccountPath); |
|
642 |
if (!cloudFiles.Any(r => Path.Combine(r.Container, r.Name) == relativeFilePath)) |
|
651 |
//Set the status of missing files to Conflict |
|
652 |
foreach (var item in filesToDelete) |
|
643 | 653 |
{ |
644 |
localFile.Delete(); |
|
645 |
StatusKeeper.ClearFileStatus(deleteCandidate.FilePath); |
|
654 |
StatusKeeper.SetFileState(item.FullName, FileStatus.Conflict, FileOverlayStatus.Deleted); |
|
646 | 655 |
} |
656 |
StatusNotification.NotifyConflicts(filesToDelete, String.Format("{0} local files are missing from Pithos, possibly because they were deleted",filesToDelete.Count)); |
|
647 | 657 |
} |
658 |
else |
|
659 |
{ |
|
660 |
foreach (var item in filesToDelete) |
|
661 |
{ |
|
662 |
item.Delete(); |
|
663 |
StatusKeeper.ClearFileStatus(item.FullName); |
|
664 |
} |
|
665 |
StatusNotification.NotifyForFiles(filesToDelete, String.Format("{0} files were deleted",filesToDelete.Count),TraceLevel.Info); |
|
666 |
} |
|
667 |
|
|
648 | 668 |
} |
649 | 669 |
|
650 | 670 |
private static void CreateContainerFolders(AccountInfo accountInfo, IEnumerable<ContainerInfo> containers) |
Also available in: Unified diff