diff options
| author | Bond_009 <bond.009@outlook.com> | 2019-01-27 17:00:17 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2019-01-27 17:00:17 +0100 |
| commit | ffe79c89829fb232e8ccb4ae4caf4b732ce51600 (patch) | |
| tree | 6938e3f5ebae59fe4baec81e4583abbef3371dae /Emby.Server.Implementations/Library/LibraryManager.cs | |
| parent | 1a3543e5a5984d4ec5284f43b7df63a9d19c8a9c (diff) | |
Check if file exists instead of catching exceptions
Diffstat (limited to 'Emby.Server.Implementations/Library/LibraryManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Library/LibraryManager.cs | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index ad070ed79..9688ab385 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -395,38 +395,33 @@ namespace Emby.Server.Implementations.Library foreach (var fileSystemInfo in item.GetDeletePaths().ToList()) { - try + if (File.Exists(fileSystemInfo.FullName)) { - _logger.LogDebug("Deleting path {path}", fileSystemInfo.FullName); - if (fileSystemInfo.IsDirectory) + try { - _fileSystem.DeleteDirectory(fileSystemInfo.FullName, true); + _logger.LogDebug("Deleting path {path}", fileSystemInfo.FullName); + if (fileSystemInfo.IsDirectory) + { + _fileSystem.DeleteDirectory(fileSystemInfo.FullName, true); + } + else + { + _fileSystem.DeleteFile(fileSystemInfo.FullName); + } } - else + catch (IOException) { - _fileSystem.DeleteFile(fileSystemInfo.FullName); + if (isRequiredForDelete) + { + throw; + } } - } - catch (FileNotFoundException) - { - // may have already been deleted manually by user - } - catch (DirectoryNotFoundException) - { - // may have already been deleted manually by user - } - catch (IOException) - { - if (isRequiredForDelete) - { - throw; - } - } - catch (UnauthorizedAccessException) - { - if (isRequiredForDelete) + catch (UnauthorizedAccessException) { - throw; + if (isRequiredForDelete) + { + throw; + } } } |
