Skip to content

Commit

Permalink
Expose logic for finding local cache path
Browse files Browse the repository at this point in the history
Needed so that FileSystemProvider can override the default behavior, since it doesn't use the same cache logic as other providers.
  • Loading branch information
jimmylewis committed May 1, 2024
1 parent 01cf3fb commit ecb6c92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/LibraryManager/Providers/BaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ protected async Task<ILibraryOperationResult> WriteToFilesAsync(ILibraryInstalla
/// Gets the expected local path for a file from the file cache
/// </summary>
/// <returns></returns>
private string GetCachedFileLocalPath(ILibraryInstallationState state, string sourceFile)
protected virtual string GetCachedFileLocalPath(ILibraryInstallationState state, string sourceFile)
{
return Path.Combine(CacheFolder, state.Name, state.Version, sourceFile.Trim('/'));
}
Expand Down
23 changes: 23 additions & 0 deletions src/LibraryManager/Providers/FileSystem/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,28 @@ protected override string GetDownloadUrl(ILibraryInstallationState state, string
{
throw new NotSupportedException();
}

protected override string GetCachedFileLocalPath(ILibraryInstallationState state, string sourceFile)
{
// FileSystemProvider pulls files directly, no caching. So here we need to build a full
// path or URI to the file.

// For HTTP files, the state.Name is the full URL to a single file
if (FileHelpers.IsHttpUri(state.Name))
{
return state.Name;
}

// For other filesystem libraries, the state.Name may be a either a file or folder
// TODO: abstract file system
if (File.Exists(state.Name))
{
return state.Name;
}

// as a fallback, assume state.Name is a directory. If this path doesn't exist, it will
// be handled elsewhere.
return Path.Combine(state.Name, sourceFile);
}
}
}

0 comments on commit ecb6c92

Please sign in to comment.