| @@ -17,7 +17,7 @@ pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3; · 16 unmodified lines |
| 17 | pub struct Context<W> { | 17 | pub struct Context<W> { |
| 18 | pub thread_limit: Option<usize>, | 18 | pub thread_limit: Option<usize>, |
| 19 | pub format: OutputFormat, | 19 | pub format: OutputFormat, |
| 20 | pub out: Option<W>, | 20 | pub out: W, |
| 21 | } | 21 | } |
| 22 | | 22 | |
| 23 | struct CloneDelegate<W> { | 23 | struct CloneDelegate<W> { |
| @@ -117,13 +117,12 @@ mod blocking_io { · 93 unmodified lines |
| 117 | } | 117 | } |
| 118 | } | 118 | } |
| 119 | | 119 | |
| 120 | match (self.ctx.format, self.ctx.out.as_mut()) { | 120 | match self.ctx.format { |
| 121 | (OutputFormat::Human, Some(out)) => drop(print(out, outcome, refs)), | 121 | OutputFormat::Human => drop(print(&mut self.ctx.out, outcome, refs)), |
| 122 | #[cfg(feature = "serde1")] | 122 | #[cfg(feature = "serde1")] |
| 123 | (OutputFormat::Json, Some(out)) => { | 123 | OutputFormat::Json => { |
| 124 | serde_json::to_writer_pretty(out, &JsonOutcome::from_outcome_and_refs(outcome, refs))? | 124 | serde_json::to_writer_pretty(&mut self.ctx.out, &JsonOutcome::from_outcome_and_refs(outcome, refs))? |
| 125 | } | 125 | } |
| 126 | (_, None) => {} | | |
| 127 | }; | 126 | }; |
| 128 | Ok(()) | 127 | Ok(()) |
| 129 | } | 128 | } |
| @@ -182,7 +181,6 @@ mod async_io { · 52 unmodified lines |
| 182 | index_kind: pack::index::Version::V2, | 181 | index_kind: pack::index::Version::V2, |
| 183 | iteration_mode: pack::data::input::Mode::Verify, | 182 | iteration_mode: pack::data::input::Mode::Verify, |
| 184 | }; | 183 | }; |
| 185 | // TODO: unblock | | |
| 186 | let outcome = pack::bundle::Bundle::write_to_directory( | 184 | let outcome = pack::bundle::Bundle::write_to_directory( |
| 187 | futures_lite::io::BlockOn::new(input), | 185 | futures_lite::io::BlockOn::new(input), |
| 188 | self.directory.take(), | 186 | self.directory.take(), |
| @@ -192,45 +190,32 @@ mod async_io { · 3 unmodified lines |
| 192 | .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; | 190 | .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; |
| 193 | | 191 | |
| 194 | if let Some(directory) = self.refs_directory.take() { | 192 | if let Some(directory) = self.refs_directory.take() { |
| 195 | let refs = refs.to_owned(); | 193 | let assure_dir_exists = |path: &BString| { |
| 196 | blocking::unblock(move || -> io::Result<()> { | 194 | assert!(!path.starts_with_str("/"), "no ref start with a /, they are relative"); |
| 197 | let assure_dir_exists = |path: &BString| { | 195 | let path = directory.join(path.to_path_lossy()); |
| 198 | assert!(!path.starts_with_str("/"), "no ref start with a /, they are relative"); | 196 | std::fs::create_dir_all(path.parent().expect("multi-component path")).map(|_| path) |
| 199 | let path = directory.join(path.to_path_lossy()); | 197 | }; |
| 200 | std::fs::create_dir_all(path.parent().expect("multi-component path")).map(|_| path) | 198 | for r in refs { |
| 201 | }; | 199 | let (path, content) = match r { |
| 202 | for r in refs { | 200 | Ref::Symbolic { path, target, .. } => (assure_dir_exists(&path)?, format!("ref: {}", target)), |
| 203 | let (path, content) = match r { | 201 | Ref::Peeled { path, tag: object, .. } | Ref::Direct { path, object } => { |
| 204 | Ref::Symbolic { path, target, .. } => { | 202 | (assure_dir_exists(&path)?, object.to_string()) |
| 205 | (assure_dir_exists(&path)?, format!("ref: {}", target)) | | |
| 206 | } | | |
| 207 | Ref::Peeled { path, tag: object, .. } | Ref::Direct { path, object } => { | | |
| 208 | (assure_dir_exists(&path)?, object.to_string()) | | |
| 209 | } | | |
| 210 | }; | | |
| 211 | std::fs::write(path, content.as_bytes())?; | | |
| 212 | } | | |
| 213 | Ok(()) | | |
| 214 | }) | | |
| 215 | .await?; | | |
| 216 | } | | |
| 217 | | | |
| 218 | blocking::unblock({ | | |
| 219 | let format_and_output = (self.ctx.format, self.ctx.out.take()); | | |
| 220 | let refs = refs.to_owned(); | | |
| 221 | move || -> io::Result<()> { | | |
| 222 | match format_and_output { | | |
| 223 | (OutputFormat::Human, Some(mut out)) => drop(print(&mut out, outcome, &refs)), | | |
| 224 | #[cfg(feature = "serde1")] | | |
| 225 | (OutputFormat::Json, Some(mut out)) => { | | |
| 226 | serde_json::to_writer_pretty(&mut out, &JsonOutcome::from_outcome_and_refs(outcome, &refs))? | | |
| 227 | } | 203 | } |
| 228 | (_, None) => {} | | |
| 229 | }; | 204 | }; |
| 230 | Ok(()) | 205 | std::fs::write(path, content.as_bytes())?; |
| 231 | } | 206 | } |
| 232 | }) | 207 | } |
| 233 | .await | 208 | |
| | 209 | let refs = refs.to_owned(); |
| | 210 | match self.ctx.format { |
| | 211 | OutputFormat::Human => drop(print(&mut self.ctx.out, outcome, &refs)), |
| | 212 | #[cfg(feature = "serde1")] |
| | 213 | OutputFormat::Json => serde_json::to_writer_pretty( |
| | 214 | &mut self.ctx.out, |
| | 215 | &JsonOutcome::from_outcome_and_refs(outcome, &refs), |
| | 216 | )?, |
| | 217 | }; |
| | 218 | Ok(()) |
| 234 | } | 219 | } |
| 235 | } | 220 | } |
| 236 | | 221 | |