var fileAgent = GetFileAgent(accountInfo);
foreach (var trashObject in trashObjects)
{
- var relativePath = trashObject.RelativeUrlToFilePath(accountInfo.UserName);
- //and remove any matching objects from the list, adding them to the commonObjects list
+ var barePath = trashObject.RelativeUrlToFilePath(accountInfo.UserName);
+ //HACK: Assume only the "pithos" container is used. Must find out what happens when
+ //deleting a file from a different container
+ var relativePath = Path.Combine("pithos", barePath);
fileAgent.Delete(relativePath);
}
}
try
{
if (action == null)
- throw new ArgumentNullException("action");
+ throw new ArgumentNullException("action");
Contract.EndContractBlock();
- var accountInfo=action.AccountInfo;
-
- var fileInfo=action.LocalFile;
+ 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 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);
+ 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
+ BlockHash = accountInfo.BlockHash,
+ BlockSize = accountInfo.BlockSize,
+ Token = accountInfo.Token
};
}
var fullFileName = fileInfo.FullName;
- using(var gate=NetworkGate.Acquire(fullFileName,NetworkOperation.Uploading))
+ using (var gate = NetworkGate.Acquire(fullFileName, NetworkOperation.Uploading))
{
//Abort if the file is already being uploaded or downloaded
if (gate.Failed)
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 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)
+ if (hash == cloudHash || topHash == cloudHash)
{
//but store any metadata changes
this.StatusKeeper.StoreInfo(fullFileName, info);
return;
}
- if (info.AllowedTo=="read")
+ if (info.AllowedTo == "read")
return;
//Mark the file as modified while we upload it
//First, calculate the tree hash
var treeHash = await Signature.CalculateTreeHashAsync(fileInfo.FullName, accountInfo.BlockSize,
- accountInfo.BlockHash);
-
- await UploadWithHashMap(accountInfo,cloudFile,fileInfo,cloudFile.Name,treeHash);
+ accountInfo.BlockHash);
+
+ await UploadWithHashMap(accountInfo, cloudFile, fileInfo, cloudFile.Name, treeHash);
//If everything succeeds, change the file and overlay status to normal
this.StatusKeeper.SetFileState(fullFileName, FileStatus.Unchanged, FileOverlayStatus.Normal);
var exc = ex.InnerException as WebException;
if (exc == null)
throw ex.InnerException;
- var response = exc.Response as HttpWebResponse;
- if (response == null)
- throw exc;
- if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- Log.Error("Not allowed to upload file", exc);
- var message = String.Format("Not allowed to uplad file {0}", action.LocalFile.FullName);
- StatusKeeper.SetFileState(action.LocalFile.FullName, FileStatus.Unchanged, FileOverlayStatus.Normal);
- StatusNotification.NotifyChange(message, TraceLevel.Warning);
+ if (HandleUploadWebException(action, exc))
return;
- }
+ throw;
+ }
+ catch (WebException ex)
+ {
+ if (HandleUploadWebException(action, ex))
+ return;
+ throw;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("Unexpected error while uploading file", ex);
throw;
}
}
+ private bool HandleUploadWebException(CloudAction action, WebException exc)
+ {
+ var response = exc.Response as HttpWebResponse;
+ if (response == null)
+ throw exc;
+ if (response.StatusCode == HttpStatusCode.Unauthorized)
+ {
+ Log.Error("Not allowed to upload file", exc);
+ var message = String.Format("Not allowed to uplad file {0}", action.LocalFile.FullName);
+ StatusKeeper.SetFileState(action.LocalFile.FullName, FileStatus.Unchanged, FileOverlayStatus.Normal);
+ StatusNotification.NotifyChange(message, TraceLevel.Warning);
+ return true;
+ }
+ return false;
+ }
+
public async Task UploadWithHashMap(AccountInfo accountInfo,ObjectInfo cloudFile,FileInfo fileInfo,string url,TreeHash treeHash)
{
if (accountInfo == null)