Skip to content

Commit 4e665b3

Browse files
committed
Expose logic for finding local cache path
Needed so that FileSystemProvider can override the default behavior, since it doesn't use the same cache logic as other providers.
1 parent c0de1fc commit 4e665b3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/LibraryManager/Providers/BaseProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ protected async Task<ILibraryOperationResult> WriteToFilesAsync(ILibraryInstalla
387387
/// Gets the expected local path for a file from the file cache
388388
/// </summary>
389389
/// <returns></returns>
390-
private string GetCachedFileLocalPath(ILibraryInstallationState state, string sourceFile)
390+
protected virtual string GetCachedFileLocalPath(ILibraryInstallationState state, string sourceFile)
391391
{
392392
return Path.Combine(CacheFolder, state.Name, state.Version, sourceFile.Trim('/'));
393393
}

src/LibraryManager/Providers/FileSystem/FileSystemProvider.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,28 @@ protected override string GetDownloadUrl(ILibraryInstallationState state, string
206206
{
207207
throw new NotSupportedException();
208208
}
209+
210+
protected override string GetCachedFileLocalPath(ILibraryInstallationState state, string sourceFile)
211+
{
212+
// FileSystemProvider pulls files directly, no caching. So here we need to build a full
213+
// path or URI to the file.
214+
215+
// For HTTP files, the state.Name is the full URL to a single file
216+
if (FileHelpers.IsHttpUri(state.Name))
217+
{
218+
return state.Name;
219+
}
220+
221+
// For other filesystem libraries, the state.Name may be a either a file or folder
222+
// TODO: abstract file system
223+
if (File.Exists(state.Name))
224+
{
225+
return state.Name;
226+
}
227+
228+
// as a fallback, assume state.Name is a directory. If this path doesn't exist, it will
229+
// be handled elsewhere.
230+
return Path.Combine(state.Name, sourceFile);
231+
}
209232
}
210233
}

0 commit comments

Comments
 (0)