Change from swallowing delete errors to wrapping DriveItemNotFoundException in FileMissingException.

This way, the regular backend manager logic can handle and log the delete of a non-existant file.
Also update some of the other operations to throw FileMissingException (rather than the backend specific DriveItemNotFoundException).
This commit is contained in:
Tyler Gill
2018-06-02 15:52:20 -06:00
parent 8131e85581
commit f2f5d4c0a6
@@ -294,17 +294,33 @@ namespace Duplicati.Library.Backend
public void Get(string remotename, Stream stream)
{
var response = this.m_client.GetAsync(string.Format("{0}/root:{1}{2}:/content", this.DrivePrefix, this.m_path, NormalizeSlashes(remotename))).Await();
this.CheckResponse(response);
using (Stream responseStream = response.Content.ReadAsStreamAsync().Await())
try
{
responseStream.CopyTo(stream);
var response = this.m_client.GetAsync(string.Format("{0}/root:{1}{2}:/content", this.DrivePrefix, this.m_path, NormalizeSlashes(remotename))).Await();
this.CheckResponse(response);
using (Stream responseStream = response.Content.ReadAsStreamAsync().Await())
{
responseStream.CopyTo(stream);
}
}
catch (DriveItemNotFoundException ex)
{
// If the item wasn't found, wrap the exception so normal handling can occur.
throw new FileMissingException(ex);
}
}
public void Rename(string oldname, string newname)
{
this.Patch(string.Format("{0}/root:{1}{2}", this.DrivePrefix, this.m_path, NormalizeSlashes(oldname)), new DriveItem() { Name = newname });
try
{
this.Patch(string.Format("{0}/root:{1}{2}", this.DrivePrefix, this.m_path, NormalizeSlashes(oldname)), new DriveItem() { Name = newname });
}
catch (DriveItemNotFoundException ex)
{
// If the item wasn't found, wrap the exception so normal handling can occur.
throw new FileMissingException(ex);
}
}
public void Put(string remotename, string filename)
@@ -418,9 +434,10 @@ namespace Duplicati.Library.Backend
{
this.CheckResponse(response);
}
catch (DriveItemNotFoundException)
catch (DriveItemNotFoundException ex)
{
// If the item doesn't exist, then attempting to delete it shouldn't fail.
// Wrap the existing item not found error in a 'FolderMissingException'
throw new FileMissingException(ex);
}
}