- if (action == null)
- throw new ArgumentNullException("action");
- Contract.EndContractBlock();
-
- try
- {
- if (action == null)
- throw new ArgumentNullException("action");
- Contract.EndContractBlock();
-
- var accountInfo=action.AccountInfo;
-
- var fileInfo=action.LocalFile;
-
- if (fileInfo.Extension.Equals("ignore", StringComparison.InvariantCultureIgnoreCase))
- return;
-
- var relativePath = fileInfo.AsRelativeTo(accountInfo.AccountPath);
- if (relativePath.StartsWith(FolderConstants.OthersFolder))
- {
- var parts=relativePath.Split('\\');
- var accountName = parts[1];
- var oldName = accountInfo.UserName;
- var absoluteUri = accountInfo.StorageUri.AbsoluteUri;
- var nameIndex=absoluteUri.IndexOf(oldName);
- var root=absoluteUri.Substring(0, nameIndex);
-
- accountInfo = new AccountInfo
- {
- UserName = accountName,
- AccountPath = Path.Combine(accountInfo.AccountPath, parts[0], parts[1]),
- StorageUri = new Uri(root + accountName),
- BlockHash=accountInfo.BlockHash,
- BlockSize=accountInfo.BlockSize,
- Token=accountInfo.Token
- };
- }
-
-
- var fullFileName = fileInfo.FullName;
- using(var gate=NetworkGate.Acquire(fullFileName,NetworkOperation.Uploading))
- {
- //Abort if the file is already being uploaded or downloaded
- if (gate.Failed)
- return;
-
- var cloudFile = action.CloudFile;
- var account = cloudFile.Account ?? accountInfo.UserName;
-
- var client = new CloudFilesClient(accountInfo);
- //Even if GetObjectInfo times out, we can proceed with the upload
- var info = client.GetObjectInfo(account, cloudFile.Container, cloudFile.Name);
- var cloudHash = info.Hash.ToLower();
-
- var hash = action.LocalHash.Value;
- var topHash = action.TopHash.Value;
-
- //If the file hashes match, abort the upload
- if (hash == cloudHash || topHash ==cloudHash)
- {
- //but store any metadata changes
- this.StatusKeeper.StoreInfo(fullFileName, info);
- Log.InfoFormat("Skip upload of {0}, hashes match", fullFileName);
- return;
- }
-
- if (info.AllowedTo=="read")
- return;
-
- //Mark the file as modified while we upload it
- StatusKeeper.SetFileOverlayStatus(fullFileName, FileOverlayStatus.Modified);
- //And then upload it
-
- //Upload even small files using the Hashmap. The server may already containt
- //the relevant folder