root / trunk / Pithos.Core / Agents / FileAgent.cs @ 79f92570
History | View | Annotate | Download (21.7 kB)
1 | 255f5f86 | Panagiotis Kanavos | #region |
---|---|---|---|
2 | 255f5f86 | Panagiotis Kanavos | /* ----------------------------------------------------------------------- |
3 | 255f5f86 | Panagiotis Kanavos | * <copyright file="FileAgent.cs" company="GRNet"> |
4 | 255f5f86 | Panagiotis Kanavos | * |
5 | 255f5f86 | Panagiotis Kanavos | * Copyright 2011-2012 GRNET S.A. All rights reserved. |
6 | 255f5f86 | Panagiotis Kanavos | * |
7 | 255f5f86 | Panagiotis Kanavos | * Redistribution and use in source and binary forms, with or |
8 | 255f5f86 | Panagiotis Kanavos | * without modification, are permitted provided that the following |
9 | 255f5f86 | Panagiotis Kanavos | * conditions are met: |
10 | 255f5f86 | Panagiotis Kanavos | * |
11 | 255f5f86 | Panagiotis Kanavos | * 1. Redistributions of source code must retain the above |
12 | 255f5f86 | Panagiotis Kanavos | * copyright notice, this list of conditions and the following |
13 | 255f5f86 | Panagiotis Kanavos | * disclaimer. |
14 | 255f5f86 | Panagiotis Kanavos | * |
15 | 255f5f86 | Panagiotis Kanavos | * 2. Redistributions in binary form must reproduce the above |
16 | 255f5f86 | Panagiotis Kanavos | * copyright notice, this list of conditions and the following |
17 | 255f5f86 | Panagiotis Kanavos | * disclaimer in the documentation and/or other materials |
18 | 255f5f86 | Panagiotis Kanavos | * provided with the distribution. |
19 | 255f5f86 | Panagiotis Kanavos | * |
20 | 255f5f86 | Panagiotis Kanavos | * |
21 | 255f5f86 | Panagiotis Kanavos | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
22 | 255f5f86 | Panagiotis Kanavos | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
23 | 255f5f86 | Panagiotis Kanavos | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
24 | 255f5f86 | Panagiotis Kanavos | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
25 | 255f5f86 | Panagiotis Kanavos | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
26 | 255f5f86 | Panagiotis Kanavos | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
27 | 255f5f86 | Panagiotis Kanavos | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
28 | 255f5f86 | Panagiotis Kanavos | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
29 | 255f5f86 | Panagiotis Kanavos | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | 255f5f86 | Panagiotis Kanavos | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
31 | 255f5f86 | Panagiotis Kanavos | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 | 255f5f86 | Panagiotis Kanavos | * POSSIBILITY OF SUCH DAMAGE. |
33 | 255f5f86 | Panagiotis Kanavos | * |
34 | 255f5f86 | Panagiotis Kanavos | * The views and conclusions contained in the software and |
35 | 255f5f86 | Panagiotis Kanavos | * documentation are those of the authors and should not be |
36 | 255f5f86 | Panagiotis Kanavos | * interpreted as representing official policies, either expressed |
37 | 255f5f86 | Panagiotis Kanavos | * or implied, of GRNET S.A. |
38 | 255f5f86 | Panagiotis Kanavos | * </copyright> |
39 | 255f5f86 | Panagiotis Kanavos | * ----------------------------------------------------------------------- |
40 | 255f5f86 | Panagiotis Kanavos | */ |
41 | 255f5f86 | Panagiotis Kanavos | #endregion |
42 | 255f5f86 | Panagiotis Kanavos | using System; |
43 | 9c4346c9 | Panagiotis Kanavos | using System.Collections.Generic; |
44 | bfc13ed8 | Panagiotis Kanavos | using System.Diagnostics.Contracts; |
45 | 9c4346c9 | Panagiotis Kanavos | using System.IO; |
46 | 9c4346c9 | Panagiotis Kanavos | using System.Linq; |
47 | db8a9589 | Panagiotis Kanavos | using System.Reflection; |
48 | a64c87c8 | Panagiotis Kanavos | using System.Threading.Tasks; |
49 | 9c4346c9 | Panagiotis Kanavos | using Pithos.Interfaces; |
50 | 1caef52e | Panagiotis Kanavos | using Pithos.Network; |
51 | 5120f3cb | Panagiotis Kanavos | using log4net; |
52 | 9c4346c9 | Panagiotis Kanavos | |
53 | 9c4346c9 | Panagiotis Kanavos | namespace Pithos.Core.Agents |
54 | 9c4346c9 | Panagiotis Kanavos | { |
55 | 4ec636f6 | Panagiotis Kanavos | // [Export] |
56 | 1caef52e | Panagiotis Kanavos | public class FileAgent |
57 | 9c4346c9 | Panagiotis Kanavos | { |
58 | db8a9589 | Panagiotis Kanavos | private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
59 | db8a9589 | Panagiotis Kanavos | |
60 | 4ec636f6 | Panagiotis Kanavos | Agent<WorkflowState> _agent; |
61 | 9c4346c9 | Panagiotis Kanavos | private FileSystemWatcher _watcher; |
62 | 78ebfd2d | Panagiotis Kanavos | private FileSystemWatcherAdapter _adapter; |
63 | 9c4346c9 | Panagiotis Kanavos | |
64 | 4ec636f6 | Panagiotis Kanavos | //[Import] |
65 | 9c4346c9 | Panagiotis Kanavos | public IStatusKeeper StatusKeeper { get; set; } |
66 | 174bbb6e | Panagiotis Kanavos | |
67 | 174bbb6e | Panagiotis Kanavos | public IStatusNotification StatusNotification { get; set; } |
68 | 4ec636f6 | Panagiotis Kanavos | //[Import] |
69 | 9c4346c9 | Panagiotis Kanavos | public IPithosWorkflow Workflow { get; set; } |
70 | 4ec636f6 | Panagiotis Kanavos | //[Import] |
71 | 9c4346c9 | Panagiotis Kanavos | public WorkflowAgent WorkflowAgent { get; set; } |
72 | 9c4346c9 | Panagiotis Kanavos | |
73 | c53aa229 | Panagiotis Kanavos | private AccountInfo AccountInfo { get; set; } |
74 | c53aa229 | Panagiotis Kanavos | |
75 | b666b39a | Panagiotis Kanavos | internal string RootPath { get; set; } |
76 | 79f92570 | Panagiotis Kanavos | |
77 | 79f92570 | Panagiotis Kanavos | private FileEventIdleBatch _eventIdleBatch; |
78 | 79f92570 | Panagiotis Kanavos | |
79 | 79f92570 | Panagiotis Kanavos | public FileAgent(int idleTimeout) |
80 | 79f92570 | Panagiotis Kanavos | { |
81 | 79f92570 | Panagiotis Kanavos | _eventIdleBatch=new FileEventIdleBatch(idleTimeout,ProcessBatchedEvents); |
82 | 79f92570 | Panagiotis Kanavos | } |
83 | 1caef52e | Panagiotis Kanavos | |
84 | 79f92570 | Panagiotis Kanavos | private void ProcessBatchedEvents(Dictionary<string, FileSystemEventArgs[]> fileEvents) |
85 | 79f92570 | Panagiotis Kanavos | { |
86 | 79f92570 | Panagiotis Kanavos | StatusNotification.SetPithosStatus(PithosStatus.LocalSyncing,String.Format("Uploading {0} files",fileEvents.Count)); |
87 | 79f92570 | Panagiotis Kanavos | foreach (var fileEvent in fileEvents) |
88 | 79f92570 | Panagiotis Kanavos | { |
89 | 79f92570 | Panagiotis Kanavos | var filePath = fileEvent.Key; |
90 | 79f92570 | Panagiotis Kanavos | var changes = fileEvent.Value; |
91 | 79f92570 | Panagiotis Kanavos | |
92 | 79f92570 | Panagiotis Kanavos | if (Ignore(filePath)) continue; |
93 | 79f92570 | Panagiotis Kanavos | |
94 | 79f92570 | Panagiotis Kanavos | foreach (var change in changes) |
95 | 79f92570 | Panagiotis Kanavos | { |
96 | 79f92570 | Panagiotis Kanavos | if (change.ChangeType == WatcherChangeTypes.Renamed) |
97 | 79f92570 | Panagiotis Kanavos | { |
98 | 79f92570 | Panagiotis Kanavos | var rename = (RenamedEventArgs) change; |
99 | 79f92570 | Panagiotis Kanavos | _agent.Post(new WorkflowState |
100 | 79f92570 | Panagiotis Kanavos | { |
101 | 79f92570 | Panagiotis Kanavos | AccountInfo = AccountInfo, |
102 | 79f92570 | Panagiotis Kanavos | OldPath = rename.OldFullPath, |
103 | 79f92570 | Panagiotis Kanavos | OldFileName = rename.OldName, |
104 | 79f92570 | Panagiotis Kanavos | Path = rename.FullPath, |
105 | 79f92570 | Panagiotis Kanavos | FileName = rename.Name, |
106 | 79f92570 | Panagiotis Kanavos | TriggeringChange = rename.ChangeType |
107 | 79f92570 | Panagiotis Kanavos | }); |
108 | 79f92570 | Panagiotis Kanavos | } |
109 | 79f92570 | Panagiotis Kanavos | else |
110 | 79f92570 | Panagiotis Kanavos | _agent.Post(new WorkflowState |
111 | 79f92570 | Panagiotis Kanavos | { |
112 | 79f92570 | Panagiotis Kanavos | AccountInfo = AccountInfo, |
113 | 79f92570 | Panagiotis Kanavos | Path = change.FullPath, |
114 | 79f92570 | Panagiotis Kanavos | FileName = change.Name, |
115 | 79f92570 | Panagiotis Kanavos | TriggeringChange = change.ChangeType |
116 | 79f92570 | Panagiotis Kanavos | }); |
117 | 79f92570 | Panagiotis Kanavos | } |
118 | 79f92570 | Panagiotis Kanavos | } |
119 | 79f92570 | Panagiotis Kanavos | StatusNotification.SetPithosStatus(PithosStatus.LocalComplete); |
120 | 79f92570 | Panagiotis Kanavos | } |
121 | cfed7823 | Panagiotis Kanavos | |
122 | 4ec636f6 | Panagiotis Kanavos | public void Start(AccountInfo accountInfo,string rootPath) |
123 | 9c4346c9 | Panagiotis Kanavos | { |
124 | 4ec636f6 | Panagiotis Kanavos | if (accountInfo==null) |
125 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentNullException("accountInfo"); |
126 | 4ec636f6 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(rootPath)) |
127 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentNullException("rootPath"); |
128 | 4ec636f6 | Panagiotis Kanavos | if (!Path.IsPathRooted(rootPath)) |
129 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentException("rootPath must be an absolute path","rootPath"); |
130 | 4ec636f6 | Panagiotis Kanavos | Contract.EndContractBlock(); |
131 | 4ec636f6 | Panagiotis Kanavos | |
132 | 4ec636f6 | Panagiotis Kanavos | AccountInfo = accountInfo; |
133 | 4ec636f6 | Panagiotis Kanavos | RootPath = rootPath; |
134 | 174bbb6e | Panagiotis Kanavos | _watcher = new FileSystemWatcher(rootPath) {IncludeSubdirectories = true,InternalBufferSize=8*4096}; |
135 | 78ebfd2d | Panagiotis Kanavos | _adapter = new FileSystemWatcherAdapter(_watcher); |
136 | 78ebfd2d | Panagiotis Kanavos | |
137 | 78ebfd2d | Panagiotis Kanavos | _adapter.Changed += OnFileEvent; |
138 | 78ebfd2d | Panagiotis Kanavos | _adapter.Created += OnFileEvent; |
139 | 78ebfd2d | Panagiotis Kanavos | _adapter.Deleted += OnFileEvent; |
140 | 174bbb6e | Panagiotis Kanavos | //_adapter.Renamed += OnRenameEvent; |
141 | 78ebfd2d | Panagiotis Kanavos | _adapter.Moved += OnMoveEvent; |
142 | 4ec636f6 | Panagiotis Kanavos | _watcher.EnableRaisingEvents = true; |
143 | 4ec636f6 | Panagiotis Kanavos | |
144 | 4ec636f6 | Panagiotis Kanavos | |
145 | 4ec636f6 | Panagiotis Kanavos | _agent = Agent<WorkflowState>.Start(inbox => |
146 | 4ec636f6 | Panagiotis Kanavos | { |
147 | 4ec636f6 | Panagiotis Kanavos | Action loop = null; |
148 | 4ec636f6 | Panagiotis Kanavos | loop = () => |
149 | 4ec636f6 | Panagiotis Kanavos | { |
150 | 4ec636f6 | Panagiotis Kanavos | var message = inbox.Receive(); |
151 | 139ac1e8 | Panagiotis Kanavos | var process=message.Then(Process,inbox.CancellationToken); |
152 | 4ec636f6 | Panagiotis Kanavos | inbox.LoopAsync(process,loop,ex=> |
153 | 4ec636f6 | Panagiotis Kanavos | Log.ErrorFormat("[ERROR] File Event Processing:\r{0}", ex)); |
154 | 4ec636f6 | Panagiotis Kanavos | }; |
155 | 4ec636f6 | Panagiotis Kanavos | loop(); |
156 | 4ec636f6 | Panagiotis Kanavos | }); |
157 | 9c4346c9 | Panagiotis Kanavos | } |
158 | 9c4346c9 | Panagiotis Kanavos | |
159 | 4ec636f6 | Panagiotis Kanavos | private Task<object> Process(WorkflowState state) |
160 | a64c87c8 | Panagiotis Kanavos | { |
161 | 4ec636f6 | Panagiotis Kanavos | if (state==null) |
162 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentNullException("state"); |
163 | 4ec636f6 | Panagiotis Kanavos | Contract.EndContractBlock(); |
164 | 4ec636f6 | Panagiotis Kanavos | |
165 | 4f6d51d4 | Panagiotis Kanavos | if (Ignore(state.Path)) |
166 | 4f6d51d4 | Panagiotis Kanavos | return CompletedTask<object>.Default; |
167 | 4ec636f6 | Panagiotis Kanavos | |
168 | 4ec636f6 | Panagiotis Kanavos | var networkState = NetworkGate.GetNetworkState(state.Path); |
169 | 4ec636f6 | Panagiotis Kanavos | //Skip if the file is already being downloaded or uploaded and |
170 | 4ec636f6 | Panagiotis Kanavos | //the change is create or modify |
171 | 4ec636f6 | Panagiotis Kanavos | if (networkState != NetworkOperation.None && |
172 | 4ec636f6 | Panagiotis Kanavos | ( |
173 | 4ec636f6 | Panagiotis Kanavos | state.TriggeringChange == WatcherChangeTypes.Created || |
174 | 4ec636f6 | Panagiotis Kanavos | state.TriggeringChange == WatcherChangeTypes.Changed |
175 | 4ec636f6 | Panagiotis Kanavos | )) |
176 | 4ec636f6 | Panagiotis Kanavos | return CompletedTask<object>.Default; |
177 | a64c87c8 | Panagiotis Kanavos | |
178 | a64c87c8 | Panagiotis Kanavos | try |
179 | a64c87c8 | Panagiotis Kanavos | { |
180 | 174bbb6e | Panagiotis Kanavos | //StatusKeeper.EnsureFileState(state.Path); |
181 | 174bbb6e | Panagiotis Kanavos | |
182 | 4ec636f6 | Panagiotis Kanavos | UpdateFileStatus(state); |
183 | 4ec636f6 | Panagiotis Kanavos | UpdateOverlayStatus(state); |
184 | 4ec636f6 | Panagiotis Kanavos | UpdateFileChecksum(state); |
185 | 4ec636f6 | Panagiotis Kanavos | WorkflowAgent.Post(state); |
186 | a64c87c8 | Panagiotis Kanavos | } |
187 | a64c87c8 | Panagiotis Kanavos | catch (IOException exc) |
188 | a64c87c8 | Panagiotis Kanavos | { |
189 | 4ec636f6 | Panagiotis Kanavos | if (File.Exists(state.Path)) |
190 | 0af3141d | Panagiotis Kanavos | { |
191 | 4ec636f6 | Panagiotis Kanavos | Log.WarnFormat("File access error occured, retrying {0}\n{1}", state.Path, exc); |
192 | 4ec636f6 | Panagiotis Kanavos | _agent.Post(state); |
193 | 0af3141d | Panagiotis Kanavos | } |
194 | 0af3141d | Panagiotis Kanavos | else |
195 | 0af3141d | Panagiotis Kanavos | { |
196 | 4ec636f6 | Panagiotis Kanavos | Log.WarnFormat("File {0} does not exist. Will be ignored\n{1}", state.Path, exc); |
197 | 0af3141d | Panagiotis Kanavos | } |
198 | a64c87c8 | Panagiotis Kanavos | } |
199 | a64c87c8 | Panagiotis Kanavos | catch (Exception exc) |
200 | a64c87c8 | Panagiotis Kanavos | { |
201 | 4ec636f6 | Panagiotis Kanavos | Log.WarnFormat("Error occured while indexing{0}. The file will be skipped\n{1}", |
202 | 4ec636f6 | Panagiotis Kanavos | state.Path, exc); |
203 | a64c87c8 | Panagiotis Kanavos | } |
204 | 4ec636f6 | Panagiotis Kanavos | return CompletedTask<object>.Default; |
205 | 5e31048f | Panagiotis Kanavos | } |
206 | a64c87c8 | Panagiotis Kanavos | |
207 | 9c4346c9 | Panagiotis Kanavos | public bool Pause |
208 | 9c4346c9 | Panagiotis Kanavos | { |
209 | 9c4346c9 | Panagiotis Kanavos | get { return _watcher == null || !_watcher.EnableRaisingEvents; } |
210 | 9c4346c9 | Panagiotis Kanavos | set |
211 | 9c4346c9 | Panagiotis Kanavos | { |
212 | 9c4346c9 | Panagiotis Kanavos | if (_watcher != null) |
213 | 9c4346c9 | Panagiotis Kanavos | _watcher.EnableRaisingEvents = !value; |
214 | 9c4346c9 | Panagiotis Kanavos | } |
215 | 9c4346c9 | Panagiotis Kanavos | } |
216 | 9c4346c9 | Panagiotis Kanavos | |
217 | 77e10b4f | Panagiotis Kanavos | public string CachePath { get; set; } |
218 | 1caef52e | Panagiotis Kanavos | |
219 | d3a13891 | Panagiotis Kanavos | private List<string> _selectivePaths = new List<string>(); |
220 | d3a13891 | Panagiotis Kanavos | public List<string> SelectivePaths |
221 | d3a13891 | Panagiotis Kanavos | { |
222 | d3a13891 | Panagiotis Kanavos | get { return _selectivePaths; } |
223 | d3a13891 | Panagiotis Kanavos | set { _selectivePaths = value; } |
224 | d3a13891 | Panagiotis Kanavos | } |
225 | d3a13891 | Panagiotis Kanavos | |
226 | d3a13891 | Panagiotis Kanavos | |
227 | 9c4346c9 | Panagiotis Kanavos | public void Post(WorkflowState workflowState) |
228 | 9c4346c9 | Panagiotis Kanavos | { |
229 | cfed7823 | Panagiotis Kanavos | if (workflowState == null) |
230 | cfed7823 | Panagiotis Kanavos | throw new ArgumentNullException("workflowState"); |
231 | cfed7823 | Panagiotis Kanavos | Contract.EndContractBlock(); |
232 | cfed7823 | Panagiotis Kanavos | |
233 | 9c4346c9 | Panagiotis Kanavos | _agent.Post(workflowState); |
234 | 9c4346c9 | Panagiotis Kanavos | } |
235 | 9c4346c9 | Panagiotis Kanavos | |
236 | 9c4346c9 | Panagiotis Kanavos | public void Stop() |
237 | 9c4346c9 | Panagiotis Kanavos | { |
238 | 9c4346c9 | Panagiotis Kanavos | if (_watcher != null) |
239 | 9c4346c9 | Panagiotis Kanavos | { |
240 | 9c4346c9 | Panagiotis Kanavos | _watcher.Dispose(); |
241 | 9c4346c9 | Panagiotis Kanavos | } |
242 | 9c4346c9 | Panagiotis Kanavos | _watcher = null; |
243 | 9c4346c9 | Panagiotis Kanavos | |
244 | cfed7823 | Panagiotis Kanavos | if (_agent!=null) |
245 | 4ec636f6 | Panagiotis Kanavos | _agent.Stop(); |
246 | 9c4346c9 | Panagiotis Kanavos | } |
247 | 9c4346c9 | Panagiotis Kanavos | |
248 | 1caef52e | Panagiotis Kanavos | // Enumerate all files in the Pithos directory except those in the Fragment folder |
249 | 1caef52e | Panagiotis Kanavos | // and files with a .ignore extension |
250 | 1caef52e | Panagiotis Kanavos | public IEnumerable<string> EnumerateFiles(string searchPattern="*") |
251 | 1caef52e | Panagiotis Kanavos | { |
252 | 1caef52e | Panagiotis Kanavos | var monitoredFiles = from filePath in Directory.EnumerateFileSystemEntries(RootPath, searchPattern, SearchOption.AllDirectories) |
253 | 1caef52e | Panagiotis Kanavos | where !Ignore(filePath) |
254 | 1caef52e | Panagiotis Kanavos | select filePath; |
255 | 1caef52e | Panagiotis Kanavos | return monitoredFiles; |
256 | 1caef52e | Panagiotis Kanavos | } |
257 | 1caef52e | Panagiotis Kanavos | |
258 | 1caef52e | Panagiotis Kanavos | public IEnumerable<FileInfo> EnumerateFileInfos(string searchPattern="*") |
259 | 1caef52e | Panagiotis Kanavos | { |
260 | 1caef52e | Panagiotis Kanavos | var rootDir = new DirectoryInfo(RootPath); |
261 | 1caef52e | Panagiotis Kanavos | var monitoredFiles = from file in rootDir.EnumerateFiles(searchPattern, SearchOption.AllDirectories) |
262 | 1caef52e | Panagiotis Kanavos | where !Ignore(file.FullName) |
263 | 1caef52e | Panagiotis Kanavos | select file; |
264 | 1caef52e | Panagiotis Kanavos | return monitoredFiles; |
265 | 1caef52e | Panagiotis Kanavos | } |
266 | 1caef52e | Panagiotis Kanavos | |
267 | 1caef52e | Panagiotis Kanavos | public IEnumerable<string> EnumerateFilesAsRelativeUrls(string searchPattern="*") |
268 | 1caef52e | Panagiotis Kanavos | { |
269 | 1caef52e | Panagiotis Kanavos | var rootDir = new DirectoryInfo(RootPath); |
270 | 1caef52e | Panagiotis Kanavos | var monitoredFiles = from file in rootDir.EnumerateFiles(searchPattern, SearchOption.AllDirectories) |
271 | 1caef52e | Panagiotis Kanavos | where !Ignore(file.FullName) |
272 | 1caef52e | Panagiotis Kanavos | select file.AsRelativeUrlTo(RootPath); |
273 | 1caef52e | Panagiotis Kanavos | return monitoredFiles; |
274 | 1caef52e | Panagiotis Kanavos | } |
275 | 1caef52e | Panagiotis Kanavos | |
276 | 540b8cf8 | Panagiotis Kanavos | public IEnumerable<string> EnumerateFilesSystemInfosAsRelativeUrls(string searchPattern="*") |
277 | 540b8cf8 | Panagiotis Kanavos | { |
278 | 540b8cf8 | Panagiotis Kanavos | var rootDir = new DirectoryInfo(RootPath); |
279 | 540b8cf8 | Panagiotis Kanavos | var monitoredFiles = from file in rootDir.EnumerateFileSystemInfos(searchPattern, SearchOption.AllDirectories) |
280 | 540b8cf8 | Panagiotis Kanavos | where !Ignore(file.FullName) |
281 | 540b8cf8 | Panagiotis Kanavos | select file.AsRelativeUrlTo(RootPath); |
282 | 540b8cf8 | Panagiotis Kanavos | return monitoredFiles; |
283 | 540b8cf8 | Panagiotis Kanavos | } |
284 | 540b8cf8 | Panagiotis Kanavos | |
285 | 1caef52e | Panagiotis Kanavos | |
286 | 1caef52e | Panagiotis Kanavos | |
287 | 1caef52e | Panagiotis Kanavos | |
288 | 1caef52e | Panagiotis Kanavos | private bool Ignore(string filePath) |
289 | 1caef52e | Panagiotis Kanavos | { |
290 | 139ac1e8 | Panagiotis Kanavos | //Ignore all first-level directories and files (ie at the container folders level) |
291 | d9b1cbeb | Panagiotis Kanavos | if (FoundBelowRoot(filePath, RootPath,1)) |
292 | 139ac1e8 | Panagiotis Kanavos | return true; |
293 | d9b1cbeb | Panagiotis Kanavos | |
294 | 139ac1e8 | Panagiotis Kanavos | //Ignore first-level items under the "others" folder (ie at the accounts folders level). |
295 | d9b1cbeb | Panagiotis Kanavos | var othersPath = Path.Combine(RootPath, FolderConstants.OthersFolder); |
296 | d9b1cbeb | Panagiotis Kanavos | if (FoundBelowRoot(filePath, othersPath,1)) |
297 | 139ac1e8 | Panagiotis Kanavos | return true; |
298 | d9b1cbeb | Panagiotis Kanavos | |
299 | 139ac1e8 | Panagiotis Kanavos | //Ignore second-level (container) folders under the "others" folder (ie at the container folders level). |
300 | d9b1cbeb | Panagiotis Kanavos | if (FoundBelowRoot(filePath, othersPath,2)) |
301 | d9b1cbeb | Panagiotis Kanavos | return true; |
302 | d9b1cbeb | Panagiotis Kanavos | |
303 | d9b1cbeb | Panagiotis Kanavos | |
304 | d9b1cbeb | Panagiotis Kanavos | //Ignore anything happening in the cache path |
305 | 77e10b4f | Panagiotis Kanavos | if (filePath.StartsWith(CachePath)) |
306 | 1caef52e | Panagiotis Kanavos | return true; |
307 | 0af3141d | Panagiotis Kanavos | if (_ignoreFiles.ContainsKey(filePath.ToLower())) |
308 | 0af3141d | Panagiotis Kanavos | return true; |
309 | 139ac1e8 | Panagiotis Kanavos | |
310 | fec5da06 | Panagiotis Kanavos | //Ignore if selective synchronization is defined, |
311 | fec5da06 | Panagiotis Kanavos | return SelectivePaths.Count > 0 |
312 | fec5da06 | Panagiotis Kanavos | //And the target file is not below any of the selective paths |
313 | fec5da06 | Panagiotis Kanavos | && !SelectivePaths.Any(filePath.IsAtOrDirectlyBelow); |
314 | 1caef52e | Panagiotis Kanavos | } |
315 | 1caef52e | Panagiotis Kanavos | |
316 | d9b1cbeb | Panagiotis Kanavos | /* private static bool FoundInRoot(string filePath, string rootPath) |
317 | d9b1cbeb | Panagiotis Kanavos | { |
318 | d9b1cbeb | Panagiotis Kanavos | //var rootDirectory = new DirectoryInfo(rootPath); |
319 | d9b1cbeb | Panagiotis Kanavos | |
320 | d9b1cbeb | Panagiotis Kanavos | //If the paths are equal, return true |
321 | d9b1cbeb | Panagiotis Kanavos | if (filePath.Equals(rootPath, StringComparison.InvariantCultureIgnoreCase)) |
322 | d9b1cbeb | Panagiotis Kanavos | return true; |
323 | d9b1cbeb | Panagiotis Kanavos | |
324 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is below the root path |
325 | d9b1cbeb | Panagiotis Kanavos | if (filePath.StartsWith(rootPath,StringComparison.InvariantCulture)) |
326 | d9b1cbeb | Panagiotis Kanavos | { |
327 | d9b1cbeb | Panagiotis Kanavos | //Get the relative path |
328 | d9b1cbeb | Panagiotis Kanavos | var relativePath = filePath.Substring(rootPath.Length + 1); |
329 | d9b1cbeb | Panagiotis Kanavos | //If the relativePath does NOT contains a path separator, we found a match |
330 | d9b1cbeb | Panagiotis Kanavos | return (!relativePath.Contains(@"\")); |
331 | d9b1cbeb | Panagiotis Kanavos | } |
332 | d9b1cbeb | Panagiotis Kanavos | |
333 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is not under the root path, return false |
334 | d9b1cbeb | Panagiotis Kanavos | return false; |
335 | d9b1cbeb | Panagiotis Kanavos | }*/ |
336 | d9b1cbeb | Panagiotis Kanavos | |
337 | d9b1cbeb | Panagiotis Kanavos | |
338 | d9b1cbeb | Panagiotis Kanavos | private static bool FoundBelowRoot(string filePath, string rootPath,int level) |
339 | d9b1cbeb | Panagiotis Kanavos | { |
340 | d9b1cbeb | Panagiotis Kanavos | //var rootDirectory = new DirectoryInfo(rootPath); |
341 | d9b1cbeb | Panagiotis Kanavos | |
342 | d9b1cbeb | Panagiotis Kanavos | //If the paths are equal, return true |
343 | d9b1cbeb | Panagiotis Kanavos | if (filePath.Equals(rootPath, StringComparison.InvariantCultureIgnoreCase)) |
344 | d9b1cbeb | Panagiotis Kanavos | return true; |
345 | d9b1cbeb | Panagiotis Kanavos | |
346 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is below the root path |
347 | d9b1cbeb | Panagiotis Kanavos | if (filePath.StartsWith(rootPath,StringComparison.InvariantCulture)) |
348 | d9b1cbeb | Panagiotis Kanavos | { |
349 | d9b1cbeb | Panagiotis Kanavos | //Get the relative path |
350 | d9b1cbeb | Panagiotis Kanavos | var relativePath = filePath.Substring(rootPath.Length + 1); |
351 | d9b1cbeb | Panagiotis Kanavos | //If the relativePath does NOT contains a path separator, we found a match |
352 | d9b1cbeb | Panagiotis Kanavos | var levels=relativePath.ToCharArray().Count(c=>c=='\\')+1; |
353 | d9b1cbeb | Panagiotis Kanavos | return levels==level; |
354 | d9b1cbeb | Panagiotis Kanavos | } |
355 | d9b1cbeb | Panagiotis Kanavos | |
356 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is not under the root path, return false |
357 | d9b1cbeb | Panagiotis Kanavos | return false; |
358 | d9b1cbeb | Panagiotis Kanavos | } |
359 | d9b1cbeb | Panagiotis Kanavos | |
360 | 1caef52e | Panagiotis Kanavos | //Post a Change message for all events except rename |
361 | 9c4346c9 | Panagiotis Kanavos | void OnFileEvent(object sender, FileSystemEventArgs e) |
362 | 9c4346c9 | Panagiotis Kanavos | { |
363 | 77e10b4f | Panagiotis Kanavos | //Ignore events that affect the cache folder |
364 | 1caef52e | Panagiotis Kanavos | var filePath = e.FullPath; |
365 | 1caef52e | Panagiotis Kanavos | if (Ignore(filePath)) |
366 | a0dcfcc9 | Panagiotis Kanavos | return; |
367 | 79f92570 | Panagiotis Kanavos | _eventIdleBatch.Post(e); |
368 | 9c4346c9 | Panagiotis Kanavos | } |
369 | 9c4346c9 | Panagiotis Kanavos | |
370 | 1caef52e | Panagiotis Kanavos | |
371 | 174bbb6e | Panagiotis Kanavos | /* |
372 | 1caef52e | Panagiotis Kanavos | //Post a Change message for renames containing the old and new names |
373 | 9c4346c9 | Panagiotis Kanavos | void OnRenameEvent(object sender, RenamedEventArgs e) |
374 | 9c4346c9 | Panagiotis Kanavos | { |
375 | 1caef52e | Panagiotis Kanavos | var oldFullPath = e.OldFullPath; |
376 | 1caef52e | Panagiotis Kanavos | var fullPath = e.FullPath; |
377 | 1caef52e | Panagiotis Kanavos | if (Ignore(oldFullPath) || Ignore(fullPath)) |
378 | 1caef52e | Panagiotis Kanavos | return; |
379 | 1caef52e | Panagiotis Kanavos | |
380 | 1bfc38f1 | Panagiotis Kanavos | _agent.Post(new WorkflowState |
381 | 9c4346c9 | Panagiotis Kanavos | { |
382 | 1bfc38f1 | Panagiotis Kanavos | AccountInfo=AccountInfo, |
383 | 1caef52e | Panagiotis Kanavos | OldPath = oldFullPath, |
384 | 9c4346c9 | Panagiotis Kanavos | OldFileName = e.OldName, |
385 | 1caef52e | Panagiotis Kanavos | Path = fullPath, |
386 | 9c4346c9 | Panagiotis Kanavos | FileName = e.Name, |
387 | 78ebfd2d | Panagiotis Kanavos | TriggeringChange = e.ChangeType |
388 | 78ebfd2d | Panagiotis Kanavos | }); |
389 | 78ebfd2d | Panagiotis Kanavos | } |
390 | 174bbb6e | Panagiotis Kanavos | */ |
391 | 78ebfd2d | Panagiotis Kanavos | |
392 | 174bbb6e | Panagiotis Kanavos | //Post a Change message for moves containing the old and new names |
393 | 78ebfd2d | Panagiotis Kanavos | void OnMoveEvent(object sender, MovedEventArgs e) |
394 | 78ebfd2d | Panagiotis Kanavos | { |
395 | 78ebfd2d | Panagiotis Kanavos | var oldFullPath = e.OldFullPath; |
396 | 78ebfd2d | Panagiotis Kanavos | var fullPath = e.FullPath; |
397 | 78ebfd2d | Panagiotis Kanavos | if (Ignore(oldFullPath) || Ignore(fullPath)) |
398 | 78ebfd2d | Panagiotis Kanavos | return; |
399 | 78ebfd2d | Panagiotis Kanavos | |
400 | 79f92570 | Panagiotis Kanavos | _eventIdleBatch.Post(e); |
401 | 9c4346c9 | Panagiotis Kanavos | } |
402 | 9c4346c9 | Panagiotis Kanavos | |
403 | 9c4346c9 | Panagiotis Kanavos | |
404 | 9c4346c9 | Panagiotis Kanavos | |
405 | 9c4346c9 | Panagiotis Kanavos | private Dictionary<WatcherChangeTypes, FileStatus> _statusDict = new Dictionary<WatcherChangeTypes, FileStatus> |
406 | fbbbe99b | Panagiotis Kanavos | { |
407 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Created,FileStatus.Created}, |
408 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Changed,FileStatus.Modified}, |
409 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Deleted,FileStatus.Deleted}, |
410 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Renamed,FileStatus.Renamed} |
411 | 9c4346c9 | Panagiotis Kanavos | }; |
412 | 9c4346c9 | Panagiotis Kanavos | |
413 | fbbbe99b | Panagiotis Kanavos | private Dictionary<string, string> _ignoreFiles=new Dictionary<string, string>(); |
414 | 0af3141d | Panagiotis Kanavos | |
415 | 9c4346c9 | Panagiotis Kanavos | private WorkflowState UpdateFileStatus(WorkflowState state) |
416 | 9c4346c9 | Panagiotis Kanavos | { |
417 | cfed7823 | Panagiotis Kanavos | if (state==null) |
418 | cfed7823 | Panagiotis Kanavos | throw new ArgumentNullException("state"); |
419 | cfed7823 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(state.Path)) |
420 | cfed7823 | Panagiotis Kanavos | throw new ArgumentException("The state's Path can't be empty","state"); |
421 | cfed7823 | Panagiotis Kanavos | Contract.EndContractBlock(); |
422 | 1caef52e | Panagiotis Kanavos | |
423 | cfed7823 | Panagiotis Kanavos | var path = state.Path; |
424 | cfed7823 | Panagiotis Kanavos | var status = _statusDict[state.TriggeringChange]; |
425 | 9c4346c9 | Panagiotis Kanavos | var oldStatus = Workflow.StatusKeeper.GetFileStatus(path); |
426 | 9c4346c9 | Panagiotis Kanavos | if (status == oldStatus) |
427 | 9c4346c9 | Panagiotis Kanavos | { |
428 | 9c4346c9 | Panagiotis Kanavos | state.Status = status; |
429 | 9c4346c9 | Panagiotis Kanavos | state.Skip = true; |
430 | 9c4346c9 | Panagiotis Kanavos | return state; |
431 | 9c4346c9 | Panagiotis Kanavos | } |
432 | 9c4346c9 | Panagiotis Kanavos | if (state.Status == FileStatus.Renamed) |
433 | 9c4346c9 | Panagiotis Kanavos | Workflow.ClearFileStatus(path); |
434 | 9c4346c9 | Panagiotis Kanavos | |
435 | 9c4346c9 | Panagiotis Kanavos | state.Status = Workflow.SetFileStatus(path, status); |
436 | 9c4346c9 | Panagiotis Kanavos | return state; |
437 | 9c4346c9 | Panagiotis Kanavos | } |
438 | 9c4346c9 | Panagiotis Kanavos | |
439 | 9c4346c9 | Panagiotis Kanavos | private WorkflowState UpdateOverlayStatus(WorkflowState state) |
440 | 9c4346c9 | Panagiotis Kanavos | { |
441 | cfed7823 | Panagiotis Kanavos | if (state==null) |
442 | cfed7823 | Panagiotis Kanavos | throw new ArgumentNullException("state"); |
443 | cfed7823 | Panagiotis Kanavos | Contract.EndContractBlock(); |
444 | cfed7823 | Panagiotis Kanavos | |
445 | 9c4346c9 | Panagiotis Kanavos | if (state.Skip) |
446 | 9c4346c9 | Panagiotis Kanavos | return state; |
447 | 9c4346c9 | Panagiotis Kanavos | |
448 | 9c4346c9 | Panagiotis Kanavos | switch (state.Status) |
449 | 9c4346c9 | Panagiotis Kanavos | { |
450 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Created: |
451 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash); |
452 | 174bbb6e | Panagiotis Kanavos | break; |
453 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Modified: |
454 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash); |
455 | 9c4346c9 | Panagiotis Kanavos | break; |
456 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Deleted: |
457 | cfed7823 | Panagiotis Kanavos | //this.StatusAgent.RemoveFileOverlayStatus(state.Path); |
458 | 9c4346c9 | Panagiotis Kanavos | break; |
459 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Renamed: |
460 | cfed7823 | Panagiotis Kanavos | this.StatusKeeper.ClearFileStatus(state.OldPath); |
461 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash); |
462 | 9c4346c9 | Panagiotis Kanavos | break; |
463 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Unchanged: |
464 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Normal,state.ShortHash); |
465 | 9c4346c9 | Panagiotis Kanavos | break; |
466 | 9c4346c9 | Panagiotis Kanavos | } |
467 | 9c4346c9 | Panagiotis Kanavos | |
468 | 9c4346c9 | Panagiotis Kanavos | if (state.Status == FileStatus.Deleted) |
469 | 1caef52e | Panagiotis Kanavos | NativeMethods.RaiseChangeNotification(Path.GetDirectoryName(state.Path)); |
470 | 9c4346c9 | Panagiotis Kanavos | else |
471 | 1caef52e | Panagiotis Kanavos | NativeMethods.RaiseChangeNotification(state.Path); |
472 | 9c4346c9 | Panagiotis Kanavos | return state; |
473 | 9c4346c9 | Panagiotis Kanavos | } |
474 | 9c4346c9 | Panagiotis Kanavos | |
475 | 9c4346c9 | Panagiotis Kanavos | |
476 | 9c4346c9 | Panagiotis Kanavos | private WorkflowState UpdateFileChecksum(WorkflowState state) |
477 | 9c4346c9 | Panagiotis Kanavos | { |
478 | 9c4346c9 | Panagiotis Kanavos | if (state.Skip) |
479 | 9c4346c9 | Panagiotis Kanavos | return state; |
480 | 9c4346c9 | Panagiotis Kanavos | |
481 | 9c4346c9 | Panagiotis Kanavos | if (state.Status == FileStatus.Deleted) |
482 | 9c4346c9 | Panagiotis Kanavos | return state; |
483 | 9c4346c9 | Panagiotis Kanavos | |
484 | 1caef52e | Panagiotis Kanavos | var path = state.Path; |
485 | 1caef52e | Panagiotis Kanavos | //Skip calculation for folders |
486 | 1caef52e | Panagiotis Kanavos | if (Directory.Exists(path)) |
487 | 1caef52e | Panagiotis Kanavos | return state; |
488 | 1caef52e | Panagiotis Kanavos | |
489 | 174bbb6e | Panagiotis Kanavos | |
490 | 0af3141d | Panagiotis Kanavos | var info = new FileInfo(path); |
491 | 174bbb6e | Panagiotis Kanavos | StatusNotification.Notify(new StatusNotification(String.Format("Hashing [{0}]",info.Name))); |
492 | 174bbb6e | Panagiotis Kanavos | |
493 | 174bbb6e | Panagiotis Kanavos | var shortHash = info.ComputeShortHash(); |
494 | 174bbb6e | Panagiotis Kanavos | |
495 | 174bbb6e | Panagiotis Kanavos | string merkleHash = info.CalculateHash(StatusKeeper.BlockSize,StatusKeeper.BlockHash); |
496 | 174bbb6e | Panagiotis Kanavos | StatusKeeper.UpdateFileChecksum(path,shortHash, merkleHash); |
497 | 9c4346c9 | Panagiotis Kanavos | |
498 | 174bbb6e | Panagiotis Kanavos | state.Hash = merkleHash; |
499 | 9c4346c9 | Panagiotis Kanavos | return state; |
500 | 9c4346c9 | Panagiotis Kanavos | } |
501 | 9c4346c9 | Panagiotis Kanavos | |
502 | bfc13ed8 | Panagiotis Kanavos | //Does the file exist in the container's local folder? |
503 | bfc13ed8 | Panagiotis Kanavos | public bool Exists(string relativePath) |
504 | bfc13ed8 | Panagiotis Kanavos | { |
505 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(relativePath)) |
506 | bfc13ed8 | Panagiotis Kanavos | throw new ArgumentNullException("relativePath"); |
507 | bfc13ed8 | Panagiotis Kanavos | //A RootPath must be set before calling this method |
508 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(RootPath)) |
509 | bfc13ed8 | Panagiotis Kanavos | throw new InvalidOperationException("RootPath was not set"); |
510 | bfc13ed8 | Panagiotis Kanavos | Contract.EndContractBlock(); |
511 | bfc13ed8 | Panagiotis Kanavos | //Create the absolute path by combining the RootPath with the relativePath |
512 | bfc13ed8 | Panagiotis Kanavos | var absolutePath=Path.Combine(RootPath, relativePath); |
513 | bfc13ed8 | Panagiotis Kanavos | //Is this a valid file? |
514 | bfc13ed8 | Panagiotis Kanavos | if (File.Exists(absolutePath)) |
515 | bfc13ed8 | Panagiotis Kanavos | return true; |
516 | bfc13ed8 | Panagiotis Kanavos | //Or a directory? |
517 | a64c87c8 | Panagiotis Kanavos | if (Directory.Exists(absolutePath)) |
518 | bfc13ed8 | Panagiotis Kanavos | return true; |
519 | bfc13ed8 | Panagiotis Kanavos | //Fail if it is neither |
520 | bfc13ed8 | Panagiotis Kanavos | return false; |
521 | bfc13ed8 | Panagiotis Kanavos | } |
522 | 9c4346c9 | Panagiotis Kanavos | |
523 | fbbbe99b | Panagiotis Kanavos | public static FileAgent GetFileAgent(AccountInfo accountInfo) |
524 | fbbbe99b | Panagiotis Kanavos | { |
525 | fbbbe99b | Panagiotis Kanavos | return GetFileAgent(accountInfo.AccountPath); |
526 | fbbbe99b | Panagiotis Kanavos | } |
527 | fbbbe99b | Panagiotis Kanavos | |
528 | fbbbe99b | Panagiotis Kanavos | public static FileAgent GetFileAgent(string rootPath) |
529 | fbbbe99b | Panagiotis Kanavos | { |
530 | fbbbe99b | Panagiotis Kanavos | return AgentLocator<FileAgent>.Get(rootPath.ToLower()); |
531 | fbbbe99b | Panagiotis Kanavos | } |
532 | fbbbe99b | Panagiotis Kanavos | |
533 | fbbbe99b | Panagiotis Kanavos | |
534 | f3d080df | Panagiotis Kanavos | public FileSystemInfo GetFileSystemInfo(string relativePath) |
535 | bfc13ed8 | Panagiotis Kanavos | { |
536 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(relativePath)) |
537 | bfc13ed8 | Panagiotis Kanavos | throw new ArgumentNullException("relativePath"); |
538 | bfc13ed8 | Panagiotis Kanavos | //A RootPath must be set before calling this method |
539 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(RootPath)) |
540 | bfc13ed8 | Panagiotis Kanavos | throw new InvalidOperationException("RootPath was not set"); |
541 | bfc13ed8 | Panagiotis Kanavos | Contract.EndContractBlock(); |
542 | bfc13ed8 | Panagiotis Kanavos | |
543 | bfc13ed8 | Panagiotis Kanavos | var absolutePath = Path.Combine(RootPath, relativePath); |
544 | bfc13ed8 | Panagiotis Kanavos | |
545 | 4f6d51d4 | Panagiotis Kanavos | if (Directory.Exists(absolutePath)) |
546 | f3d080df | Panagiotis Kanavos | return new DirectoryInfo(absolutePath).WithProperCapitalization(); |
547 | 4f6d51d4 | Panagiotis Kanavos | else |
548 | f3d080df | Panagiotis Kanavos | return new FileInfo(absolutePath).WithProperCapitalization(); |
549 | bfc13ed8 | Panagiotis Kanavos | |
550 | bfc13ed8 | Panagiotis Kanavos | } |
551 | a27aa447 | Panagiotis Kanavos | |
552 | 0af3141d | Panagiotis Kanavos | public void Delete(string relativePath) |
553 | 0af3141d | Panagiotis Kanavos | { |
554 | 4f6d51d4 | Panagiotis Kanavos | var absolutePath = Path.Combine(RootPath, relativePath).ToLower(); |
555 | 0af3141d | Panagiotis Kanavos | if (File.Exists(absolutePath)) |
556 | 4f6d51d4 | Panagiotis Kanavos | { |
557 | 4f6d51d4 | Panagiotis Kanavos | try |
558 | 4f6d51d4 | Panagiotis Kanavos | { |
559 | 4f6d51d4 | Panagiotis Kanavos | File.Delete(absolutePath); |
560 | 4f6d51d4 | Panagiotis Kanavos | } |
561 | 4f6d51d4 | Panagiotis Kanavos | //The file may have been deleted by another thread. Just ignore the relevant exception |
562 | 4f6d51d4 | Panagiotis Kanavos | catch (FileNotFoundException) { } |
563 | 4f6d51d4 | Panagiotis Kanavos | } |
564 | 4f6d51d4 | Panagiotis Kanavos | else if (Directory.Exists(absolutePath)) |
565 | 4f6d51d4 | Panagiotis Kanavos | { |
566 | 4f6d51d4 | Panagiotis Kanavos | try |
567 | 4f6d51d4 | Panagiotis Kanavos | { |
568 | 4f6d51d4 | Panagiotis Kanavos | Directory.Delete(absolutePath, true); |
569 | 4f6d51d4 | Panagiotis Kanavos | } |
570 | 4f6d51d4 | Panagiotis Kanavos | //The directory may have been deleted by another thread. Just ignore the relevant exception |
571 | 4f6d51d4 | Panagiotis Kanavos | catch (DirectoryNotFoundException){} |
572 | 0af3141d | Panagiotis Kanavos | } |
573 | 4f6d51d4 | Panagiotis Kanavos | |
574 | 4f6d51d4 | Panagiotis Kanavos | //_ignoreFiles[absolutePath] = absolutePath; |
575 | 0af3141d | Panagiotis Kanavos | StatusKeeper.ClearFileStatus(absolutePath); |
576 | 0af3141d | Panagiotis Kanavos | } |
577 | 9c4346c9 | Panagiotis Kanavos | } |
578 | 9c4346c9 | Panagiotis Kanavos | } |