Revision bc27bb7e trunk/Pithos.Core/Agents/StatusAgent.cs
b/trunk/Pithos.Core/Agents/StatusAgent.cs | ||
---|---|---|
844 | 844 |
_persistenceAgent.Post(() => FileState.UpdateChecksum(path, shortHash,checksum)); |
845 | 845 |
} |
846 | 846 |
|
847 |
|
|
848 |
public void CleanupOrphanStates() |
|
849 |
{ |
|
850 |
//Orphan states are those that do not correspond to an account, ie. their paths |
|
851 |
//do not start with the root path of any registered account |
|
852 |
|
|
853 |
var roots=(from account in Settings.Accounts |
|
854 |
select account.RootPath).ToList(); |
|
855 |
|
|
856 |
var allStates = from state in FileState.Queryable |
|
857 |
select state.FilePath; |
|
858 |
|
|
859 |
foreach (var statePath in allStates) |
|
860 |
{ |
|
861 |
if (!roots.Any(root=>statePath.StartsWith(root,StringComparison.InvariantCultureIgnoreCase))) |
|
862 |
this.DeleteDirect(statePath); |
|
863 |
} |
|
864 |
} |
|
865 |
|
|
866 |
public void CleanupStaleStates(AccountInfo accountInfo, List<ObjectInfo> objectInfos) |
|
867 |
{ |
|
868 |
if (accountInfo == null) |
|
869 |
throw new ArgumentNullException("accountInfo"); |
|
870 |
if (objectInfos == null) |
|
871 |
throw new ArgumentNullException("objectInfos"); |
|
872 |
Contract.EndContractBlock(); |
|
873 |
|
|
874 |
|
|
875 |
|
|
876 |
//Stale states are those that have no corresponding local or server file |
|
877 |
|
|
878 |
|
|
879 |
var agent=FileAgent.GetFileAgent(accountInfo); |
|
880 |
|
|
881 |
var localFiles=agent.EnumerateFiles(); |
|
882 |
var localSet = new HashSet<string>(localFiles); |
|
883 |
|
|
884 |
var serverFiles = from info in objectInfos |
|
885 |
select Path.Combine(accountInfo.AccountPath,info.RelativeUrlToFilePath(accountInfo.UserName)); |
|
886 |
var serverSet = new HashSet<string>(serverFiles); |
|
887 |
|
|
888 |
var allStates = from state in FileState.Queryable |
|
889 |
where state.FilePath.StartsWith(agent.RootPath) |
|
890 |
select state.FilePath; |
|
891 |
var stateSet = new HashSet<string>(allStates); |
|
892 |
stateSet.ExceptWith(serverSet); |
|
893 |
stateSet.ExceptWith(localSet); |
|
894 |
|
|
895 |
foreach (var remainder in stateSet) |
|
896 |
{ |
|
897 |
DeleteDirect(remainder); |
|
898 |
} |
|
899 |
|
|
900 |
|
|
901 |
} |
|
847 | 902 |
} |
848 | 903 |
|
849 | 904 |
|
Also available in: Unified diff