From 3500a4c25b511bfa3bb02a351a5d020b4040e9be Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 26 Nov 2026 14:28:22 -0600 Subject: [PATCH] S048: farm rule only over HTTP (FTP keeps mtime as proof of change); http test builds Co-Authored-By: Claude Opus 5.5 --- crates/core/src/http/download.rs | 6 +++--- crates/core/src/http/fetch.rs | 11 ++++++++--- crates/core/src/http/mod.rs | 5 +++++ crates/core/tests/http.rs | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/core/src/http/download.rs b/crates/core/src/http/download.rs index cb026fd..a2866e5 100644 --- a/crates/core/src/http/download.rs +++ b/crates/core/src/http/download.rs @@ -175,7 +175,7 @@ async fn fetch_whole( let here = if url == task.url { source.at(&probe.url) } else { source.mirror(&url)?.at(&probe.url) }; let mut link = Link::new(client.clone(), here, probe.ranges, probe.version.clone(), task.farm); // The bytes here are of the version first seen; replies of another one with the same size are checked by their bytes. - if !parts.is_empty() && !compared && !old(&task).same_file(&link.version) && old(&task).maybe_same(&link.version) { + if !parts.is_empty() && !compared && !old(&task).same_file(&link.version) && link.maybe_same(&old(&task)) { link.version = old(&task); } let (file, parts) = match file { @@ -283,7 +283,7 @@ async fn open_one(client: &Client, task: &Task, parts: &[Part], source: Source, if first { // Another server of a farm differs in dates only; the bytes tell when the parts go on. let old = old(task); - return if old.same_file(&probe.version) || old.maybe_same(&probe.version) { Ok((probe, false)) } else { Err(Error::Changed) }; + return if old.same_file(&probe.version) || source.web() && old.maybe_same(&probe.version) { Ok((probe, false)) } else { Err(Error::Changed) }; } let link = NewLink { url: source.url.to_string(), ..NewLink::default() }; let checked = relink::check(client, task, parts, link, source, stop).await?; @@ -372,7 +372,7 @@ async fn resume( compared: bool, stop: &mut Stop, ) -> Result<(Arc, Vec)> { - if !compared && !old(task).same_file(&link.version) && !old(task).maybe_same(&link.version) { + if !compared && !old(task).same_file(&link.version) && !link.maybe_same(&old(task)) { return Err(Error::Changed); } let file = Arc::new(file); diff --git a/crates/core/src/http/fetch.rs b/crates/core/src/http/fetch.rs index d67e99a..06ec609 100644 --- a/crates/core/src/http/fetch.rs +++ b/crates/core/src/http/fetch.rs @@ -63,6 +63,11 @@ impl Link { self.farm.sample.lock().unwrap().get_or_insert((at, data)); } + /// Of a farm's other server maybe, to be told by the bytes. Only over HTTP: other links have no farms. + pub(super) fn maybe_same(&self, version: &Validators) -> bool { + self.source.web() && self.version.maybe_same(version) + } + /// Of the version the bytes here are of, or of one shown to have the same bytes. fn sure(&self, version: &Validators) -> bool { self.version.same_file(version) || self.farm.proven.lock().unwrap().iter().any(|p| p == version) @@ -281,7 +286,7 @@ async fn send_range(link: &Link, first: u64, end: Option, stop: &mut Stop) let range = ContentRange::of(headers).ok_or_else(|| Error::BadReply("no usable Content-Range".into()))?; let version = Validators::of(headers, range.total); let unsure = !link.sure(&version); - if unsure && !link.version.maybe_same(&version) { + if unsure && !link.maybe_same(&version) { return Err(Error::Changed); } if range.first != first || end.is_some_and(|e| range.last >= e) { @@ -296,10 +301,10 @@ async fn send_range(link: &Link, first: u64, end: Option, stop: &mut Stop) if link.version.same_file(&version) { return Err(Error::RangeIgnored); } - if link.version.maybe_same(&version) && if_range.take().is_some() { + if link.maybe_same(&version) && if_range.take().is_some() { continue; } - if link.farm() && link.version.maybe_same(&version) { + if link.farm() && link.maybe_same(&version) { return Err(Error::RangeIgnored); } return Err(if comes_as_page(link, headers) { Error::Page } else { Error::Changed }); diff --git a/crates/core/src/http/mod.rs b/crates/core/src/http/mod.rs index 105fd2b..4911ce5 100644 --- a/crates/core/src/http/mod.rs +++ b/crates/core/src/http/mod.rs @@ -212,6 +212,11 @@ pub struct Source { const HOPS: usize = 10; impl Source { + /// HTTP or HTTPS, not a remote of its own (FTP, SFTP). + pub(crate) fn web(&self) -> bool { + self.remote.is_none() + } + pub fn new(url: &str) -> Result { let url = Url::parse(url).map_err(|_| Error::Link)?; let remote = Remote::of(&url).map(Arc::new); diff --git a/crates/core/tests/http.rs b/crates/core/tests/http.rs index 48aa368..c5c1744 100644 --- a/crates/core/tests/http.rs +++ b/crates/core/tests/http.rs @@ -335,7 +335,7 @@ async fn one_part(b: &Bench, path: &str, done: u64) -> (Result<()>, Vec, Par let (_keep, mut stop) = watch::channel(false); let source = Source::new(&b.server.url(path)).unwrap(); let p = probe(&b.client, &source, &mut stop).await.unwrap(); - let link = Link { client: b.client.clone(), source, ranges: true, version: p.version }; + let link = Link { client: b.client.clone(), source, ranges: true, version: p.version, farm: Default::default() }; let (file, name) = PartialFile::create(&b.folder(), "part", &Default::default()).unwrap(); std::fs::write(partial_path(&b.folder(), &name), vec![0; 200_000]).unwrap(); let part = LivePart::new(Part { start: 100_000, end: Some(200_000), done: 0 });