Skip to content

Commit 0bbf3e9

Browse files
committed
Fix another case better solved via GoalState
1 parent 31a538d commit 0bbf3e9

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/LibraryManager/Providers/FileSystem/FileSystemProvider.cs

+11-19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading;
1010
using System.Threading.Tasks;
1111
using Microsoft.Web.LibraryManager.Contracts;
12+
using Microsoft.Web.LibraryManager.Helpers;
1213
using Microsoft.Web.LibraryManager.LibraryNaming;
1314
using Microsoft.Web.LibraryManager.Resources;
1415

@@ -73,25 +74,25 @@ public override async Task<OperationResult<LibraryInstallationGoalState>> Instal
7374
return goalStateResult;
7475
}
7576

76-
foreach (string file in desiredState.Files)
77+
foreach ((string destFile, string sourceFile) in goalStateResult.Result.InstalledFiles)
7778
{
7879
if (cancellationToken.IsCancellationRequested)
7980
{
8081
return OperationResult<LibraryInstallationGoalState>.FromCancelled(goalStateResult.Result);
8182
}
8283

83-
if (string.IsNullOrEmpty(file))
84+
if (string.IsNullOrEmpty(destFile))
8485
{
85-
return OperationResult<LibraryInstallationGoalState>.FromError(PredefinedErrors.CouldNotWriteFile(file));
86+
return OperationResult<LibraryInstallationGoalState>.FromError(PredefinedErrors.CouldNotWriteFile(destFile));
8687
}
8788

88-
string path = Path.Combine(desiredState.DestinationPath, file);
89-
var sourceStream = new Func<Stream>(() => GetStreamAsync(desiredState, file, cancellationToken).Result);
90-
bool writeOk = await HostInteraction.WriteFileAsync(path, sourceStream, desiredState, cancellationToken).ConfigureAwait(false);
89+
string libraryName = LibraryNamingScheme.GetLibraryId(desiredState.Name, desiredState.Version);
90+
var sourceStream = new Func<Stream>(() => GetStreamAsync(sourceFile, libraryName, cancellationToken).Result);
91+
bool writeOk = await HostInteraction.WriteFileAsync(destFile, sourceStream, desiredState, cancellationToken).ConfigureAwait(false);
9192

9293
if (!writeOk)
9394
{
94-
return OperationResult<LibraryInstallationGoalState>.FromError(PredefinedErrors.CouldNotWriteFile(file));
95+
return OperationResult<LibraryInstallationGoalState>.FromError(PredefinedErrors.CouldNotWriteFile(destFile));
9596
}
9697
}
9798

@@ -135,10 +136,8 @@ public override string GetSuggestedDestination(ILibrary library)
135136
return string.Empty;
136137
}
137138

138-
private async Task<Stream> GetStreamAsync(ILibraryInstallationState state, string file, CancellationToken cancellationToken)
139+
private async Task<Stream> GetStreamAsync(string sourceFile, string libraryName, CancellationToken cancellationToken)
139140
{
140-
string sourceFile = state.Name;
141-
142141
try
143142
{
144143
if (!Uri.TryCreate(sourceFile, UriKind.RelativeOrAbsolute, out Uri url))
@@ -154,14 +153,7 @@ private async Task<Stream> GetStreamAsync(ILibraryInstallationState state, strin
154153
// File
155154
if (url.IsFile)
156155
{
157-
if (Directory.Exists(url.OriginalString))
158-
{
159-
return await FileHelpers.ReadFileAsStreamAsync(Path.Combine(url.OriginalString, file), cancellationToken).ConfigureAwait(false);
160-
}
161-
else
162-
{
163-
return await FileHelpers.ReadFileAsStreamAsync(sourceFile, cancellationToken).ConfigureAwait(false);
164-
}
156+
return await FileHelpers.ReadFileAsStreamAsync(sourceFile, cancellationToken).ConfigureAwait(false);
165157
}
166158
// Url
167159
else
@@ -175,7 +167,7 @@ private async Task<Stream> GetStreamAsync(ILibraryInstallationState state, strin
175167
}
176168
catch (Exception)
177169
{
178-
throw new InvalidLibraryException(state.Name, state.ProviderId);
170+
throw new InvalidLibraryException(libraryName, Id);
179171
}
180172
}
181173

0 commit comments

Comments
 (0)