Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 8cd7d87

Browse files
committed
CA-365905 (XSI-1215): Create a temporary file in the target download folder instead of the user's temp...
... folder if the latter is in a different drive from the target folder. Signed-off-by: Konstantina Chremmou <[email protected]>
1 parent 271b9c1 commit 8cd7d87

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

csharp/autogen/src/HTTP.cs

+21-5
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ protected TooManyRedirectsException(SerializationInfo info, StreamingContext con
7575
public override void GetObjectData(SerializationInfo info, StreamingContext context)
7676
{
7777
if (info == null)
78-
{
79-
throw new ArgumentNullException("info");
80-
}
78+
throw new ArgumentNullException(nameof(info));
8179

8280
info.AddValue("redirect", redirect);
8381
info.AddValue("uri", uri, typeof(Uri));
@@ -773,11 +771,29 @@ public static void Put(UpdateProgressDelegate progressDelegate, FuncBool cancell
773771
public static void Get(DataCopiedDelegate dataCopiedDelegate, FuncBool cancellingDelegate,
774772
Uri uri, IWebProxy proxy, string path, int timeoutMs)
775773
{
776-
string tmpFile = Path.GetTempFileName();
774+
if (string.IsNullOrWhiteSpace(path))
775+
throw new ArgumentException(nameof(path));
776+
777+
var tmpFile = Path.GetTempFileName();
778+
779+
if (Path.GetPathRoot(path) != Path.GetPathRoot(tmpFile))
780+
{
781+
//CA-365905: if the target path is under a root different from
782+
//the temp file, use instead a temp file under the target root,
783+
//otherwise there may not be enough space for the download
784+
785+
var dir = Path.GetDirectoryName(path);
786+
if (dir == null) //path is root directory
787+
throw new ArgumentException(nameof(path));
788+
789+
tmpFile = Path.Combine(dir, Path.GetRandomFileName());
790+
File.Delete(tmpFile);
791+
}
792+
777793
try
778794
{
779795
using (Stream fileStream = new FileStream(tmpFile, FileMode.Create, FileAccess.Write, FileShare.None),
780-
downloadStream = HttpGetStream(uri, proxy, timeoutMs))
796+
downloadStream = HttpGetStream(uri, proxy, timeoutMs))
781797
{
782798
CopyStream(downloadStream, fileStream, dataCopiedDelegate, cancellingDelegate);
783799
fileStream.Flush();

0 commit comments

Comments
 (0)