Skip to content

Commit

Permalink
Merge pull request #2095 from itowlson/local-loader-cache-control
Browse files Browse the repository at this point in the history
Allow hosts to control local loader download cache
  • Loading branch information
itowlson authored Nov 14, 2023
2 parents 273c684 + 155c472 commit 3d9d266
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crates/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ pub(crate) const MAX_FILE_LOADING_CONCURRENCY: usize = 16;
pub async fn from_file(
manifest_path: impl AsRef<Path>,
files_mount_strategy: FilesMountStrategy,
cache_root: Option<PathBuf>,
) -> Result<LockedApp> {
let path = manifest_path.as_ref();
let app_root = parent_dir(path)?;
let loader = LocalLoader::new(&app_root, files_mount_strategy).await?;
let loader = LocalLoader::new(&app_root, files_mount_strategy, cache_root).await?;
loader.load_file(path).await
}

Expand Down
8 changes: 6 additions & 2 deletions crates/loader/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ pub struct LocalLoader {
}

impl LocalLoader {
pub async fn new(app_root: &Path, files_mount_strategy: FilesMountStrategy) -> Result<Self> {
pub async fn new(
app_root: &Path,
files_mount_strategy: FilesMountStrategy,
cache_root: Option<PathBuf>,
) -> Result<Self> {
let app_root = app_root
.canonicalize()
.with_context(|| format!("Invalid manifest dir `{}`", app_root.display()))?;
Ok(Self {
app_root,
files_mount_strategy,
cache: Cache::new(None).await?,
cache: Cache::new(cache_root).await?,
// Limit concurrency to avoid hitting system resource limits
file_loading_permits: Semaphore::new(crate::MAX_FILE_LOADING_CONCURRENCY),
})
Expand Down
1 change: 1 addition & 0 deletions crates/loader/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn run_test(input: &Path, normalizer: &mut Normalizer) -> Result<String, Failed>
let locked = spin_loader::from_file(
input,
spin_loader::FilesMountStrategy::Copy(files_mount_root),
None,
)
.await
.map_err(|err| format!("{err:?}"))?;
Expand Down
1 change: 1 addition & 0 deletions crates/oci/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl Client {
let locked = spin_loader::from_file(
manifest_path,
FilesMountStrategy::Copy(working_dir.path().into()),
None,
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl UpCommand {
} else {
FilesMountStrategy::Copy(working_dir.join("assets"))
};
spin_loader::from_file(&manifest_path, files_mount_strategy)
spin_loader::from_file(&manifest_path, files_mount_strategy, None)
.await
.with_context(|| format!("Failed to load manifest from {manifest_path:?}"))
}
Expand Down

0 comments on commit 3d9d266

Please sign in to comment.