MCPcopy Index your code
hub / github.com/Firstyear/opensuse-proxy-cache / write_file

Function write_file

opensuse-proxy-cache/src/main.rs:949–1089  ·  view source on GitHub ↗
(
    cache_key: PathBuf,
    mut headers: HeaderMap,
    file: NamedTempFile,
    submit_tx: Sender<CacheMeta>,
    cls: Classification,
    mut reader: I,
)

Source from the content-addressed store, hash-verified

947
948#[instrument(skip_all)]
949async fn write_file<I>(
950 cache_key: PathBuf,
951 mut headers: HeaderMap,
952 file: NamedTempFile,
953 submit_tx: Sender<CacheMeta>,
954 cls: Classification,
955 mut reader: I,
956) where
957 I: AsyncRead + Unpin,
958{
959 let cnt_amt = headers
960 .remove("content-length")
961 .and_then(|hk| hk.to_str().ok().and_then(|i| usize::from_str(i).ok()))
962 .unwrap_or(0);
963
964 debug!(etag = ?headers.get("etag"));
965
966 let etag_nginix_len = headers
967 .get("etag")
968 .and_then(|hk| {
969 hk.to_str().ok().and_then(|t| {
970 ETAG_NGINIX_RE.captures(t).and_then(|caps| {
971 let etcap = caps.name("len");
972 etcap
973 .map(|s| s.as_str())
974 .and_then(|len_str| usize::from_str_radix(len_str, 16).ok())
975 })
976 })
977 })
978 .unwrap_or(0);
979
980 let etag_apache_len = headers
981 .get("etag")
982 .and_then(|hk| {
983 hk.to_str().ok().and_then(|t| {
984 ETAG_APACHE_RE.captures(t).and_then(|caps| {
985 let etcap = caps.name("len");
986 etcap
987 .map(|s| s.as_str())
988 .and_then(|len_str| usize::from_str_radix(len_str, 16).ok())
989 })
990 })
991 })
992 .unwrap_or(0);
993
994 // At least *one* etag length has to make sense ...
995 // Does this length make sense? Can we get an etag length?
996
997 if cnt_amt == 0 {
998 info!("Ignoring 0 length content amount");
999 return;
1000 } else if etag_nginix_len == 0 && etag_apache_len == 0 {
1001 info!("disregard 0 length etags");
1002 } else if (etag_nginix_len != 0 && cnt_amt == etag_nginix_len)
1003 || (etag_apache_len != 0 && cnt_amt == etag_apache_len)
1004 {
1005 info!(
1006 "content-length and etag agree - {} == a {} || n {}",

Callers 2

missFunction · 0.85
prefetch_dl_taskFunction · 0.85

Calls 3

removeMethod · 0.80
insertMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected