From 3111e787ef4cb6efb8f831a92d40e76b5ae356f7 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Sun, 6 Jun 2021 15:42:30 -0600 Subject: [PATCH] Catch and abort on out-of-space exceptions when allocating files #220 --- DepotDownloader/ContentDownloader.cs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index cbf38b9..31d354a 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -1055,7 +1055,14 @@ namespace DepotDownloader // create new file. need all chunks fs = File.Create(fileFinalPath); - fs.SetLength((long)file.TotalSize); + try + { + fs.SetLength((long)file.TotalSize); + } + catch (IOException ex) + { + throw new ContentDownloaderException(String.Format("Failed to allocate file {0}: {1}", fileFinalPath, ex.Message)); + } neededChunks = new List(file.Chunks); } else @@ -1099,7 +1106,14 @@ namespace DepotDownloader File.Move(fileFinalPath, fileStagingPath); fs = File.Open(fileFinalPath, FileMode.Create); - fs.SetLength((long)file.TotalSize); + try + { + fs.SetLength((long)file.TotalSize); + } + catch (IOException ex) + { + throw new ContentDownloaderException(String.Format("Failed to resize file to expected size {0}: {1}", fileFinalPath, ex.Message)); + } using (var fsOld = File.Open(fileStagingPath, FileMode.Open)) { @@ -1133,7 +1147,14 @@ namespace DepotDownloader fs = File.Open(fileFinalPath, FileMode.Open); if ((ulong)fi.Length != file.TotalSize) { - fs.SetLength((long)file.TotalSize); + try + { + fs.SetLength((long)file.TotalSize); + } + catch (IOException ex) + { + throw new ContentDownloaderException(String.Format("Failed to allocate file {0}: {1}", fileFinalPath, ex.Message)); + } } Console.WriteLine("Validating {0}", fileFinalPath);