team-ljyzipelo

공개

압축파일을 복사하는 동안 읽은 바이트를 알림

목록과 추출 전에 원본을 임시 파일로 복사하는 동안 진행률을 보내지 않아
큰 파일에서 화면이 "0 B"로 멈춘 것처럼 보였음. 0.2초 간격과 복사 끝에
읽은 바이트와 전체 크기를 Read 단계 진행률로 보냄. ZIP 생성 경로는 동작이 같음.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
작성자
LeeJunyoung
작성 시각
커밋
e4faa4cf197f8c2907b48ee22ea5a2bfe54daf11
부모
606b59b
이 시점의 파일 보기

변경된 파일 2개

+42-5
수정experiments/rust-archive-worker/src/runtime.rs+10-2
@@ -198,8 +198,16 @@ impl<W: Write> Job<W> {
198198 let extract = matches!(start.action, Action::Extract { .. });
199199 let path = source.to_path()?;
200200 self.progress(Stage::Read, 0, None, 0)?;
201삭제: let mut snapshot =
202삭제: crate::spool::Snapshot::open(&path, start.limits.input, &mut || self.check())?;
201추가: let mut snapshot = crate::spool::Snapshot::open_reporting(
202추가: &path,
203추가: start.limits.input,
204추가: &mut |step| match step {
205추가: crate::spool::Step::Check => self.check(),
206추가: crate::spool::Step::Read { bytes, total } => {
207추가: self.progress(Stage::Read, bytes, Some(total), 0)
208추가: }
209추가: },
210추가: )?;
203211 if let Action::Extract {
204212 list_id: Some(expected),
205213 ..
수정experiments/rust-archive-worker/src/spool.rs+32-3
@@ -70,6 +70,12 @@ pub(crate) fn temporary() -> Result<File> {
7070 }
7171}
7272
73추가: #[derive(Clone, Copy, Debug)]
74추가: pub(crate) enum Step {
75추가: Check,
76추가: Read { bytes: u64, total: u64 },
77추가: }
78추가:
7379pub(crate) struct Snapshot {
7480 pub file: File,
7581 pub len: u64,
@@ -77,7 +83,12 @@ pub(crate) struct Snapshot {
7783 pub hash: [u8; 32],
7884}
7985impl Snapshot {
80삭제: pub fn open(path: &Path, limit: u64, check: &mut impl FnMut() -> Result<()>) -> Result<Self> {
86추가: /// 원본을 임시 파일로 복사하는 동안 읽은 바이트와 전체 크기를 함께 알림.
87추가: pub fn open_reporting(
88추가: path: &Path,
89추가: limit: u64,
90추가: step: &mut impl FnMut(Step) -> Result<()>,
91추가: ) -> Result<Self> {
8192 let mut options = OpenOptions::new();
8293 options.read(true);
8394 #[cfg(unix)]
@@ -91,7 +102,7 @@ impl Snapshot {
91102 options.share_mode(1);
92103 }
93104 let mut source = options.open(path).map_err(|_| ErrorCode::Io)?;
94삭제: let snapshot = Self::capture(&mut source, limit, check)?;
105추가: let snapshot = Self::capture_reporting(&mut source, limit, step)?;
95106 let named = options.open(path).map_err(|_| ErrorCode::SourceChanged)?;
96107 if filesystem::object(&named)? != snapshot.object
97108 || !named.metadata().map_err(|_| ErrorCode::Io)?.is_file()
@@ -104,6 +115,16 @@ impl Snapshot {
104115 source: &mut File,
105116 limit: u64,
106117 check: &mut impl FnMut() -> Result<()>,
118추가: ) -> Result<Self> {
119추가: Self::capture_reporting(source, limit, &mut |step| match step {
120추가: Step::Check => check(),
121추가: Step::Read { .. } => Ok(()),
122추가: })
123추가: }
124추가: fn capture_reporting(
125추가: source: &mut File,
126추가: limit: u64,
127추가: step: &mut impl FnMut(Step) -> Result<()>,
107128 ) -> Result<Self> {
108129 let before = source.metadata().map_err(|_| ErrorCode::Io)?;
109130 if !before.is_file() {
@@ -119,8 +140,10 @@ impl Snapshot {
119140 let mut buffer = zeroize::Zeroizing::new([0; 65536]);
120141 let mut hash = Sha256::new();
121142 let mut len = 0u64;
143추가: let total = before.len();
144추가: let mut reported = std::time::Instant::now();
122145 loop {
123삭제: check()?;
146추가: step(Step::Check)?;
124147 let n = source.read(&mut buffer[..]).map_err(|_| ErrorCode::Io)?;
125148 if n == 0 {
126149 break;
@@ -132,7 +155,13 @@ impl Snapshot {
132155 file.write_all(&buffer[..n])
133156 .map_err(crate::space::io_error)?;
134157 hash.update(&buffer[..n]);
158추가: // 큰 파일에서도 진행이 보이도록 일정 간격으로만 알림.
159추가: if reported.elapsed() >= std::time::Duration::from_millis(200) {
160추가: step(Step::Read { bytes: len, total })?;
161추가: reported = std::time::Instant::now();
162추가: }
135163 }
164추가: step(Step::Read { bytes: len, total })?;
136165 let after = source.metadata().map_err(|_| ErrorCode::Io)?;
137166 if filesystem::object(&source)? != object
138167 || before.len() != len