Skip to content

Commit 3ef4c0f

Browse files
authored
feat: store info on where file is loaded from (#91)
Pass along info about where the file was loaded from
1 parent 4d5e439 commit 3ef4c0f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rs_lib/src/file_fetcher/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl FileOrRedirect {
9898
maybe_headers: Some(cache_entry.metadata.headers),
9999
#[allow(clippy::disallowed_types)] // ok for source
100100
source: std::sync::Arc::from(cache_entry.content),
101+
loaded_from: LoadedFrom::Cache,
101102
}))
102103
}
103104
}
@@ -131,6 +132,21 @@ pub struct File {
131132
pub maybe_headers: Option<HashMap<String, String>>,
132133
/// The source of the file.
133134
pub source: FileSource,
135+
136+
/// Where the file was loaded from.
137+
pub loaded_from: LoadedFrom,
138+
}
139+
140+
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
141+
pub enum LoadedFrom {
142+
/// The module was loaded from a remote source.
143+
Remote,
144+
/// The module was loaded from a local source.
145+
Local,
146+
/// The module was loaded from a cache for remote sources.
147+
Cache,
148+
/// The source of the module is unknown.
149+
Unknown,
134150
}
135151

136152
impl File {
@@ -690,6 +706,7 @@ impl<TBlobStore: BlobStore, TSys: FileFetcherSys, THttpClient: HttpClient>
690706
url: url.clone(),
691707
mtime: None,
692708
maybe_headers: Some(headers),
709+
loaded_from: LoadedFrom::Local,
693710
#[allow(clippy::disallowed_types)] // ok for source
694711
source: std::sync::Arc::from(bytes),
695712
})
@@ -718,6 +735,7 @@ impl<TBlobStore: BlobStore, TSys: FileFetcherSys, THttpClient: HttpClient>
718735
url: url.clone(),
719736
mtime: None,
720737
maybe_headers: Some(headers),
738+
loaded_from: LoadedFrom::Local,
721739
#[allow(clippy::disallowed_types)] // ok for source
722740
source: std::sync::Arc::from(blob.bytes),
723741
})
@@ -824,6 +842,7 @@ impl<TBlobStore: BlobStore, TSys: FileFetcherSys, THttpClient: HttpClient>
824842
maybe_headers: Some(headers),
825843
#[allow(clippy::disallowed_types)] // ok for source
826844
source: std::sync::Arc::from(bytes),
845+
loaded_from: LoadedFrom::Remote,
827846
}))
828847
}
829848
}
@@ -1018,6 +1037,7 @@ impl<TBlobStore: BlobStore, TSys: FileFetcherSys, THttpClient: HttpClient>
10181037
url: url.clone(),
10191038
mtime,
10201039
maybe_headers: headers,
1040+
loaded_from: LoadedFrom::Local,
10211041
source: bytes.into(),
10221042
})
10231043
}

0 commit comments

Comments
 (0)