root / trunk / Pithos.Core / Agents / FileAgent.cs @ dccd340f
History | View | Annotate | Download (21.9 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 | 5d7b20e8 | Panagiotis Kanavos | public TimeSpan IdleTimeout { get; set; } |
80 | 5d7b20e8 | Panagiotis Kanavos | |
81 | 1caef52e | Panagiotis Kanavos | |
82 | 79f92570 | Panagiotis Kanavos | private void ProcessBatchedEvents(Dictionary<string, FileSystemEventArgs[]> fileEvents) |
83 | 79f92570 | Panagiotis Kanavos | { |
84 | 79f92570 | Panagiotis Kanavos | StatusNotification.SetPithosStatus(PithosStatus.LocalSyncing,String.Format("Uploading {0} files",fileEvents.Count)); |
85 | 79f92570 | Panagiotis Kanavos | foreach (var fileEvent in fileEvents) |
86 | 79f92570 | Panagiotis Kanavos | { |
87 | 79f92570 | Panagiotis Kanavos | var filePath = fileEvent.Key; |
88 | 79f92570 | Panagiotis Kanavos | var changes = fileEvent.Value; |
89 | 79f92570 | Panagiotis Kanavos | |
90 | 79f92570 | Panagiotis Kanavos | if (Ignore(filePath)) continue; |
91 | 79f92570 | Panagiotis Kanavos | |
92 | 79f92570 | Panagiotis Kanavos | foreach (var change in changes) |
93 | 79f92570 | Panagiotis Kanavos | { |
94 | 79f92570 | Panagiotis Kanavos | if (change.ChangeType == WatcherChangeTypes.Renamed) |
95 | 79f92570 | Panagiotis Kanavos | { |
96 | 79f92570 | Panagiotis Kanavos | var rename = (RenamedEventArgs) change; |
97 | 79f92570 | Panagiotis Kanavos | _agent.Post(new WorkflowState |
98 | 79f92570 | Panagiotis Kanavos | { |
99 | 79f92570 | Panagiotis Kanavos | AccountInfo = AccountInfo, |
100 | 79f92570 | Panagiotis Kanavos | OldPath = rename.OldFullPath, |
101 | 79f92570 | Panagiotis Kanavos | OldFileName = rename.OldName, |
102 | 79f92570 | Panagiotis Kanavos | Path = rename.FullPath, |
103 | 79f92570 | Panagiotis Kanavos | FileName = rename.Name, |
104 | 79f92570 | Panagiotis Kanavos | TriggeringChange = rename.ChangeType |
105 | 79f92570 | Panagiotis Kanavos | }); |
106 | 79f92570 | Panagiotis Kanavos | } |
107 | 79f92570 | Panagiotis Kanavos | else |
108 | 79f92570 | Panagiotis Kanavos | _agent.Post(new WorkflowState |
109 | 79f92570 | Panagiotis Kanavos | { |
110 | 79f92570 | Panagiotis Kanavos | AccountInfo = AccountInfo, |
111 | 79f92570 | Panagiotis Kanavos | Path = change.FullPath, |
112 | 79f92570 | Panagiotis Kanavos | FileName = change.Name, |
113 | 79f92570 | Panagiotis Kanavos | TriggeringChange = change.ChangeType |
114 | 79f92570 | Panagiotis Kanavos | }); |
115 | 79f92570 | Panagiotis Kanavos | } |
116 | 79f92570 | Panagiotis Kanavos | } |
117 | 79f92570 | Panagiotis Kanavos | StatusNotification.SetPithosStatus(PithosStatus.LocalComplete); |
118 | 79f92570 | Panagiotis Kanavos | } |
119 | cfed7823 | Panagiotis Kanavos | |
120 | 4ec636f6 | Panagiotis Kanavos | public void Start(AccountInfo accountInfo,string rootPath) |
121 | 9c4346c9 | Panagiotis Kanavos | { |
122 | 4ec636f6 | Panagiotis Kanavos | if (accountInfo==null) |
123 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentNullException("accountInfo"); |
124 | 4ec636f6 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(rootPath)) |
125 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentNullException("rootPath"); |
126 | 4ec636f6 | Panagiotis Kanavos | if (!Path.IsPathRooted(rootPath)) |
127 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentException("rootPath must be an absolute path","rootPath"); |
128 | 5d7b20e8 | Panagiotis Kanavos | if (IdleTimeout == null) |
129 | 5d7b20e8 | Panagiotis Kanavos | throw new InvalidOperationException("IdleTimeout must have a valid value"); |
130 | 4ec636f6 | Panagiotis Kanavos | Contract.EndContractBlock(); |
131 | 4ec636f6 | Panagiotis Kanavos | |
132 | 4ec636f6 | Panagiotis Kanavos | AccountInfo = accountInfo; |
133 | 4ec636f6 | Panagiotis Kanavos | RootPath = rootPath; |
134 | 5d7b20e8 | Panagiotis Kanavos | |
135 | 5d7b20e8 | Panagiotis Kanavos | _eventIdleBatch = new FileEventIdleBatch((int)IdleTimeout.TotalMilliseconds, ProcessBatchedEvents); |
136 | 5d7b20e8 | Panagiotis Kanavos | |
137 | 174bbb6e | Panagiotis Kanavos | _watcher = new FileSystemWatcher(rootPath) {IncludeSubdirectories = true,InternalBufferSize=8*4096}; |
138 | 78ebfd2d | Panagiotis Kanavos | _adapter = new FileSystemWatcherAdapter(_watcher); |
139 | 78ebfd2d | Panagiotis Kanavos | |
140 | 78ebfd2d | Panagiotis Kanavos | _adapter.Changed += OnFileEvent; |
141 | 78ebfd2d | Panagiotis Kanavos | _adapter.Created += OnFileEvent; |
142 | 78ebfd2d | Panagiotis Kanavos | _adapter.Deleted += OnFileEvent; |
143 | 174bbb6e | Panagiotis Kanavos | //_adapter.Renamed += OnRenameEvent; |
144 | 78ebfd2d | Panagiotis Kanavos | _adapter.Moved += OnMoveEvent; |
145 | 4ec636f6 | Panagiotis Kanavos | _watcher.EnableRaisingEvents = true; |
146 | 4ec636f6 | Panagiotis Kanavos | |
147 | 4ec636f6 | Panagiotis Kanavos | |
148 | 4ec636f6 | Panagiotis Kanavos | _agent = Agent<WorkflowState>.Start(inbox => |
149 | 4ec636f6 | Panagiotis Kanavos | { |
150 | 4ec636f6 | Panagiotis Kanavos | Action loop = null; |
151 | 4ec636f6 | Panagiotis Kanavos | loop = () => |
152 | 4ec636f6 | Panagiotis Kanavos | { |
153 | 4ec636f6 | Panagiotis Kanavos | var message = inbox.Receive(); |
154 | 139ac1e8 | Panagiotis Kanavos | var process=message.Then(Process,inbox.CancellationToken); |
155 | 4ec636f6 | Panagiotis Kanavos | inbox.LoopAsync(process,loop,ex=> |
156 | 4ec636f6 | Panagiotis Kanavos | Log.ErrorFormat("[ERROR] File Event Processing:\r{0}", ex)); |
157 | 4ec636f6 | Panagiotis Kanavos | }; |
158 | 4ec636f6 | Panagiotis Kanavos | loop(); |
159 | 4ec636f6 | Panagiotis Kanavos | }); |
160 | 9c4346c9 | Panagiotis Kanavos | } |
161 | 9c4346c9 | Panagiotis Kanavos | |
162 | 4ec636f6 | Panagiotis Kanavos | private Task<object> Process(WorkflowState state) |
163 | a64c87c8 | Panagiotis Kanavos | { |
164 | 4ec636f6 | Panagiotis Kanavos | if (state==null) |
165 | 4ec636f6 | Panagiotis Kanavos | throw new ArgumentNullException("state"); |
166 | 4ec636f6 | Panagiotis Kanavos | Contract.EndContractBlock(); |
167 | 4ec636f6 | Panagiotis Kanavos | |
168 | 4f6d51d4 | Panagiotis Kanavos | if (Ignore(state.Path)) |
169 | 4f6d51d4 | Panagiotis Kanavos | return CompletedTask<object>.Default; |
170 | 4ec636f6 | Panagiotis Kanavos | |
171 | 4ec636f6 | Panagiotis Kanavos | var networkState = NetworkGate.GetNetworkState(state.Path); |
172 | 4ec636f6 | Panagiotis Kanavos | //Skip if the file is already being downloaded or uploaded and |
173 | 4ec636f6 | Panagiotis Kanavos | //the change is create or modify |
174 | 4ec636f6 | Panagiotis Kanavos | if (networkState != NetworkOperation.None && |
175 | 4ec636f6 | Panagiotis Kanavos | ( |
176 | 4ec636f6 | Panagiotis Kanavos | state.TriggeringChange == WatcherChangeTypes.Created || |
177 | 4ec636f6 | Panagiotis Kanavos | state.TriggeringChange == WatcherChangeTypes.Changed |
178 | 4ec636f6 | Panagiotis Kanavos | )) |
179 | 4ec636f6 | Panagiotis Kanavos | return CompletedTask<object>.Default; |
180 | a64c87c8 | Panagiotis Kanavos | |
181 | a64c87c8 | Panagiotis Kanavos | try |
182 | a64c87c8 | Panagiotis Kanavos | { |
183 | 174bbb6e | Panagiotis Kanavos | //StatusKeeper.EnsureFileState(state.Path); |
184 | 174bbb6e | Panagiotis Kanavos | |
185 | 4ec636f6 | Panagiotis Kanavos | UpdateFileStatus(state); |
186 | 4ec636f6 | Panagiotis Kanavos | UpdateOverlayStatus(state); |
187 | 4ec636f6 | Panagiotis Kanavos | UpdateFileChecksum(state); |
188 | 4ec636f6 | Panagiotis Kanavos | WorkflowAgent.Post(state); |
189 | a64c87c8 | Panagiotis Kanavos | } |
190 | a64c87c8 | Panagiotis Kanavos | catch (IOException exc) |
191 | a64c87c8 | Panagiotis Kanavos | { |
192 | 4ec636f6 | Panagiotis Kanavos | if (File.Exists(state.Path)) |
193 | 0af3141d | Panagiotis Kanavos | { |
194 | 4ec636f6 | Panagiotis Kanavos | Log.WarnFormat("File access error occured, retrying {0}\n{1}", state.Path, exc); |
195 | 4ec636f6 | Panagiotis Kanavos | _agent.Post(state); |
196 | 0af3141d | Panagiotis Kanavos | } |
197 | 0af3141d | Panagiotis Kanavos | else |
198 | 0af3141d | Panagiotis Kanavos | { |
199 | 4ec636f6 | Panagiotis Kanavos | Log.WarnFormat("File {0} does not exist. Will be ignored\n{1}", state.Path, exc); |
200 | 0af3141d | Panagiotis Kanavos | } |
201 | a64c87c8 | Panagiotis Kanavos | } |
202 | a64c87c8 | Panagiotis Kanavos | catch (Exception exc) |
203 | a64c87c8 | Panagiotis Kanavos | { |
204 | 4ec636f6 | Panagiotis Kanavos | Log.WarnFormat("Error occured while indexing{0}. The file will be skipped\n{1}", |
205 | 4ec636f6 | Panagiotis Kanavos | state.Path, exc); |
206 | a64c87c8 | Panagiotis Kanavos | } |
207 | 4ec636f6 | Panagiotis Kanavos | return CompletedTask<object>.Default; |
208 | 5e31048f | Panagiotis Kanavos | } |
209 | a64c87c8 | Panagiotis Kanavos | |
210 | 9c4346c9 | Panagiotis Kanavos | public bool Pause |
211 | 9c4346c9 | Panagiotis Kanavos | { |
212 | 9c4346c9 | Panagiotis Kanavos | get { return _watcher == null || !_watcher.EnableRaisingEvents; } |
213 | 9c4346c9 | Panagiotis Kanavos | set |
214 | 9c4346c9 | Panagiotis Kanavos | { |
215 | 9c4346c9 | Panagiotis Kanavos | if (_watcher != null) |
216 | 9c4346c9 | Panagiotis Kanavos | _watcher.EnableRaisingEvents = !value; |
217 | 9c4346c9 | Panagiotis Kanavos | } |
218 | 9c4346c9 | Panagiotis Kanavos | } |
219 | 9c4346c9 | Panagiotis Kanavos | |
220 | 77e10b4f | Panagiotis Kanavos | public string CachePath { get; set; } |
221 | 1caef52e | Panagiotis Kanavos | |
222 | d3a13891 | Panagiotis Kanavos | private List<string> _selectivePaths = new List<string>(); |
223 | d3a13891 | Panagiotis Kanavos | public List<string> SelectivePaths |
224 | d3a13891 | Panagiotis Kanavos | { |
225 | d3a13891 | Panagiotis Kanavos | get { return _selectivePaths; } |
226 | d3a13891 | Panagiotis Kanavos | set { _selectivePaths = value; } |
227 | d3a13891 | Panagiotis Kanavos | } |
228 | d3a13891 | Panagiotis Kanavos | |
229 | d3a13891 | Panagiotis Kanavos | |
230 | 9c4346c9 | Panagiotis Kanavos | public void Post(WorkflowState workflowState) |
231 | 9c4346c9 | Panagiotis Kanavos | { |
232 | cfed7823 | Panagiotis Kanavos | if (workflowState == null) |
233 | cfed7823 | Panagiotis Kanavos | throw new ArgumentNullException("workflowState"); |
234 | cfed7823 | Panagiotis Kanavos | Contract.EndContractBlock(); |
235 | cfed7823 | Panagiotis Kanavos | |
236 | 9c4346c9 | Panagiotis Kanavos | _agent.Post(workflowState); |
237 | 9c4346c9 | Panagiotis Kanavos | } |
238 | 9c4346c9 | Panagiotis Kanavos | |
239 | 9c4346c9 | Panagiotis Kanavos | public void Stop() |
240 | 9c4346c9 | Panagiotis Kanavos | { |
241 | 9c4346c9 | Panagiotis Kanavos | if (_watcher != null) |
242 | 9c4346c9 | Panagiotis Kanavos | { |
243 | 9c4346c9 | Panagiotis Kanavos | _watcher.Dispose(); |
244 | 9c4346c9 | Panagiotis Kanavos | } |
245 | 9c4346c9 | Panagiotis Kanavos | _watcher = null; |
246 | 9c4346c9 | Panagiotis Kanavos | |
247 | cfed7823 | Panagiotis Kanavos | if (_agent!=null) |
248 | 4ec636f6 | Panagiotis Kanavos | _agent.Stop(); |
249 | 9c4346c9 | Panagiotis Kanavos | } |
250 | 9c4346c9 | Panagiotis Kanavos | |
251 | 1caef52e | Panagiotis Kanavos | // Enumerate all files in the Pithos directory except those in the Fragment folder |
252 | 1caef52e | Panagiotis Kanavos | // and files with a .ignore extension |
253 | 1caef52e | Panagiotis Kanavos | public IEnumerable<string> EnumerateFiles(string searchPattern="*") |
254 | 1caef52e | Panagiotis Kanavos | { |
255 | 1caef52e | Panagiotis Kanavos | var monitoredFiles = from filePath in Directory.EnumerateFileSystemEntries(RootPath, searchPattern, SearchOption.AllDirectories) |
256 | 1caef52e | Panagiotis Kanavos | where !Ignore(filePath) |
257 | 1caef52e | Panagiotis Kanavos | select filePath; |
258 | 1caef52e | Panagiotis Kanavos | return monitoredFiles; |
259 | 1caef52e | Panagiotis Kanavos | } |
260 | 1caef52e | Panagiotis Kanavos | |
261 | 1caef52e | Panagiotis Kanavos | public IEnumerable<FileInfo> EnumerateFileInfos(string searchPattern="*") |
262 | 1caef52e | Panagiotis Kanavos | { |
263 | 1caef52e | Panagiotis Kanavos | var rootDir = new DirectoryInfo(RootPath); |
264 | 1caef52e | Panagiotis Kanavos | var monitoredFiles = from file in rootDir.EnumerateFiles(searchPattern, SearchOption.AllDirectories) |
265 | 1caef52e | Panagiotis Kanavos | where !Ignore(file.FullName) |
266 | 1caef52e | Panagiotis Kanavos | select file; |
267 | 1caef52e | Panagiotis Kanavos | return monitoredFiles; |
268 | 1caef52e | Panagiotis Kanavos | } |
269 | 1caef52e | Panagiotis Kanavos | |
270 | 1caef52e | Panagiotis Kanavos | public IEnumerable<string> EnumerateFilesAsRelativeUrls(string searchPattern="*") |
271 | 1caef52e | Panagiotis Kanavos | { |
272 | 1caef52e | Panagiotis Kanavos | var rootDir = new DirectoryInfo(RootPath); |
273 | 1caef52e | Panagiotis Kanavos | var monitoredFiles = from file in rootDir.EnumerateFiles(searchPattern, SearchOption.AllDirectories) |
274 | 1caef52e | Panagiotis Kanavos | where !Ignore(file.FullName) |
275 | 1caef52e | Panagiotis Kanavos | select file.AsRelativeUrlTo(RootPath); |
276 | 1caef52e | Panagiotis Kanavos | return monitoredFiles; |
277 | 1caef52e | Panagiotis Kanavos | } |
278 | 1caef52e | Panagiotis Kanavos | |
279 | 540b8cf8 | Panagiotis Kanavos | public IEnumerable<string> EnumerateFilesSystemInfosAsRelativeUrls(string searchPattern="*") |
280 | 540b8cf8 | Panagiotis Kanavos | { |
281 | 540b8cf8 | Panagiotis Kanavos | var rootDir = new DirectoryInfo(RootPath); |
282 | 540b8cf8 | Panagiotis Kanavos | var monitoredFiles = from file in rootDir.EnumerateFileSystemInfos(searchPattern, SearchOption.AllDirectories) |
283 | 540b8cf8 | Panagiotis Kanavos | where !Ignore(file.FullName) |
284 | 540b8cf8 | Panagiotis Kanavos | select file.AsRelativeUrlTo(RootPath); |
285 | 540b8cf8 | Panagiotis Kanavos | return monitoredFiles; |
286 | 540b8cf8 | Panagiotis Kanavos | } |
287 | 540b8cf8 | Panagiotis Kanavos | |
288 | 1caef52e | Panagiotis Kanavos | |
289 | 1caef52e | Panagiotis Kanavos | |
290 | 1caef52e | Panagiotis Kanavos | |
291 | 1caef52e | Panagiotis Kanavos | private bool Ignore(string filePath) |
292 | 1caef52e | Panagiotis Kanavos | { |
293 | 139ac1e8 | Panagiotis Kanavos | //Ignore all first-level directories and files (ie at the container folders level) |
294 | d9b1cbeb | Panagiotis Kanavos | if (FoundBelowRoot(filePath, RootPath,1)) |
295 | 139ac1e8 | Panagiotis Kanavos | return true; |
296 | d9b1cbeb | Panagiotis Kanavos | |
297 | 139ac1e8 | Panagiotis Kanavos | //Ignore first-level items under the "others" folder (ie at the accounts folders level). |
298 | d9b1cbeb | Panagiotis Kanavos | var othersPath = Path.Combine(RootPath, FolderConstants.OthersFolder); |
299 | d9b1cbeb | Panagiotis Kanavos | if (FoundBelowRoot(filePath, othersPath,1)) |
300 | 139ac1e8 | Panagiotis Kanavos | return true; |
301 | d9b1cbeb | Panagiotis Kanavos | |
302 | 139ac1e8 | Panagiotis Kanavos | //Ignore second-level (container) folders under the "others" folder (ie at the container folders level). |
303 | d9b1cbeb | Panagiotis Kanavos | if (FoundBelowRoot(filePath, othersPath,2)) |
304 | d9b1cbeb | Panagiotis Kanavos | return true; |
305 | d9b1cbeb | Panagiotis Kanavos | |
306 | d9b1cbeb | Panagiotis Kanavos | |
307 | d9b1cbeb | Panagiotis Kanavos | //Ignore anything happening in the cache path |
308 | 77e10b4f | Panagiotis Kanavos | if (filePath.StartsWith(CachePath)) |
309 | 1caef52e | Panagiotis Kanavos | return true; |
310 | 0af3141d | Panagiotis Kanavos | if (_ignoreFiles.ContainsKey(filePath.ToLower())) |
311 | 0af3141d | Panagiotis Kanavos | return true; |
312 | 139ac1e8 | Panagiotis Kanavos | |
313 | fec5da06 | Panagiotis Kanavos | //Ignore if selective synchronization is defined, |
314 | fec5da06 | Panagiotis Kanavos | return SelectivePaths.Count > 0 |
315 | fec5da06 | Panagiotis Kanavos | //And the target file is not below any of the selective paths |
316 | fec5da06 | Panagiotis Kanavos | && !SelectivePaths.Any(filePath.IsAtOrDirectlyBelow); |
317 | 1caef52e | Panagiotis Kanavos | } |
318 | 1caef52e | Panagiotis Kanavos | |
319 | d9b1cbeb | Panagiotis Kanavos | /* private static bool FoundInRoot(string filePath, string rootPath) |
320 | d9b1cbeb | Panagiotis Kanavos | { |
321 | d9b1cbeb | Panagiotis Kanavos | //var rootDirectory = new DirectoryInfo(rootPath); |
322 | d9b1cbeb | Panagiotis Kanavos | |
323 | d9b1cbeb | Panagiotis Kanavos | //If the paths are equal, return true |
324 | d9b1cbeb | Panagiotis Kanavos | if (filePath.Equals(rootPath, StringComparison.InvariantCultureIgnoreCase)) |
325 | d9b1cbeb | Panagiotis Kanavos | return true; |
326 | d9b1cbeb | Panagiotis Kanavos | |
327 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is below the root path |
328 | d9b1cbeb | Panagiotis Kanavos | if (filePath.StartsWith(rootPath,StringComparison.InvariantCulture)) |
329 | d9b1cbeb | Panagiotis Kanavos | { |
330 | d9b1cbeb | Panagiotis Kanavos | //Get the relative path |
331 | d9b1cbeb | Panagiotis Kanavos | var relativePath = filePath.Substring(rootPath.Length + 1); |
332 | d9b1cbeb | Panagiotis Kanavos | //If the relativePath does NOT contains a path separator, we found a match |
333 | d9b1cbeb | Panagiotis Kanavos | return (!relativePath.Contains(@"\")); |
334 | d9b1cbeb | Panagiotis Kanavos | } |
335 | d9b1cbeb | Panagiotis Kanavos | |
336 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is not under the root path, return false |
337 | d9b1cbeb | Panagiotis Kanavos | return false; |
338 | d9b1cbeb | Panagiotis Kanavos | }*/ |
339 | d9b1cbeb | Panagiotis Kanavos | |
340 | d9b1cbeb | Panagiotis Kanavos | |
341 | d9b1cbeb | Panagiotis Kanavos | private static bool FoundBelowRoot(string filePath, string rootPath,int level) |
342 | d9b1cbeb | Panagiotis Kanavos | { |
343 | d9b1cbeb | Panagiotis Kanavos | //var rootDirectory = new DirectoryInfo(rootPath); |
344 | d9b1cbeb | Panagiotis Kanavos | |
345 | d9b1cbeb | Panagiotis Kanavos | //If the paths are equal, return true |
346 | d9b1cbeb | Panagiotis Kanavos | if (filePath.Equals(rootPath, StringComparison.InvariantCultureIgnoreCase)) |
347 | d9b1cbeb | Panagiotis Kanavos | return true; |
348 | d9b1cbeb | Panagiotis Kanavos | |
349 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is below the root path |
350 | d9b1cbeb | Panagiotis Kanavos | if (filePath.StartsWith(rootPath,StringComparison.InvariantCulture)) |
351 | d9b1cbeb | Panagiotis Kanavos | { |
352 | d9b1cbeb | Panagiotis Kanavos | //Get the relative path |
353 | d9b1cbeb | Panagiotis Kanavos | var relativePath = filePath.Substring(rootPath.Length + 1); |
354 | d9b1cbeb | Panagiotis Kanavos | //If the relativePath does NOT contains a path separator, we found a match |
355 | d9b1cbeb | Panagiotis Kanavos | var levels=relativePath.ToCharArray().Count(c=>c=='\\')+1; |
356 | d9b1cbeb | Panagiotis Kanavos | return levels==level; |
357 | d9b1cbeb | Panagiotis Kanavos | } |
358 | d9b1cbeb | Panagiotis Kanavos | |
359 | d9b1cbeb | Panagiotis Kanavos | //If the filepath is not under the root path, return false |
360 | d9b1cbeb | Panagiotis Kanavos | return false; |
361 | d9b1cbeb | Panagiotis Kanavos | } |
362 | d9b1cbeb | Panagiotis Kanavos | |
363 | 1caef52e | Panagiotis Kanavos | //Post a Change message for all events except rename |
364 | 9c4346c9 | Panagiotis Kanavos | void OnFileEvent(object sender, FileSystemEventArgs e) |
365 | 9c4346c9 | Panagiotis Kanavos | { |
366 | 77e10b4f | Panagiotis Kanavos | //Ignore events that affect the cache folder |
367 | 1caef52e | Panagiotis Kanavos | var filePath = e.FullPath; |
368 | 1caef52e | Panagiotis Kanavos | if (Ignore(filePath)) |
369 | a0dcfcc9 | Panagiotis Kanavos | return; |
370 | 79f92570 | Panagiotis Kanavos | _eventIdleBatch.Post(e); |
371 | 9c4346c9 | Panagiotis Kanavos | } |
372 | 9c4346c9 | Panagiotis Kanavos | |
373 | 1caef52e | Panagiotis Kanavos | |
374 | 174bbb6e | Panagiotis Kanavos | /* |
375 | 1caef52e | Panagiotis Kanavos | //Post a Change message for renames containing the old and new names |
376 | 9c4346c9 | Panagiotis Kanavos | void OnRenameEvent(object sender, RenamedEventArgs e) |
377 | 9c4346c9 | Panagiotis Kanavos | { |
378 | 1caef52e | Panagiotis Kanavos | var oldFullPath = e.OldFullPath; |
379 | 1caef52e | Panagiotis Kanavos | var fullPath = e.FullPath; |
380 | 1caef52e | Panagiotis Kanavos | if (Ignore(oldFullPath) || Ignore(fullPath)) |
381 | 1caef52e | Panagiotis Kanavos | return; |
382 | 1caef52e | Panagiotis Kanavos | |
383 | 1bfc38f1 | Panagiotis Kanavos | _agent.Post(new WorkflowState |
384 | 9c4346c9 | Panagiotis Kanavos | { |
385 | 1bfc38f1 | Panagiotis Kanavos | AccountInfo=AccountInfo, |
386 | 1caef52e | Panagiotis Kanavos | OldPath = oldFullPath, |
387 | 9c4346c9 | Panagiotis Kanavos | OldFileName = e.OldName, |
388 | 1caef52e | Panagiotis Kanavos | Path = fullPath, |
389 | 9c4346c9 | Panagiotis Kanavos | FileName = e.Name, |
390 | 78ebfd2d | Panagiotis Kanavos | TriggeringChange = e.ChangeType |
391 | 78ebfd2d | Panagiotis Kanavos | }); |
392 | 78ebfd2d | Panagiotis Kanavos | } |
393 | 174bbb6e | Panagiotis Kanavos | */ |
394 | 78ebfd2d | Panagiotis Kanavos | |
395 | 174bbb6e | Panagiotis Kanavos | //Post a Change message for moves containing the old and new names |
396 | 78ebfd2d | Panagiotis Kanavos | void OnMoveEvent(object sender, MovedEventArgs e) |
397 | 78ebfd2d | Panagiotis Kanavos | { |
398 | 78ebfd2d | Panagiotis Kanavos | var oldFullPath = e.OldFullPath; |
399 | 78ebfd2d | Panagiotis Kanavos | var fullPath = e.FullPath; |
400 | 78ebfd2d | Panagiotis Kanavos | if (Ignore(oldFullPath) || Ignore(fullPath)) |
401 | 78ebfd2d | Panagiotis Kanavos | return; |
402 | 78ebfd2d | Panagiotis Kanavos | |
403 | 79f92570 | Panagiotis Kanavos | _eventIdleBatch.Post(e); |
404 | 9c4346c9 | Panagiotis Kanavos | } |
405 | 9c4346c9 | Panagiotis Kanavos | |
406 | 9c4346c9 | Panagiotis Kanavos | |
407 | 9c4346c9 | Panagiotis Kanavos | |
408 | 9c4346c9 | Panagiotis Kanavos | private Dictionary<WatcherChangeTypes, FileStatus> _statusDict = new Dictionary<WatcherChangeTypes, FileStatus> |
409 | fbbbe99b | Panagiotis Kanavos | { |
410 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Created,FileStatus.Created}, |
411 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Changed,FileStatus.Modified}, |
412 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Deleted,FileStatus.Deleted}, |
413 | 9c4346c9 | Panagiotis Kanavos | {WatcherChangeTypes.Renamed,FileStatus.Renamed} |
414 | 9c4346c9 | Panagiotis Kanavos | }; |
415 | 9c4346c9 | Panagiotis Kanavos | |
416 | fbbbe99b | Panagiotis Kanavos | private Dictionary<string, string> _ignoreFiles=new Dictionary<string, string>(); |
417 | 0af3141d | Panagiotis Kanavos | |
418 | 9c4346c9 | Panagiotis Kanavos | private WorkflowState UpdateFileStatus(WorkflowState state) |
419 | 9c4346c9 | Panagiotis Kanavos | { |
420 | cfed7823 | Panagiotis Kanavos | if (state==null) |
421 | cfed7823 | Panagiotis Kanavos | throw new ArgumentNullException("state"); |
422 | cfed7823 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(state.Path)) |
423 | cfed7823 | Panagiotis Kanavos | throw new ArgumentException("The state's Path can't be empty","state"); |
424 | cfed7823 | Panagiotis Kanavos | Contract.EndContractBlock(); |
425 | 1caef52e | Panagiotis Kanavos | |
426 | cfed7823 | Panagiotis Kanavos | var path = state.Path; |
427 | cfed7823 | Panagiotis Kanavos | var status = _statusDict[state.TriggeringChange]; |
428 | 9c4346c9 | Panagiotis Kanavos | var oldStatus = Workflow.StatusKeeper.GetFileStatus(path); |
429 | 9c4346c9 | Panagiotis Kanavos | if (status == oldStatus) |
430 | 9c4346c9 | Panagiotis Kanavos | { |
431 | 9c4346c9 | Panagiotis Kanavos | state.Status = status; |
432 | 9c4346c9 | Panagiotis Kanavos | state.Skip = true; |
433 | 9c4346c9 | Panagiotis Kanavos | return state; |
434 | 9c4346c9 | Panagiotis Kanavos | } |
435 | 9c4346c9 | Panagiotis Kanavos | if (state.Status == FileStatus.Renamed) |
436 | 9c4346c9 | Panagiotis Kanavos | Workflow.ClearFileStatus(path); |
437 | 9c4346c9 | Panagiotis Kanavos | |
438 | 9c4346c9 | Panagiotis Kanavos | state.Status = Workflow.SetFileStatus(path, status); |
439 | 9c4346c9 | Panagiotis Kanavos | return state; |
440 | 9c4346c9 | Panagiotis Kanavos | } |
441 | 9c4346c9 | Panagiotis Kanavos | |
442 | 9c4346c9 | Panagiotis Kanavos | private WorkflowState UpdateOverlayStatus(WorkflowState state) |
443 | 9c4346c9 | Panagiotis Kanavos | { |
444 | cfed7823 | Panagiotis Kanavos | if (state==null) |
445 | cfed7823 | Panagiotis Kanavos | throw new ArgumentNullException("state"); |
446 | cfed7823 | Panagiotis Kanavos | Contract.EndContractBlock(); |
447 | cfed7823 | Panagiotis Kanavos | |
448 | 9c4346c9 | Panagiotis Kanavos | if (state.Skip) |
449 | 9c4346c9 | Panagiotis Kanavos | return state; |
450 | 9c4346c9 | Panagiotis Kanavos | |
451 | 9c4346c9 | Panagiotis Kanavos | switch (state.Status) |
452 | 9c4346c9 | Panagiotis Kanavos | { |
453 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Created: |
454 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash); |
455 | 174bbb6e | Panagiotis Kanavos | break; |
456 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Modified: |
457 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash); |
458 | 9c4346c9 | Panagiotis Kanavos | break; |
459 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Deleted: |
460 | cfed7823 | Panagiotis Kanavos | //this.StatusAgent.RemoveFileOverlayStatus(state.Path); |
461 | 9c4346c9 | Panagiotis Kanavos | break; |
462 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Renamed: |
463 | cfed7823 | Panagiotis Kanavos | this.StatusKeeper.ClearFileStatus(state.OldPath); |
464 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash); |
465 | 9c4346c9 | Panagiotis Kanavos | break; |
466 | 9c4346c9 | Panagiotis Kanavos | case FileStatus.Unchanged: |
467 | 174bbb6e | Panagiotis Kanavos | this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Normal,state.ShortHash); |
468 | 9c4346c9 | Panagiotis Kanavos | break; |
469 | 9c4346c9 | Panagiotis Kanavos | } |
470 | 9c4346c9 | Panagiotis Kanavos | |
471 | 9c4346c9 | Panagiotis Kanavos | if (state.Status == FileStatus.Deleted) |
472 | 1caef52e | Panagiotis Kanavos | NativeMethods.RaiseChangeNotification(Path.GetDirectoryName(state.Path)); |
473 | 9c4346c9 | Panagiotis Kanavos | else |
474 | 1caef52e | Panagiotis Kanavos | NativeMethods.RaiseChangeNotification(state.Path); |
475 | 9c4346c9 | Panagiotis Kanavos | return state; |
476 | 9c4346c9 | Panagiotis Kanavos | } |
477 | 9c4346c9 | Panagiotis Kanavos | |
478 | 9c4346c9 | Panagiotis Kanavos | |
479 | 9c4346c9 | Panagiotis Kanavos | private WorkflowState UpdateFileChecksum(WorkflowState state) |
480 | 9c4346c9 | Panagiotis Kanavos | { |
481 | 9c4346c9 | Panagiotis Kanavos | if (state.Skip) |
482 | 9c4346c9 | Panagiotis Kanavos | return state; |
483 | 9c4346c9 | Panagiotis Kanavos | |
484 | 9c4346c9 | Panagiotis Kanavos | if (state.Status == FileStatus.Deleted) |
485 | 9c4346c9 | Panagiotis Kanavos | return state; |
486 | 9c4346c9 | Panagiotis Kanavos | |
487 | 1caef52e | Panagiotis Kanavos | var path = state.Path; |
488 | 1caef52e | Panagiotis Kanavos | //Skip calculation for folders |
489 | 1caef52e | Panagiotis Kanavos | if (Directory.Exists(path)) |
490 | 1caef52e | Panagiotis Kanavos | return state; |
491 | 1caef52e | Panagiotis Kanavos | |
492 | 174bbb6e | Panagiotis Kanavos | |
493 | 0af3141d | Panagiotis Kanavos | var info = new FileInfo(path); |
494 | 174bbb6e | Panagiotis Kanavos | StatusNotification.Notify(new StatusNotification(String.Format("Hashing [{0}]",info.Name))); |
495 | 174bbb6e | Panagiotis Kanavos | |
496 | 174bbb6e | Panagiotis Kanavos | var shortHash = info.ComputeShortHash(); |
497 | 174bbb6e | Panagiotis Kanavos | |
498 | 174bbb6e | Panagiotis Kanavos | string merkleHash = info.CalculateHash(StatusKeeper.BlockSize,StatusKeeper.BlockHash); |
499 | 174bbb6e | Panagiotis Kanavos | StatusKeeper.UpdateFileChecksum(path,shortHash, merkleHash); |
500 | 9c4346c9 | Panagiotis Kanavos | |
501 | 174bbb6e | Panagiotis Kanavos | state.Hash = merkleHash; |
502 | 9c4346c9 | Panagiotis Kanavos | return state; |
503 | 9c4346c9 | Panagiotis Kanavos | } |
504 | 9c4346c9 | Panagiotis Kanavos | |
505 | bfc13ed8 | Panagiotis Kanavos | //Does the file exist in the container's local folder? |
506 | bfc13ed8 | Panagiotis Kanavos | public bool Exists(string relativePath) |
507 | bfc13ed8 | Panagiotis Kanavos | { |
508 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(relativePath)) |
509 | bfc13ed8 | Panagiotis Kanavos | throw new ArgumentNullException("relativePath"); |
510 | bfc13ed8 | Panagiotis Kanavos | //A RootPath must be set before calling this method |
511 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(RootPath)) |
512 | bfc13ed8 | Panagiotis Kanavos | throw new InvalidOperationException("RootPath was not set"); |
513 | bfc13ed8 | Panagiotis Kanavos | Contract.EndContractBlock(); |
514 | bfc13ed8 | Panagiotis Kanavos | //Create the absolute path by combining the RootPath with the relativePath |
515 | bfc13ed8 | Panagiotis Kanavos | var absolutePath=Path.Combine(RootPath, relativePath); |
516 | bfc13ed8 | Panagiotis Kanavos | //Is this a valid file? |
517 | bfc13ed8 | Panagiotis Kanavos | if (File.Exists(absolutePath)) |
518 | bfc13ed8 | Panagiotis Kanavos | return true; |
519 | bfc13ed8 | Panagiotis Kanavos | //Or a directory? |
520 | a64c87c8 | Panagiotis Kanavos | if (Directory.Exists(absolutePath)) |
521 | bfc13ed8 | Panagiotis Kanavos | return true; |
522 | bfc13ed8 | Panagiotis Kanavos | //Fail if it is neither |
523 | bfc13ed8 | Panagiotis Kanavos | return false; |
524 | bfc13ed8 | Panagiotis Kanavos | } |
525 | 9c4346c9 | Panagiotis Kanavos | |
526 | fbbbe99b | Panagiotis Kanavos | public static FileAgent GetFileAgent(AccountInfo accountInfo) |
527 | fbbbe99b | Panagiotis Kanavos | { |
528 | fbbbe99b | Panagiotis Kanavos | return GetFileAgent(accountInfo.AccountPath); |
529 | fbbbe99b | Panagiotis Kanavos | } |
530 | fbbbe99b | Panagiotis Kanavos | |
531 | fbbbe99b | Panagiotis Kanavos | public static FileAgent GetFileAgent(string rootPath) |
532 | fbbbe99b | Panagiotis Kanavos | { |
533 | fbbbe99b | Panagiotis Kanavos | return AgentLocator<FileAgent>.Get(rootPath.ToLower()); |
534 | fbbbe99b | Panagiotis Kanavos | } |
535 | fbbbe99b | Panagiotis Kanavos | |
536 | fbbbe99b | Panagiotis Kanavos | |
537 | f3d080df | Panagiotis Kanavos | public FileSystemInfo GetFileSystemInfo(string relativePath) |
538 | bfc13ed8 | Panagiotis Kanavos | { |
539 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(relativePath)) |
540 | bfc13ed8 | Panagiotis Kanavos | throw new ArgumentNullException("relativePath"); |
541 | bfc13ed8 | Panagiotis Kanavos | //A RootPath must be set before calling this method |
542 | bfc13ed8 | Panagiotis Kanavos | if (String.IsNullOrWhiteSpace(RootPath)) |
543 | bfc13ed8 | Panagiotis Kanavos | throw new InvalidOperationException("RootPath was not set"); |
544 | bfc13ed8 | Panagiotis Kanavos | Contract.EndContractBlock(); |
545 | bfc13ed8 | Panagiotis Kanavos | |
546 | bfc13ed8 | Panagiotis Kanavos | var absolutePath = Path.Combine(RootPath, relativePath); |
547 | bfc13ed8 | Panagiotis Kanavos | |
548 | 4f6d51d4 | Panagiotis Kanavos | if (Directory.Exists(absolutePath)) |
549 | f3d080df | Panagiotis Kanavos | return new DirectoryInfo(absolutePath).WithProperCapitalization(); |
550 | 4f6d51d4 | Panagiotis Kanavos | else |
551 | f3d080df | Panagiotis Kanavos | return new FileInfo(absolutePath).WithProperCapitalization(); |
552 | bfc13ed8 | Panagiotis Kanavos | |
553 | bfc13ed8 | Panagiotis Kanavos | } |
554 | a27aa447 | Panagiotis Kanavos | |
555 | 0af3141d | Panagiotis Kanavos | public void Delete(string relativePath) |
556 | 0af3141d | Panagiotis Kanavos | { |
557 | 4f6d51d4 | Panagiotis Kanavos | var absolutePath = Path.Combine(RootPath, relativePath).ToLower(); |
558 | 0af3141d | Panagiotis Kanavos | if (File.Exists(absolutePath)) |
559 | 4f6d51d4 | Panagiotis Kanavos | { |
560 | 4f6d51d4 | Panagiotis Kanavos | try |
561 | 4f6d51d4 | Panagiotis Kanavos | { |
562 | 4f6d51d4 | Panagiotis Kanavos | File.Delete(absolutePath); |
563 | 4f6d51d4 | Panagiotis Kanavos | } |
564 | 4f6d51d4 | Panagiotis Kanavos | //The file may have been deleted by another thread. Just ignore the relevant exception |
565 | 4f6d51d4 | Panagiotis Kanavos | catch (FileNotFoundException) { } |
566 | 4f6d51d4 | Panagiotis Kanavos | } |
567 | 4f6d51d4 | Panagiotis Kanavos | else if (Directory.Exists(absolutePath)) |
568 | 4f6d51d4 | Panagiotis Kanavos | { |
569 | 4f6d51d4 | Panagiotis Kanavos | try |
570 | 4f6d51d4 | Panagiotis Kanavos | { |
571 | 4f6d51d4 | Panagiotis Kanavos | Directory.Delete(absolutePath, true); |
572 | 4f6d51d4 | Panagiotis Kanavos | } |
573 | 4f6d51d4 | Panagiotis Kanavos | //The directory may have been deleted by another thread. Just ignore the relevant exception |
574 | 4f6d51d4 | Panagiotis Kanavos | catch (DirectoryNotFoundException){} |
575 | 0af3141d | Panagiotis Kanavos | } |
576 | 4f6d51d4 | Panagiotis Kanavos | |
577 | 4f6d51d4 | Panagiotis Kanavos | //_ignoreFiles[absolutePath] = absolutePath; |
578 | 0af3141d | Panagiotis Kanavos | StatusKeeper.ClearFileStatus(absolutePath); |
579 | 0af3141d | Panagiotis Kanavos | } |
580 | 9c4346c9 | Panagiotis Kanavos | } |
581 | 9c4346c9 | Panagiotis Kanavos | } |