Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Clone repository
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Install rust
uses: dsherret/rust-toolchain-file@v1
Expand All @@ -39,15 +39,6 @@ jobs:
- name: Test
run: cargo test

- name: Cargo publish
if: |
contains(matrix.os, 'ubuntu') &&
github.repository == 'denoland/deno_cache_dir' &&
startsWith(github.ref, 'refs/tags/')
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish -p deno_cache_dir

deno:
name: deno_cache_dir-deno
if: |
Expand All @@ -61,7 +52,7 @@ jobs:

steps:
- name: Clone repository
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Install rust
uses: dsherret/rust-toolchain-file@v1
- uses: Swatinem/rust-cache@v2
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: publish

on:
push:
tags:
- "*"

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Clone repository
uses: actions/checkout@v5
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Clone repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
token: ${{ secrets.DENOBOT_PAT }}

Expand All @@ -36,4 +36,4 @@ jobs:
run: |
git config user.email "denobot@users.noreply.github.com"
git config user.name "denobot"
deno run -A https://raw.githubusercontent.com/denoland/automation/0.20.0/tasks/publish_release.ts --${{github.event.inputs.releaseKind}} deno_cache_dir
deno run -A jsr:@deno/rust-automation@0.22.0/publish-release --${{github.event.inputs.releaseKind}} deno_cache_dir
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
max_width = 80
tab_spaces = 2
edition = "2021"
edition = "2024"
4 changes: 2 additions & 2 deletions rs_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "deno_cache_dir"
version = "0.25.0"
edition = "2021"
edition = "2024"
license = "MIT"
description = "Cache directory logic used in Deno"
repository = "https://github.com/denoland/deno_cache"
repository = "https://github.com/denoland/deno_cache_dir"

[lib]
crate-type = ["cdylib", "lib"]
Expand Down
10 changes: 0 additions & 10 deletions rs_lib/clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ disallowed-methods = [
{ path = "std::path::Path::read_link", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::Path::symlink_metadata", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::Path::try_exists", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::exists", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::canonicalize", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::is_dir", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::is_file", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::is_symlink", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::metadata", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::read_dir", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::read_link", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::symlink_metadata", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::path::PathBuf::try_exists", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::env::set_current_dir", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::env::temp_dir", reason = "File system operations should be done using DenoCacheEnv trait" },
{ path = "std::fs::canonicalize", reason = "File system operations should be done using DenoCacheEnv trait" },
Expand Down
6 changes: 3 additions & 3 deletions rs_lib/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use std::time::SystemTime;
use thiserror::Error;
use url::Url;

use crate::GlobalHttpCacheRc;
use crate::LocalHttpCacheRc;
use crate::common::HeadersMap;
use crate::common::base_url_to_filename_parts;
use crate::common::checksum;
use crate::common::HeadersMap;
use crate::global::GlobalHttpCacheSys;
use crate::local::LocalHttpCacheSys;
use crate::sync::MaybeSend;
use crate::sync::MaybeSync;
use crate::GlobalHttpCacheRc;
use crate::LocalHttpCacheRc;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum GlobalToLocalCopy {
Expand Down
8 changes: 6 additions & 2 deletions rs_lib/src/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum DenoDirResolutionError {
#[error("Could not resolve global Deno cache directory. Please make sure that either the DENO_DIR environment variable is set or the cache directory is available.")]
#[error(
"Could not resolve global Deno cache directory. Please make sure that either the DENO_DIR environment variable is set or the cache directory is available."
)]
NoCacheOrHomeDir,
#[error("Could not resolve global Deno cache directory because the current working directory could not be resolved. Please set the DENO_DIR environment variable and ensure it is pointing at an absolute path.")]
#[error(
"Could not resolve global Deno cache directory because the current working directory could not be resolved. Please set the DENO_DIR environment variable and ensure it is pointing at an absolute path."
)]
FailedCwd {
#[source]
source: std::io::Error,
Expand Down
2 changes: 1 addition & 1 deletion rs_lib/src/file_fetcher/auth_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::net::Ipv6Addr;
use std::net::SocketAddr;
use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use base64::prelude::BASE64_STANDARD;
use log::debug;
use log::error;
use sys_traits::EnvVar;
Expand Down
32 changes: 16 additions & 16 deletions rs_lib/src/file_fetcher/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ impl CacheSemantics {
};
}

