Handle exceptions when clearing temp files BECAUSE NO ONE REPORTED IT

This commit is contained in:
Brant Martin
2019-09-25 17:36:16 -04:00
parent 792151a8b7
commit e4ad517cb1

View File

@@ -35,8 +35,21 @@ namespace Torch.Managers
private void ClearTemp()
{
foreach (var file in Directory.GetFiles(TempDirectory, "*", SearchOption.AllDirectories))
{
try
{
File.Delete(file);
}
catch (UnauthorizedAccessException)
{
_log.Debug($"Failed to delete file {file}, it's probably in use by another process'");
}
catch (Exception ex)
{
_log.Warn($"Unhandled exception when clearing temp files. You may ignore this. {ex}");
}
}
}
/// <summary>
/// Move the given file (if it exists) to a temporary directory that will be cleared the next time the application starts.