Revision b666b39a trunk/Pithos.Core/Agents/PollAgent.cs

b/trunk/Pithos.Core/Agents/PollAgent.cs
270 270
                        
271 271

  
272 272
                        //Create a list of actions from the remote files
273
                        var allActions = ChangesToActions(accountInfo, differencer.Changed.FilterDirectlyBelow(SelectiveUris))
273
                        var allActions = MovesToActions(accountInfo,differencer.Moved.FilterDirectlyBelow(SelectiveUris))
274
                                        .Union(
275
                                        ChangesToActions(accountInfo, differencer.Changed.FilterDirectlyBelow(SelectiveUris)))
274 276
                                        .Union(
275 277
                                        CreatesToActions(accountInfo, differencer.Created.FilterDirectlyBelow(SelectiveUris)));
276 278

  
......
379 381

  
380 382
        }
381 383

  
382
        //Creates an appropriate action for each server file
384
        /// <summary>
385
        /// Creates a Sync action for each changed server file
386
        /// </summary>
387
        /// <param name="accountInfo"></param>
388
        /// <param name="changes"></param>
389
        /// <returns></returns>
383 390
        private IEnumerable<CloudAction> ChangesToActions(AccountInfo accountInfo, IEnumerable<ObjectInfo> changes)
384 391
        {
385 392
            if (changes == null)
......
392 399
            foreach (var objectInfo in changes)
393 400
            {
394 401
                var relativePath = objectInfo.RelativeUrlToFilePath(accountInfo.UserName);
395
                //and remove any matching objects from the list, adding them to the commonObjects list
402
                //If a directory object already exists, we may need to sync it
396 403
                if (fileAgent.Exists(relativePath))
397 404
                {
398
                    //If a directory object already exists, we don't need to perform any other action                    
399 405
                    var localFile = fileAgent.GetFileSystemInfo(relativePath);
406
                    //We don't need to sync directories
400 407
                    if (objectInfo.Content_Type == @"application/directory" && localFile is DirectoryInfo)
401 408
                        continue;
402 409
                    using (new SessionScope(FlushAction.Never))
......
418 425
            }
419 426
        }
420 427

  
428
        /// <summary>
429
        /// Creates a Local Move action for each moved server file
430
        /// </summary>
431
        /// <param name="accountInfo"></param>
432
        /// <param name="moves"></param>
433
        /// <returns></returns>
434
        private IEnumerable<CloudAction> MovesToActions(AccountInfo accountInfo, IEnumerable<ObjectInfo> moves)
435
        {
436
            if (moves == null)
437
                throw new ArgumentNullException();
438
            Contract.EndContractBlock();
439
            var fileAgent = FileAgent.GetFileAgent(accountInfo);
440

  
441
            //In order to avoid multiple iterations over the files, we iterate only once
442
            //over the remote files
443
            foreach (var objectInfo in moves)
444
            {
445
                var previousRelativepath = objectInfo.Previous.RelativeUrlToFilePath(accountInfo.UserName);
446
                //If the previous file already exists, we can execute a Move operation
447
                if (fileAgent.Exists(previousRelativepath))
448
                {
449
                    var previousFile = fileAgent.GetFileSystemInfo(previousRelativepath);
450
                    using (new SessionScope(FlushAction.Never))
451
                    {
452
                        var state = StatusKeeper.GetStateByFilePath(previousFile.FullName);
453
                        _lastSeen[previousFile.FullName] = DateTime.Now;
454

  
455
                        //For each moved object we need to move both the local file and update                                                
456
                        yield return new CloudAction(accountInfo, CloudActionType.RenameLocal,
457
                                                     previousFile, objectInfo, state, accountInfo.BlockSize,
458
                                                     accountInfo.BlockHash);
459
                        //For modified files, we need to download the changes as well
460
                        if (objectInfo.Hash!=objectInfo.PreviousHash)
461
                            yield return new CloudDownloadAction(accountInfo,objectInfo);
462
                    }
463
                }
464
                //If the previous file does not exist, we need to download it in the new location
465
                else
466
                {
467
                    //Remote files should be downloaded
468
                    yield return new CloudDownloadAction(accountInfo, objectInfo);
469
                }
470
            }
471
        }
472

  
473

  
474
        /// <summary>
475
        /// Creates a download action for each new server file
476
        /// </summary>
477
        /// <param name="accountInfo"></param>
478
        /// <param name="creates"></param>
479
        /// <returns></returns>
421 480
        private IEnumerable<CloudAction> CreatesToActions(AccountInfo accountInfo, IEnumerable<ObjectInfo> creates)
422 481
        {
423 482
            if (creates == null)
......
430 489
            foreach (var objectInfo in creates)
431 490
            {
432 491
                var relativePath = objectInfo.RelativeUrlToFilePath(accountInfo.UserName);
433
                //and remove any matching objects from the list, adding them to the commonObjects list
492
                //If the object already exists, we probably have a conflict
434 493
                if (fileAgent.Exists(relativePath))
435 494
                {
436
                    //If the object already exists, we probably have a conflict
437 495
                    //If a directory object already exists, we don't need to perform any other action                    
438 496
                    var localFile = fileAgent.GetFileSystemInfo(relativePath);
439 497
                    StatusKeeper.SetFileState(localFile.FullName, FileStatus.Conflict, FileOverlayStatus.Conflict);

Also available in: Unified diff