Revision b666b39a trunk/Pithos.Core/Agents/NetworkAgent.cs
b/trunk/Pithos.Core/Agents/NetworkAgent.cs | ||
---|---|---|
161 | 161 |
var moveAction = (CloudMoveAction)action; |
162 | 162 |
RenameCloudFile(accountInfo, moveAction); |
163 | 163 |
break; |
164 |
case CloudActionType.RenameLocal: |
|
165 |
RenameLocalFile(accountInfo, action); |
|
166 |
break; |
|
164 | 167 |
case CloudActionType.MustSynch: |
165 | 168 |
if (!File.Exists(downloadPath) && !Directory.Exists(downloadPath)) |
166 | 169 |
{ |
... | ... | |
214 | 217 |
} |
215 | 218 |
} |
216 | 219 |
|
220 |
|
|
217 | 221 |
private void UpdateStatus(PithosStatus status) |
218 | 222 |
{ |
219 | 223 |
StatusKeeper.SetPithosStatus(status); |
220 | 224 |
StatusNotification.Notify(new Notification()); |
221 | 225 |
} |
222 | 226 |
|
223 |
|
|
227 |
private void RenameLocalFile(AccountInfo accountInfo, CloudAction action) |
|
228 |
{ |
|
229 |
if (accountInfo == null) |
|
230 |
throw new ArgumentNullException("accountInfo"); |
|
231 |
if (action == null) |
|
232 |
throw new ArgumentNullException("action"); |
|
233 |
if (action.LocalFile == null) |
|
234 |
throw new ArgumentException("The action's local file is not specified", "action"); |
|
235 |
if (!Path.IsPathRooted(action.LocalFile.FullName)) |
|
236 |
throw new ArgumentException("The action's local file path must be absolute", "action"); |
|
237 |
if (action.CloudFile == null) |
|
238 |
throw new ArgumentException("The action's cloud file is not specified", "action"); |
|
239 |
Contract.EndContractBlock(); |
|
240 |
|
|
241 |
//We assume that the local file already exists, otherwise the poll agent |
|
242 |
//would have issued a download request |
|
243 |
|
|
244 |
var currentInfo = action.CloudFile; |
|
245 |
var previousInfo = action.CloudFile.Previous; |
|
246 |
var fileAgent = FileAgent.GetFileAgent(accountInfo); |
|
247 |
|
|
248 |
var previousRelativepath = previousInfo.RelativeUrlToFilePath(accountInfo.UserName); |
|
249 |
var previousFile = fileAgent.GetFileSystemInfo(previousRelativepath); |
|
250 |
|
|
251 |
//In every case we need to move the local file first |
|
252 |
MoveLocalFile(accountInfo, previousFile, fileAgent, currentInfo); |
|
253 |
|
|
254 |
} |
|
255 |
|
|
256 |
private void MoveLocalFile(AccountInfo accountInfo, FileSystemInfo previousFile, FileAgent fileAgent, |
|
257 |
ObjectInfo currentInfo) |
|
258 |
{ |
|
259 |
var currentRelativepath = currentInfo.RelativeUrlToFilePath(accountInfo.UserName); |
|
260 |
var newPath = Path.Combine(fileAgent.RootPath, currentRelativepath); |
|
261 |
|
|
262 |
var isFile= (previousFile is FileInfo); |
|
263 |
var previousFullPath = isFile? |
|
264 |
FileInfoExtensions.GetProperFilePathCapitalization(previousFile.FullName): |
|
265 |
FileInfoExtensions.GetProperDirectoryCapitalization(previousFile.FullName); |
|
266 |
|
|
267 |
using (var gateOld = NetworkGate.Acquire(previousFullPath, NetworkOperation.Renaming)) |
|
268 |
using (var gateNew = NetworkGate.Acquire(newPath,NetworkOperation.Renaming)) |
|
269 |
using (new SessionScope(FlushAction.Auto)) |
|
270 |
{ |
|
271 |
if (isFile) |
|
272 |
(previousFile as FileInfo).MoveTo(newPath); |
|
273 |
else |
|
274 |
{ |
|
275 |
(previousFile as DirectoryInfo).MoveTo(newPath); |
|
276 |
} |
|
277 |
var state = StatusKeeper.GetStateByFilePath(previousFullPath); |
|
278 |
state.FilePath = newPath; |
|
279 |
state.SaveCopy(); |
|
280 |
StatusKeeper.SetFileState(previousFullPath,FileStatus.Deleted,FileOverlayStatus.Deleted); |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
224 | 284 |
private async Task SyncFiles(AccountInfo accountInfo,CloudAction action) |
225 | 285 |
{ |
226 | 286 |
if (accountInfo == null) |
Also available in: Unified diff