Revision b5061ac8 trunk/Pithos.Core/InMemStatusChecker.cs
b/trunk/Pithos.Core/InMemStatusChecker.cs | ||
---|---|---|
1 | 1 |
using System; |
2 |
using System.Collections.Concurrent; |
|
2 | 3 |
using System.Collections.Generic; |
3 | 4 |
using System.ComponentModel.Composition; |
4 | 5 |
using System.Diagnostics.Contracts; |
6 |
using System.Linq; |
|
5 | 7 |
using Pithos.Interfaces; |
6 | 8 |
|
7 | 9 |
namespace Pithos.Core |
... | ... | |
14 | 16 |
|
15 | 17 |
private readonly string[] _states = {"Normal", "Modified", "Conflict","Synch"}; |
16 | 18 |
|
17 |
Dictionary<string,FileOverlayStatus> _overlayCache=new Dictionary<string,FileOverlayStatus>();
|
|
18 |
Dictionary<string, FileStatus> _statusCache= new Dictionary<string, FileStatus>();
|
|
19 |
Dictionary<string, string> _checksums = new Dictionary<string, string>();
|
|
19 |
ConcurrentDictionary<string, FileOverlayStatus> _overlayCache = new ConcurrentDictionary<string, FileOverlayStatus>();
|
|
20 |
ConcurrentDictionary<string, FileStatus> _statusCache = new ConcurrentDictionary<string, FileStatus>();
|
|
21 |
ConcurrentDictionary<string, string> _checksums = new ConcurrentDictionary<string, string>();
|
|
20 | 22 |
|
21 | 23 |
public FileOverlayStatus GetFileOverlayStatus(string path) |
22 | 24 |
{ |
23 | 25 |
if (!_overlayCache.ContainsKey(path)) |
24 |
return FileOverlayStatus.NA;
|
|
26 |
return FileOverlayStatus.Unversioned;
|
|
25 | 27 |
|
26 | 28 |
var pithosPath = Settings.PithosPath; |
27 | 29 |
if (path.StartsWith(pithosPath,true,null)) |
... | ... | |
29 | 31 |
var status = _overlayCache[path]; |
30 | 32 |
return status; |
31 | 33 |
} |
32 |
return FileOverlayStatus.NA; |
|
34 |
return FileOverlayStatus.Unversioned; |
|
35 |
} |
|
36 |
|
|
37 |
public IEnumerable<string> StoreUnversionedFiles(ParallelQuery<string> paths) |
|
38 |
{ |
|
39 |
|
|
40 |
var newFiles = (from file in paths |
|
41 |
where !_overlayCache.ContainsKey(file) |
|
42 |
select new { |
|
43 |
FilePath = file, |
|
44 |
OverlayStatus = FileOverlayStatus.Unversioned, |
|
45 |
FileStatus = FileStatus.Created, |
|
46 |
Checksum = Signature.CalculateHash(file) |
|
47 |
}); |
|
48 |
ConcurrentBag<string> files = new ConcurrentBag<string>(); |
|
49 |
newFiles.ForAll(state => |
|
50 |
{ |
|
51 |
_overlayCache[state.FilePath] = state.OverlayStatus; |
|
52 |
_statusCache[state.FilePath] = state.FileStatus; |
|
53 |
_checksums[state.FilePath] = state.Checksum; |
|
54 |
files.Add(state.FilePath); |
|
55 |
}); |
|
56 |
return files.GetConsumingEnumerable(); |
|
33 | 57 |
} |
34 | 58 |
|
35 | 59 |
|
... | ... | |
51 | 75 |
|
52 | 76 |
public void RemoveFileOverlayStatus(string path) |
53 | 77 |
{ |
54 |
_overlayCache.Remove(path); |
|
78 |
FileOverlayStatus value; |
|
79 |
_overlayCache.TryRemove(path, out value); |
|
55 | 80 |
} |
56 | 81 |
|
57 | 82 |
public void RenameFileOverlayStatus(string oldPath, string newPath) |
58 | 83 |
{ |
59 | 84 |
var status=_overlayCache[oldPath]; |
60 |
_overlayCache[newPath] = status; |
|
61 |
_overlayCache.Remove(oldPath); |
|
85 |
_overlayCache[newPath] = status; |
|
86 |
FileOverlayStatus value; |
|
87 |
_overlayCache.TryRemove(oldPath,out value); |
|
62 | 88 |
} |
63 | 89 |
|
64 | 90 |
public void SetFileStatus(string path, FileStatus status) |
... | ... | |
75 | 101 |
|
76 | 102 |
public void ClearFileStatus(string path) |
77 | 103 |
{ |
78 |
_statusCache.Remove(path); |
|
104 |
FileStatus value; |
|
105 |
_statusCache.TryRemove(path,out value); |
|
79 | 106 |
} |
80 | 107 |
|
81 | 108 |
public void UpdateFileChecksum(string path, string checksum) |
Also available in: Unified diff