Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions csharp/autogen/src/HTTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ protected TooManyRedirectsException(SerializationInfo info, StreamingContext con
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
throw new ArgumentNullException(nameof(info));

info.AddValue("redirect", redirect);
info.AddValue("uri", uri, typeof(Uri));
Expand Down Expand Up @@ -773,11 +771,29 @@ public static void Put(UpdateProgressDelegate progressDelegate, FuncBool cancell
public static void Get(DataCopiedDelegate dataCopiedDelegate, FuncBool cancellingDelegate,
Uri uri, IWebProxy proxy, string path, int timeoutMs)
{
string tmpFile = Path.GetTempFileName();
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException(nameof(path));

var tmpFile = Path.GetTempFileName();

if (Path.GetPathRoot(path) != Path.GetPathRoot(tmpFile))
{
//CA-365905: if the target path is under a root different from
//the temp file, use instead a temp file under the target root,
//otherwise there may not be enough space for the download

var dir = Path.GetDirectoryName(path);
if (dir == null) //path is root directory
throw new ArgumentException(nameof(path));

tmpFile = Path.Combine(dir, Path.GetRandomFileName());
File.Delete(tmpFile);
}

try
{
using (Stream fileStream = new FileStream(tmpFile, FileMode.Create, FileAccess.Write, FileShare.None),
downloadStream = HttpGetStream(uri, proxy, timeoutMs))
downloadStream = HttpGetStream(uri, proxy, timeoutMs))
{
CopyStream(downloadStream, fileStream, dataCopiedDelegate, cancellingDelegate);
fileStream.Flush();
Expand Down