From 5b462768286c2a260882df13551400c23e2dd13a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 16 Jul 2026 03:27:19 +0900 Subject: refactor(remote-filesystem): return headers from copy/get_contents Wrap RemoteFilesystem in Rc> inside HttpDownloader, in prep for the upcoming &self conversion of add()/get(). copy()/get_contents() now bundle the response headers into their return value instead of requiring a follow-up get_last_headers() call, since two separate calls through a shared RefCell could otherwise race: nothing would guarantee the reader observes the headers from its own request rather than one clobbered by a concurrently borrowed call. get_last_headers() itself is left in place, mirroring RemoteFilesystem::getLastHeaders() in PHP. --- crates/shirabe/src/util/remote_filesystem.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/src/util/remote_filesystem.rs') diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index 9b851007..df47be20 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -96,6 +96,9 @@ impl RemoteFilesystem { } } + /// Returns the response headers alongside the result (rather than requiring a follow-up + /// `get_last_headers()` call) so that a caller sharing this instance via `Rc>` + /// always reads the headers produced by its own call, not one clobbered by a concurrent one. pub fn copy( &mut self, origin_url: &str, @@ -103,24 +106,27 @@ impl RemoteFilesystem { file_name: &str, progress: bool, options: IndexMap, - ) -> anyhow::Result { - self.get( + ) -> anyhow::Result<(GetResult, Vec)> { + let result = self.get( origin_url, file_url, options, Some(file_name.to_string()), progress, - ) + )?; + Ok((result, self.last_headers.clone())) } + /// See `copy` for why the headers are bundled into the return value. pub fn get_contents( &mut self, origin_url: &str, file_url: &str, progress: bool, options: IndexMap, - ) -> anyhow::Result { - self.get(origin_url, file_url, options, None, progress) + ) -> anyhow::Result<(GetResult, Vec)> { + let result = self.get(origin_url, file_url, options, None, progress)?; + Ok((result, self.last_headers.clone())) } pub fn get_options(&self) -> &IndexMap { -- cgit v1.3.1