if let Some(last_modified) = self.headers.get("last-modified") {
if let Ok(last_modified) = DateTime::parse_from_rfc2822(last_modified) {
let last_modified = SystemTime::UNIX_EPOCH
+ Duration::from_secs(last_modified.timestamp().max(0) as _);
if let Ok(diff) = server_date.duration_since(last_modified) {
let secs_left = diff.as_secs() as f64 * 0.1;
return default_min_ttl.max(Duration::from_secs(secs_left as _));
}
if let Some(last_modified) = self.headers.get("last-modified")
&& let Ok(last_modified) = DateTime::parse_from_rfc2822(last_modified)
{
let last_modified = SystemTime::UNIX_EPOCH
+ Duration::from_secs(last_modified.timestamp().max(0) as _);
if let Ok(diff) = server_date.duration_since(last_modified) {
let secs_left = diff.as_secs() as f64 * 0.1;
return default_min_ttl.max(Duration::from_secs(secs_left as _));
}
}

Expand All @@ -120,16 +120,16 @@ impl CacheSemantics {
return false;
}

if let Some(max_age) = self.cache_control.max_age {
if self.age() > max_age {
return false;
}
if let Some(max_age) = self.cache_control.max_age
&& self.age() > max_age
{
return false;
}

if let Some(min_fresh) = self.cache_control.min_fresh {
if self.time_to_live() < min_fresh {
return false;
}
if let Some(min_fresh) = self.cache_control.min_fresh
&& self.time_to_live() < min_fresh
{
return false;
}

if self.is_stale() {
Expand Down
21 changes: 11 additions & 10 deletions rs_lib/src/file_fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ use thiserror::Error;
use url::Url;

use self::http_util::CacheSemantics;
use crate::cache::HttpCacheRc;
use crate::common::HeadersMap;
use crate::sync::MaybeSend;
use crate::sync::MaybeSync;
use crate::CacheEntry;
use crate::CacheReadFileError;
use crate::Checksum;
use crate::ChecksumIntegrityError;
use crate::cache::HttpCacheRc;
use crate::common::HeadersMap;
use crate::sync::MaybeSend;
use crate::sync::MaybeSync;

mod auth_tokens;
mod http_util;
Expand Down Expand Up @@ -260,7 +260,9 @@ pub struct TooManyRedirectsError(pub Url);
// before `file_fetcher.rs` APIs are even hit.
#[derive(Debug, Error, JsError)]
#[class(type)]
#[error("Unsupported scheme \"{scheme}\" for module \"{url}\". Supported schemes:\n - \"blob\"\n - \"data\"\n - \"file\"\n - \"http\"\n - \"https\"\n - \"jsr\"\n - \"npm\"")]
#[error(
"Unsupported scheme \"{scheme}\" for module \"{url}\". Supported schemes:\n - \"blob\"\n - \"data\"\n - \"file\"\n - \"http\"\n - \"https\"\n - \"jsr\"\n - \"npm\""
)]
pub struct UnsupportedSchemeError {
pub scheme: String,
pub url: Url,
Expand Down Expand Up @@ -752,12 +754,11 @@ impl<TBlobStore: BlobStore, TSys: FileFetcherSys, THttpClient: HttpClient>
) -> Result<TStrategy::ReturnValue, FetchNoFollowError> {
debug!("FileFetcher::fetch_remote_no_follow - specifier: {}", url);

if self.should_use_cache(url, cache_setting) {
if let Some(value) =
if self.should_use_cache(url, cache_setting)
&& let Some(value) =
strategy.handle_fetch_cached_no_follow(url, maybe_checksum)?
{
return Ok(value);
}
{
return Ok(value);
}

if *cache_setting == CacheSetting::Only {
Expand Down
4 changes: 2 additions & 2 deletions rs_lib/src/global/cache_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use sys_traits::FsRename;
use sys_traits::SystemRandom;
use sys_traits::ThreadSleep;

use crate::cache::CacheEntry;
use crate::SerializedCachedUrlMetadata;
use crate::CACHE_PERM;
use crate::SerializedCachedUrlMetadata;
use crate::cache::CacheEntry;

// File format:
// <content>\n// denoCacheMetadata=<metadata><EOF>
Expand Down
26 changes: 16 additions & 10 deletions rs_lib/src/global/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use url::Url;

use super::cache::HttpCache;
use super::cache::HttpCacheItemKey;
use crate::cache::url_to_filename;
use crate::cache::CacheEntry;
use crate::cache::CacheReadFileError;
use crate::cache::Checksum;
use crate::cache::SerializedCachedUrlMetadata;
use crate::cache::url_to_filename;
use crate::common::HeadersMap;
use crate::sync::MaybeSend;
use crate::sync::MaybeSync;
Expand Down Expand Up @@ -157,12 +157,12 @@ impl<TSys: GlobalHttpCacheSys> HttpCache for GlobalHttpCache<TSys> {

let maybe_file = cache_file::read(&self.sys, self.key_file_path(key))?;

if let Some(file) = &maybe_file {
if let Some(expected_checksum) = maybe_checksum {
expected_checksum
.check(key.url, &file.content)
.map_err(CacheReadFileError::ChecksumIntegrity)?;
}
if let Some(file) = &maybe_file
&& let Some(expected_checksum) = maybe_checksum
{
expected_checksum
.check(key.url, &file.content)
.map_err(CacheReadFileError::ChecksumIntegrity)?;
}

Ok(maybe_file)
Expand Down Expand Up @@ -217,12 +217,18 @@ mod test {
#[test]
fn test_url_to_filename() {
let test_cases = [
("https://deno.land/x/foo.ts", "https/deno.land/2c0a064891b9e3fbe386f5d4a833bce5076543f5404613656042107213a7bbc8"),
(
"https://deno.land/x/foo.ts",
"https/deno.land/2c0a064891b9e3fbe386f5d4a833bce5076543f5404613656042107213a7bbc8",
),
(
"https://deno.land:8080/x/foo.ts",
"https/deno.land_PORT8080/2c0a064891b9e3fbe386f5d4a833bce5076543f5404613656042107213a7bbc8",
),
("https://deno.land/", "https/deno.land/8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1"),
(
"https://deno.land/",
"https/deno.land/8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1",
),
(
"https://deno.land/?asdf=qwer",
"https/deno.land/e4edd1f433165141015db6a823094e6bd8f24dd16fe33f2abd99d34a0a21a3c0",
Expand All @@ -240,7 +246,7 @@ mod test {
(
"data:text/plain,Hello%2C%20Deno!",
"data/967374e3561d6741234131e342bf5c6848b70b13758adfe23ee1a813a8131818",
)
),
];

for (url, expected) in test_cases.iter() {
Expand Down
14 changes: 7 additions & 7 deletions rs_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod sync;
/// Permissions used to save a file in the disk caches.
pub const CACHE_PERM: u32 = 0o644;

pub use cache::url_to_filename;
pub use cache::CacheEntry;
pub use cache::CacheReadFileError;
pub use cache::Checksum;
Expand All @@ -25,10 +24,11 @@ pub use cache::HttpCache;
pub use cache::HttpCacheItemKey;
pub use cache::HttpCacheRc;
pub use cache::SerializedCachedUrlMetadata;
pub use cache::url_to_filename;
pub use common::HeadersMap;
pub use deno_dir::resolve_deno_dir;
pub use deno_dir::DenoDirResolutionError;
pub use deno_dir::ResolveDenoDirSys;
pub use deno_dir::resolve_deno_dir;
pub use global::GlobalHttpCache;
pub use global::GlobalHttpCacheRc;
pub use global::GlobalHttpCacheSys;
Expand All @@ -46,21 +46,21 @@ pub mod wasm {
use js_sys::Object;
use js_sys::Reflect;
use js_sys::Uint8Array;
use sys_traits::EnvVar;
use sys_traits::impls::RealSys;
use sys_traits::impls::wasm_path_to_str;
use sys_traits::impls::wasm_string_to_path;
use sys_traits::impls::RealSys;
use sys_traits::EnvVar;
use url::Url;
use wasm_bindgen::prelude::*;

use crate::CacheReadFileError;
use crate::Checksum;
use crate::HttpCache;
use crate::cache::CacheEntry;
use crate::cache::GlobalToLocalCopy;
use crate::common::HeadersMap;
use crate::deno_dir;
use crate::sync::new_rc;
use crate::CacheReadFileError;
use crate::Checksum;
use crate::HttpCache;

#[wasm_bindgen]
pub fn url_to_filename(url: &str) -> Result<String, JsValue> {
Expand Down
Loading
Loading