Skip to content

Commit 4360e10

Browse files
authored
Resolve bug when VC incompletely download remote profile (#226)
1 parent 4950f85 commit 4360e10

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/VirtualClient/VirtualClient.Main/RunProfileCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,16 @@ protected async Task<IEnumerable<string>> InitializeProfilesAsync(IServiceCollec
447447
string profileFullPath = null;
448448
if (path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
449449
{
450+
// The profile downloaded from internet will live in /profiles/downloaded/ directory and not interfere with the ones in the repo.
450451
var profileUri = new Uri(path);
451452
string profileName = Path.GetFileName(profileUri.AbsolutePath);
452-
profileFullPath = systemManagement.PlatformSpecifics.GetProfilePath(profileName);
453+
profileFullPath = systemManagement.PlatformSpecifics.GetProfilePath("downloaded", profileName);
454+
455+
string downloadDirectory = Path.GetDirectoryName(profileFullPath);
456+
if (!fileSystem.Directory.Exists(downloadDirectory))
457+
{
458+
fileSystem.Directory.CreateDirectory(downloadDirectory);
459+
}
453460

454461
if (!pathsOnly)
455462
{
@@ -458,7 +465,7 @@ protected async Task<IEnumerable<string>> InitializeProfilesAsync(IServiceCollec
458465
await Policy.Handle<Exception>().WaitAndRetryAsync(5, (retries) => TimeSpan.FromSeconds(retries * 2)).ExecuteAsync(async () =>
459466
{
460467
var response = await client.GetAsync(profileUri);
461-
using (var fs = new FileStream(profileFullPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
468+
using (var fs = new FileStream(profileFullPath, FileMode.Create, FileAccess.Write, FileShare.Write))
462469
{
463470
await response.Content.CopyToAsync(fs);
464471
}

0 commit comments

Comments
 (0)