Catch and abort on out-of-space exceptions when allocating files #220

pull/225/head
Ryan Kistner 5 years ago
parent 08b7911d2d
commit 3111e787ef

@ -1055,7 +1055,14 @@ namespace DepotDownloader
// create new file. need all chunks // create new file. need all chunks
fs = File.Create(fileFinalPath); 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<ProtoManifest.ChunkData>(file.Chunks); neededChunks = new List<ProtoManifest.ChunkData>(file.Chunks);
} }
else else
@ -1099,7 +1106,14 @@ namespace DepotDownloader
File.Move(fileFinalPath, fileStagingPath); File.Move(fileFinalPath, fileStagingPath);
fs = File.Open(fileFinalPath, FileMode.Create); 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)) using (var fsOld = File.Open(fileStagingPath, FileMode.Open))
{ {
@ -1133,7 +1147,14 @@ namespace DepotDownloader
fs = File.Open(fileFinalPath, FileMode.Open); fs = File.Open(fileFinalPath, FileMode.Open);
if ((ulong)fi.Length != file.TotalSize) 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); Console.WriteLine("Validating {0}", fileFinalPath);

Loading…
Cancel
Save