From f2f5d4c0a69ea714d74fc13f5dca9af47cc2c028 Mon Sep 17 00:00:00 2001 From: Tyler Gill Date: Sat, 2 Jun 2018 15:52:20 -0600 Subject: [PATCH] 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). --- .../Backend/OneDrive/MicrosoftGraphBackend.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs b/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs index b3e0d6b13..ebf9a92a6 100644 --- a/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs +++ b/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs @@ -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); } }