항목 처리의 진행 시각 갱신을 통합한다
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
7b0f24ad0b88a723fdc68728f1e930d474bf3fa3- 부모
- 5a24bd5
변경된 파일 18개
+904-195| @@ -112,7 +112,7 @@ Python 표준 bz2, lzma와 tarfile로 독립 생성 및 해제한 결과의 SHA2 | ||
| 112 | 112 | - kind 7의 `ResourceReply`는 challenge_id u64, scope, allow bool입니다. 프레임의 작업 ID, 현재 질문 ID와 요청한 scope가 모두 일치하는 응답 한 개만 허용합니다. 중복, 오래된 응답과 다른 종류의 질문 응답은 Protocol입니다. 승인은 해당 작업의 해당 범위에만 적용하며 재사용하지 않습니다. |
| 113 | 113 | - 해제량이 256 MiB 이상이고 압축률이 1,000배를 초과하면 ratio 범위를 별도로 묻습니다. ZIP은 항목별 크기와 전체 payload 합계, 7z는 solid 폴더와 전체, 압축 TAR와 GZip은 스트림 전체의 크기로 검사합니다. 예상량과 실제량을 구분하고 u128 곱셈으로 비교합니다. 승인 중에는 추가 해제와 쓰기를 멈추며 취소는 별도 제어 읽기에서 처리합니다. |
| 114 | 114 | - 승인 후에도 64 GiB와 200,000개 정책 상한, 메타데이터와 사전 예산, 경로 및 무결성, 임시 저장소와 목적지 공간 검사를 적용합니다. ZIP 생성은 원본 논리 크기 합계를 제한하며 ZIP 구조와 암호화로 늘어나는 저장 공간을 별도로 계산합니다. 이미 게시한 출력은 실패나 취소 시 유지하고 게시 및 정리 상태를 보고합니다. |
| 115 | 삭제: - 승인된 작업은 전체 300초 대신 진행이 60초 동안 없을 때 Limit로 중단합니다. 실제 읽기, 해독, 쓰기와 메타데이터 수집 및 빈 파일과 디렉터리의 성공 게시를 진행으로 계산하며 반복 check 호출은 기한을 늘리지 않습니다. 암호, 충돌과 자원 질문은 한 번에 하나이며 각 응답 대기는 300초입니다. 유효한 응답 뒤에는 사용자 대기 시간을 제외하고 정체 감시를 재개합니다. 기존 요청의 전체 300초 제한은 유지합니다. OS의 블로킹 I/O를 강제로 중단하는 보장은 아닙니다. | |
| 115 | 추가: - 승인된 작업은 전체 300초 대신 진행이 60초 동안 없을 때 Limit로 중단합니다. 성공한 읽기, 해독, 쓰기와 항목별 메타데이터 및 경로 검사를 공통 완료 함수로 기록합니다. 사전검사, 기존 폴더 조회와 생성, ZIP 헤더와 중앙 목록 기록, 목록 전송, 이름 후보와 덮어쓰기 재검사, 게시와 임시 파일 정리도 포함하며 반복 check와 UI 진행 알림만으로는 기한을 늘리지 않습니다. 한 단계 자체가 60초 이상 멈추면 완료 시에도 Limit로 처리하고 이미 만들어진 출력 집계와 정리는 유지합니다. 암호, 충돌과 자원 질문은 한 번에 하나이며 각 응답 대기는 300초입니다. 유효한 응답 뒤에는 사용자 대기 시간을 제외하고 정체 감시를 재개합니다. 기존 요청의 전체 300초 제한은 유지합니다. OS의 블로킹 I/O를 강제로 중단하는 보장은 아닙니다. | |
| 116 | 116 | |
| 117 | 117 | 메타데이터 정책은 유효한 자원 승인 여부로 선택하며 요청의 ceiling만 늘려서는 확대되지 않습니다. 원본 계획의 경로와 대기 이름은 확대 작업에서 같은 항목의 복사 비용으로 계산하고 노드를 중복 가산하지 않습니다. 이름 및 원본 경로의 바이트 비용과 암묵적 상위 폴더 노드는 계속 계산하므로 긴 경로나 많은 상위 폴더가 있으면 항목 200,000개 이전에도 Limit로 중단될 수 있습니다. 승인 전과 기존 slice API의 메타데이터 한도 및 계산 방식은 유지합니다. 기존 대용량 회귀의 64 MiB RSS 목표는 기본 메타데이터 정책의 측정값이며 확대 작업 전체의 메모리 상한을 뜻하지 않습니다. |
| 118 | 118 | |
| @@ -120,7 +120,7 @@ Python 표준 bz2, lzma와 tarfile로 독립 생성 및 해제한 결과의 SHA2 | ||
| 120 | 120 | |
| 121 | 121 | 작업자의 짧은 이름 빈 ZIP 항목 200,000개 목록 시험과 앱 승인 및 재시도 시험을 반영했습니다. `resource-approval`, `resource-ratio`, `resource-retry`, `resource-partial` 상황과 가이드도 추가됐습니다. Windows와 Wayland의 실제 화면 및 입력 검증은 별도로 남아 있습니다. |
| 122 | 122 | |
| 123 | 삭제: 시험은 실제 64 GiB를 쓰지 않고 수치 경계와 축소한 limits/ceiling을 사용합니다. `resource_budget.rs`는 16 GiB 아래/경계/초과, 64 GiB 초과, 10,000개 및 200,000개 경계, 압축률 경계와 가상 시계의 60초 정체를 검사합니다. `metadata_policy.rs`는 축소한 바이트와 노드 예산, 원본 계획과 암묵적 폴더 계산을 확인합니다. `guarded.rs`는 승인 전 메타데이터 거부, 승인 뒤 200,000개 목록, 실제 작업자 승인/거부, 오래된 응답, 암호/충돌 순서, 승인 뒤 공간 실패, 여러 형식과 작은 고압축 입력의 경고 및 취소를 검사합니다. | |
| 123 | 추가: 시험은 실제 64 GiB를 쓰지 않고 수치 경계와 축소한 limits/ceiling을 사용합니다. `resource_budget.rs`는 16 GiB 아래/경계/초과, 64 GiB 초과, 10,000개 및 200,000개 경계, 압축률 경계와 가상 시계의 60초 정체를 검사합니다. `item_progress.rs`는 기존 빈 폴더 8개를 포함해 각 단계를 가상 10초씩 늦춘 실제 작업자와 단일 60초 정체의 출력 집계 및 정리를 검사합니다. `metadata_policy.rs`는 축소한 바이트와 노드 예산, 원본 계획과 암묵적 폴더 계산을 확인합니다. `guarded.rs`는 승인 전 메타데이터 거부, 승인 뒤 200,000개 목록, 실제 작업자 승인/거부, 오래된 응답, 암호/충돌 순서, 승인 뒤 공간 실패, 여러 형식과 작은 고압축 입력의 경고 및 취소를 검사합니다. | |
| 124 | 124 | |
| 125 | 125 | ## 검증과 의존성 |
| 126 | 126 |
| @@ -152,23 +152,26 @@ pub(crate) fn validate_members_with( | ||
| 152 | 152 | let mut names = BTreeMap::<String, bool>::new(); |
| 153 | 153 | let mut budget = MetadataBudget::default(); |
| 154 | 154 | for member in members { |
| 155 | 삭제: check.activity()?; | |
| 155 | 추가: check.check()?; | |
| 156 | 156 | budget.charge_with(&member.entry.name, check.metadata_limits())?; |
| 157 | 157 | let directory = member.entry.kind == EntryKind::Directory; |
| 158 | 158 | let name = valid_name(&member.entry.name, directory)?.to_lowercase(); |
| 159 | 159 | if names.insert(name, directory).is_some() { |
| 160 | 160 | return Err(ErrorCode::Conflict); |
| 161 | 161 | } |
| 162 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 162 | 163 | } |
| 163 | 164 | for name in names.keys() { |
| 164 | 삭제: check.activity()?; | |
| 165 | 추가: check.check()?; | |
| 165 | 166 | let mut parent = name.as_str(); |
| 166 | 167 | while let Some((p, _)) = parent.rsplit_once('/') { |
| 167 | 168 | if names.get(p) == Some(&false) { |
| 168 | 169 | return Err(ErrorCode::Conflict); |
| 169 | 170 | } |
| 170 | 171 | parent = p; |
| 172 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 171 | 173 | } |
| 174 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 172 | 175 | } |
| 173 | 176 | Ok(()) |
| 174 | 177 | } |
| @@ -180,7 +183,7 @@ pub(crate) fn output_directories( | ||
| 180 | 183 | let mut budget = MetadataBudget::default(); |
| 181 | 184 | let mut dirs = BTreeSet::new(); |
| 182 | 185 | for member in members { |
| 183 | 삭제: check.activity()?; | |
| 186 | 추가: check.check()?; | |
| 184 | 187 | budget.charge_with(&member.entry.name, check.metadata_limits())?; |
| 185 | 188 | if member.entry.kind == EntryKind::Directory && !dirs.contains(member.entry.name.as_str()) { |
| 186 | 189 | dirs.insert(member.entry.name.clone()); |
| @@ -192,7 +195,9 @@ pub(crate) fn output_directories( | ||
| 192 | 195 | dirs.insert(parent.to_owned()); |
| 193 | 196 | } |
| 194 | 197 | name = parent; |
| 198 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 195 | 199 | } |
| 200 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 196 | 201 | } |
| 197 | 202 | Ok(dirs) |
| 198 | 203 | } |
| @@ -47,9 +47,7 @@ impl<F: crate::resources::Monitor> Read for CheckedInput<'_, F> { | ||
| 47 | 47 | .read(&mut buffer[..count]) |
| 48 | 48 | .map_err(|_| io::Error::other(InputError(ErrorCode::Io)))?; |
| 49 | 49 | if n != 0 { |
| 50 | 삭제: self.check | |
| 51 | 삭제: .borrow_mut() | |
| 52 | 삭제: .activity() | |
| 50 | 추가: crate::resources::completed(Ok(()), &mut **self.check.borrow_mut()) | |
| 53 | 51 | .map_err(|e| io::Error::other(InputError(e)))?; |
| 54 | 52 | } |
| 55 | 53 | Ok(n) |
| @@ -132,12 +130,13 @@ pub(crate) fn decode( | ||
| 132 | 130 | }, |
| 133 | 131 | Some(&output), |
| 134 | 132 | )?; |
| 135 | 삭제: check.borrow_mut().activity()?; | |
| 133 | 추가: crate::resources::completed(Ok(()), &mut **check.borrow_mut())?; | |
| 136 | 134 | // 전체 검증 전에는 비공개 임시 파일에만 기록함. |
| 137 | 135 | space::ensure(&output, count as u64)?; |
| 138 | 삭제: output | |
| 139 | 삭제: .write_all(&buffer[..count]) | |
| 140 | 삭제: .map_err(space::io_error)?; | |
| 136 | 추가: crate::resources::completed( | |
| 137 | 추가: output.write_all(&buffer[..count]).map_err(space::io_error), | |
| 138 | 추가: &mut **check.borrow_mut(), | |
| 139 | 추가: )?; | |
| 141 | 140 | } |
| 142 | 141 | check.borrow_mut().check()?; |
| 143 | 142 | if expected.is_some_and(|expected| expected != total) { |
| @@ -163,7 +162,7 @@ fn read_at( | ||
| 163 | 162 | ErrorCode::Io |
| 164 | 163 | } |
| 165 | 164 | })?; |
| 166 | 삭제: check.activity() | |
| 165 | 추가: crate::resources::completed(Ok(()), check) | |
| 167 | 166 | } |
| 168 | 167 | |
| 169 | 168 | fn vli(bytes: &[u8], cursor: &mut usize) -> Result<u64> { |
| @@ -371,6 +370,7 @@ fn xz_layout( | ||
| 371 | 370 | .filter(|total| *total <= limit) |
| 372 | 371 | .ok_or(ErrorCode::Limit)?; |
| 373 | 372 | records.push((unpadded, size)); |
| 373 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 374 | 374 | } |
| 375 | 375 | if data_end - cursor > 3 || index[cursor..data_end].iter().any(|byte| *byte != 0) { |
| 376 | 376 | return Err(ErrorCode::Integrity); |
| @@ -398,6 +398,7 @@ fn xz_layout( | ||
| 398 | 398 | for (unpadded, size) in records { |
| 399 | 399 | xz_block(source, block_at, unpadded, size, check_size, check)?; |
| 400 | 400 | block_at += (unpadded + 3) & !3; |
| 401 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 401 | 402 | } |
| 402 | 403 | end = start; |
| 403 | 404 | } |
| @@ -57,11 +57,12 @@ fn pack( | ||
| 57 | 57 | if n == 0 { |
| 58 | 58 | break; |
| 59 | 59 | } |
| 60 | 삭제: check.activity()?; | |
| 60 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 61 | 61 | crate::space::ensure(output, n as u64)?; |
| 62 | 62 | crc = crc32(crc, &buffer[..n]); |
| 63 | 63 | io(output.write_all(&buffer[..n]))?; |
| 64 | 64 | size += n as u64; |
| 65 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 65 | 66 | } |
| 66 | 67 | if size != length { |
| 67 | 68 | return Err(ErrorCode::SourceChanged); |
| @@ -94,7 +95,7 @@ fn pack( | ||
| 94 | 95 | crate::space::ensure(output, written as u64)?; |
| 95 | 96 | io(output.write_all(&encoded[..written]))?; |
| 96 | 97 | if used != 0 || written != 0 { |
| 97 | 삭제: check.activity()?; | |
| 98 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 98 | 99 | } |
| 99 | 100 | size = size.checked_add(written as u64).ok_or(ErrorCode::Limit)?; |
| 100 | 101 | if status == Status::StreamEnd { |
| @@ -142,7 +143,7 @@ pub(crate) fn zip( | ||
| 142 | 143 | .min(limits.output) |
| 143 | 144 | .checked_sub(total) |
| 144 | 145 | .ok_or(ErrorCode::Limit)?; |
| 145 | 삭제: let mut input = source.open()?; | |
| 146 | 추가: let mut input = crate::resources::completed(source.open(), check)?; | |
| 146 | 147 | let mut snapshot = if directory { |
| 147 | 148 | None |
| 148 | 149 | } else { |
| @@ -223,7 +224,7 @@ pub(crate) fn zip( | ||
| 223 | 224 | header.extend(name); |
| 224 | 225 | header.extend(extra); |
| 225 | 226 | io(output.write_all(&header))?; |
| 226 | 삭제: check.activity()?; | |
| 227 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 227 | 228 | io(packed.rewind())?; |
| 228 | 229 | if let Some(password) = password { |
| 229 | 230 | crate::crypto::aes_encrypt_file( |
| @@ -243,7 +244,7 @@ pub(crate) fn zip( | ||
| 243 | 244 | } |
| 244 | 245 | crate::space::ensure(&output, n as u64)?; |
| 245 | 246 | io(output.write_all(&buffer[..n]))?; |
| 246 | 삭제: check.activity()?; | |
| 247 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 247 | 248 | } |
| 248 | 249 | } |
| 249 | 250 | let mut extra = zip64_extra(length, packed_size, Some(offset)); |
| @@ -285,11 +286,14 @@ pub(crate) fn zip( | ||
| 285 | 286 | ); |
| 286 | 287 | central.extend(name); |
| 287 | 288 | central.extend(extra); |
| 289 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 288 | 290 | } |
| 289 | 291 | check.check()?; |
| 290 | 292 | let at = io(output.stream_position())?; |
| 291 | 293 | crate::space::ensure(&output, central.len() as u64 + 98)?; |
| 292 | 삭제: io(output.write_all(¢ral))?; | |
| 294 | 추가: if !central.is_empty() { | |
| 295 | 추가: crate::resources::completed(io(output.write_all(¢ral)), check)?; | |
| 296 | 추가: } | |
| 293 | 297 | let large_at = io(output.stream_position())?; |
| 294 | 298 | let mut end = Vec::new(); |
| 295 | 299 | if have_zip64 |
| @@ -329,7 +333,7 @@ pub(crate) fn zip( | ||
| 329 | 333 | put32(&mut end, at as u32); |
| 330 | 334 | put16(&mut end, 0); |
| 331 | 335 | } |
| 332 | 삭제: io(output.write_all(&end))?; | |
| 336 | 추가: crate::resources::completed(io(output.write_all(&end)), check)?; | |
| 333 | 337 | plan.verify(check)?; |
| 334 | 338 | let size = io(output.stream_position())?; |
| 335 | 339 | io(output.rewind())?; |
| @@ -219,20 +219,26 @@ impl Plan { | ||
| 219 | 219 | if !roots.insert(name.to_lowercase()) { |
| 220 | 220 | return Err(ErrorCode::Conflict); |
| 221 | 221 | } |
| 222 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 222 | 223 | } |
| 223 | 224 | for source in sources { |
| 224 | 225 | let path = source.path.to_path()?; |
| 225 | 삭제: let input = Input::open(&path)?; | |
| 226 | 추가: let input = crate::resources::completed(Input::open(&path), check)?; | |
| 226 | 227 | plan.visit(path, source.archive_name.clone(), input, check)?; |
| 227 | 228 | } |
| 228 | 229 | let members = plan |
| 229 | 230 | .items |
| 230 | 231 | .iter() |
| 231 | 삭제: .map(|p| Member { | |
| 232 | 삭제: entry: p.member.entry.clone(), | |
| 233 | 삭제: data: Vec::new(), | |
| 232 | 추가: .map(|p| { | |
| 233 | 추가: crate::resources::completed( | |
| 234 | 추가: Ok(Member { | |
| 235 | 추가: entry: p.member.entry.clone(), | |
| 236 | 추가: data: Vec::new(), | |
| 237 | 추가: }), | |
| 238 | 추가: check, | |
| 239 | 추가: ) | |
| 234 | 240 | }) |
| 235 | 삭제: .collect::<Vec<_>>(); | |
| 241 | 추가: .collect::<Result<Vec<_>>>()?; | |
| 236 | 242 | archive::validate_members_with(&members, check)?; |
| 237 | 243 | Ok(plan) |
| 238 | 244 | } |
| @@ -247,7 +253,10 @@ impl Plan { | ||
| 247 | 253 | if self.items.len() >= self.limits.entries as usize { |
| 248 | 254 | return Err(ErrorCode::Limit); |
| 249 | 255 | } |
| 250 | 삭제: let metadata: Metadata = input.file.metadata().map_err(crate::space::io_error)?; | |
| 256 | 추가: let metadata: Metadata = crate::resources::completed( | |
| 257 | 추가: input.file.metadata().map_err(crate::space::io_error), | |
| 258 | 추가: check, | |
| 259 | 추가: )?; | |
| 251 | 260 | let directory = metadata.is_dir(); |
| 252 | 261 | let name = archive::valid_name(&name, directory)?; |
| 253 | 262 | self.budget.charge_with(&name, check.metadata_limits())?; |
| @@ -267,7 +276,7 @@ impl Plan { | ||
| 267 | 276 | }, |
| 268 | 277 | None, |
| 269 | 278 | )?; |
| 270 | 삭제: check.activity()?; | |
| 279 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 271 | 280 | self.items.push(Planned { |
| 272 | 281 | member: Member { |
| 273 | 282 | entry: Entry { |
| @@ -285,7 +294,7 @@ impl Plan { | ||
| 285 | 294 | data: Vec::new(), |
| 286 | 295 | }, |
| 287 | 296 | path: path.clone(), |
| 288 | 삭제: object: filesystem::object(&input.file)?, | |
| 297 | 추가: object: crate::resources::completed(filesystem::object(&input.file), check)?, | |
| 289 | 298 | modified: metadata.modified().ok(), |
| 290 | 299 | }); |
| 291 | 300 | if directory { |
| @@ -310,11 +319,11 @@ impl Plan { | ||
| 310 | 319 | }, |
| 311 | 320 | None, |
| 312 | 321 | )?; |
| 313 | 삭제: check.activity()?; | |
| 322 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 314 | 323 | } |
| 315 | 324 | children.sort(); |
| 316 | 325 | for leaf in children { |
| 317 | 삭제: let child = input.open_child(&path, &leaf)?; | |
| 326 | 추가: let child = crate::resources::completed(input.open_child(&path, &leaf), check)?; | |
| 318 | 327 | self.visit(path.join(&leaf), format!("{name}/{leaf}"), child, check)?; |
| 319 | 328 | } |
| 320 | 329 | } |
| @@ -324,7 +333,7 @@ impl Plan { | ||
| 324 | 333 | for item in &self.items { |
| 325 | 334 | check.check()?; |
| 326 | 335 | item.open()?; |
| 327 | 삭제: check.activity()?; | |
| 336 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 328 | 337 | } |
| 329 | 338 | Ok(()) |
| 330 | 339 | } |
| @@ -218,7 +218,7 @@ impl Decryptor { | ||
| 218 | 218 | .map_err(|_| ErrorCode::Integrity)?; |
| 219 | 219 | mac.update(&buffer[..n]); |
| 220 | 220 | remaining -= n as u64; |
| 221 | 삭제: check.activity()?; | |
| 221 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 222 | 222 | } |
| 223 | 223 | let mut tag = [0; 10]; |
| 224 | 224 | file.read_exact(&mut tag) |
| @@ -336,7 +336,7 @@ pub(crate) fn aes_encrypt_file( | ||
| 336 | 336 | .write_all(&buffer[..n]) |
| 337 | 337 | .map_err(crate::space::io_error)?; |
| 338 | 338 | remaining -= n as u64; |
| 339 | 삭제: check.activity()?; | |
| 339 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 340 | 340 | } |
| 341 | 341 | output |
| 342 | 342 | .write_all(&mac.finalize().into_bytes()[..10]) |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | use crate::archive::valid_name; |
| 2 | 2 | use crate::protocol::*; |
| 3 | 추가: use crate::resources::{Monitor, completed}; | |
| 3 | 4 | use sha2::{Digest, Sha256}; |
| 4 | 5 | use std::fs::{File, OpenOptions}; |
| 5 | 6 | use std::io::{Read, Write}; |
| @@ -128,6 +129,7 @@ pub fn snapshot( | ||
| 128 | 129 | bytes.try_reserve(n).map_err(|_| ErrorCode::Limit)?; |
| 129 | 130 | bytes.extend_from_slice(&buffer[..n]); |
| 130 | 131 | hash.update(&buffer[..n]); |
| 132 | 추가: completed(Ok(()), check)?; | |
| 131 | 133 | } |
| 132 | 134 | let after = file.metadata().map_err(|_| ErrorCode::Io)?; |
| 133 | 135 | let named = options.open(path).map_err(|_| ErrorCode::SourceChanged)?; |
| @@ -493,12 +495,17 @@ mod platform { | ||
| 493 | 495 | #[cfg(not(any(target_os = "linux", windows)))] |
| 494 | 496 | compile_error!("Archive worker supports Linux and Windows only"); |
| 495 | 497 | pub use platform::Dir; |
| 496 | 삭제: fn parent(root: &Dir, name: &str, create: bool) -> Result<Option<(Dir, String)>> { | |
| 498 | 추가: fn parent_with( | |
| 499 | 추가: root: &Dir, | |
| 500 | 추가: name: &str, | |
| 501 | 추가: create: bool, | |
| 502 | 추가: check: &mut impl Monitor, | |
| 503 | 추가: ) -> Result<Option<(Dir, String)>> { | |
| 497 | 504 | let mut parts = name.split('/').collect::<Vec<_>>(); |
| 498 | 505 | let leaf = parts.pop().ok_or(ErrorCode::UnsafePath)?; |
| 499 | 506 | let mut d = root.duplicate()?; |
| 500 | 507 | for p in parts { |
| 501 | 삭제: match d.child(p, create)? { | |
| 508 | 추가: match completed(d.child(p, create), check)? { | |
| 502 | 509 | Some(child) => d = child, |
| 503 | 510 | None => return Ok(None), |
| 504 | 511 | } |
| @@ -506,25 +513,46 @@ fn parent(root: &Dir, name: &str, create: bool) -> Result<Option<(Dir, String)>> | ||
| 506 | 513 | Ok(Some((d, leaf.to_owned()))) |
| 507 | 514 | } |
| 508 | 515 | pub fn existing(root: &Dir, name: &str) -> Result<Option<Existing>> { |
| 516 | 추가: existing_with(root, name, &mut || Ok(())) | |
| 517 | 추가: } | |
| 518 | 추가: pub(crate) fn existing_with( | |
| 519 | 추가: root: &Dir, | |
| 520 | 추가: name: &str, | |
| 521 | 추가: check: &mut impl Monitor, | |
| 522 | 추가: ) -> Result<Option<Existing>> { | |
| 509 | 523 | valid_name(name, false)?; |
| 510 | 삭제: match parent(root, name, false)? { | |
| 524 | 추가: let result = match parent_with(root, name, false, check)? { | |
| 511 | 525 | Some((dir, leaf)) => dir.existing(&leaf), |
| 512 | 526 | None => Ok(None), |
| 513 | 삭제: } | |
| 527 | 추가: }; | |
| 528 | 추가: completed(result, check) | |
| 514 | 529 | } |
| 515 | 530 | pub fn unused(root: &Dir, name: &str) -> Result<bool> { |
| 531 | 추가: unused_with(root, name, &mut || Ok(())) | |
| 532 | 추가: } | |
| 533 | 추가: pub(crate) fn unused_with(root: &Dir, name: &str, check: &mut impl Monitor) -> Result<bool> { | |
| 516 | 534 | valid_name(name, false)?; |
| 517 | 삭제: match parent(root, name, false)? { | |
| 535 | 추가: let result = match parent_with(root, name, false, check)? { | |
| 518 | 536 | Some((dir, leaf)) => dir.absent(&leaf), |
| 519 | 537 | None => Ok(true), |
| 520 | 삭제: } | |
| 538 | 추가: }; | |
| 539 | 추가: completed(result, check) | |
| 521 | 540 | } |
| 522 | 541 | pub fn preflight(root: &Dir, names: &[(String, EntryKind)]) -> Result<()> { |
| 523 | 542 | preflight_mode(root, names, false) |
| 524 | 543 | } |
| 525 | 544 | pub fn preflight_mode(root: &Dir, names: &[(String, EntryKind)], interactive: bool) -> Result<()> { |
| 545 | 추가: preflight_mode_with(root, names, interactive, &mut || Ok(())) | |
| 546 | 추가: } | |
| 547 | 추가: pub(crate) fn preflight_mode_with( | |
| 548 | 추가: root: &Dir, | |
| 549 | 추가: names: &[(String, EntryKind)], | |
| 550 | 추가: interactive: bool, | |
| 551 | 추가: check: &mut impl Monitor, | |
| 552 | 추가: ) -> Result<()> { | |
| 526 | 553 | for (name, kind) in names { |
| 527 | 삭제: if let Some((d, leaf)) = parent(root, name, false)? { | |
| 554 | 추가: check.check()?; | |
| 555 | 추가: if let Some((d, leaf)) = parent_with(root, name, false, check)? { | |
| 528 | 556 | if *kind == EntryKind::Directory { |
| 529 | 557 | let _ = d.child(&leaf, false)?; |
| 530 | 558 | } else if interactive { |
| @@ -533,13 +561,15 @@ pub fn preflight_mode(root: &Dir, names: &[(String, EntryKind)], interactive: bo | ||
| 533 | 561 | return Err(ErrorCode::Conflict); |
| 534 | 562 | } |
| 535 | 563 | } |
| 564 | 추가: completed(Ok(()), check)?; | |
| 536 | 565 | } |
| 537 | 566 | Ok(()) |
| 538 | 567 | } |
| 539 | 삭제: pub(crate) fn preflight_space( | |
| 568 | 추가: pub(crate) fn preflight_space_with( | |
| 540 | 569 | root: &Dir, |
| 541 | 570 | files: &[(String, u64)], |
| 542 | 571 | staging: Option<(&File, u64)>, |
| 572 | 추가: check: &mut impl Monitor, | |
| 543 | 573 | ) -> Result<()> { |
| 544 | 574 | let mut volumes = std::collections::BTreeMap::<u64, (File, u64)>::new(); |
| 545 | 575 | let mut charge = |file: &File, bytes: u64| -> Result<()> { |
| @@ -556,7 +586,7 @@ pub(crate) fn preflight_space( | ||
| 556 | 586 | Ok(()) |
| 557 | 587 | }; |
| 558 | 588 | if let Some((file, bytes)) = staging { |
| 559 | 삭제: charge(file, bytes)?; | |
| 589 | 추가: completed(charge(file, bytes), check)?; | |
| 560 | 590 | } |
| 561 | 591 | for (name, size) in files { |
| 562 | 592 | valid_name(name, false)?; |
| @@ -564,26 +594,38 @@ pub(crate) fn preflight_space( | ||
| 564 | 594 | let mut parts = name.split('/').collect::<Vec<_>>(); |
| 565 | 595 | parts.pop(); |
| 566 | 596 | for part in parts { |
| 567 | 삭제: match parent.child(part, false)? { | |
| 597 | 추가: match completed(parent.child(part, false), check)? { | |
| 568 | 598 | Some(child) => parent = child, |
| 569 | 599 | None => break, |
| 570 | 600 | } |
| 571 | 601 | } |
| 572 | 삭제: charge(parent.handle(), *size)?; | |
| 602 | 추가: completed(charge(parent.handle(), *size), check)?; | |
| 573 | 603 | } |
| 574 | 604 | for (file, bytes) in volumes.values() { |
| 575 | 삭제: crate::space::ensure(file, *bytes)?; | |
| 605 | 추가: completed(crate::space::ensure(file, *bytes), check)?; | |
| 576 | 606 | } |
| 577 | 607 | Ok(()) |
| 578 | 608 | } |
| 579 | 609 | pub fn directory(root: &Dir, name: &str) -> Result<(bool, Durability, Option<ErrorCode>)> { |
| 580 | 삭제: let (d, leaf) = parent(root, name, false)?.ok_or(ErrorCode::Io)?; | |
| 581 | 삭제: if d.child(&leaf, false)?.is_some() { | |
| 610 | 추가: directory_with(root, name, &mut || Ok(())) | |
| 611 | 추가: } | |
| 612 | 추가: pub(crate) fn directory_with( | |
| 613 | 추가: root: &Dir, | |
| 614 | 추가: name: &str, | |
| 615 | 추가: check: &mut impl Monitor, | |
| 616 | 추가: ) -> Result<(bool, Durability, Option<ErrorCode>)> { | |
| 617 | 추가: let (d, leaf) = parent_with(root, name, false, check)?.ok_or(ErrorCode::Io)?; | |
| 618 | 추가: if completed(d.child(&leaf, false), check)?.is_some() { | |
| 582 | 619 | return Ok((false, Durability::NotApplicable, None)); |
| 583 | 620 | } |
| 584 | 621 | d.child(&leaf, true)?.ok_or(ErrorCode::Io)?; |
| 622 | 추가: let progress_error = completed(Ok(()), check).err(); | |
| 585 | 623 | Ok(match d.sync_checked() { |
| 586 | 삭제: Ok(durability) => (true, durability, None), | |
| 624 | 추가: Ok(durability) => ( | |
| 625 | 추가: true, | |
| 626 | 추가: durability, | |
| 627 | 추가: progress_error.or_else(|| completed(Ok(()), check).err()), | |
| 628 | 추가: ), | |
| 587 | 629 | Err(error) => (true, Durability::Failed, Some(error)), |
| 588 | 630 | }) |
| 589 | 631 | } |
| @@ -627,6 +669,43 @@ pub fn publish_reader_mode( | ||
| 627 | 669 | length: u64, |
| 628 | 670 | replace: Option<&Existing>, |
| 629 | 671 | check: &mut impl FnMut(bool) -> Result<()>, |
| 672 | 추가: ) -> Published { | |
| 673 | 추가: publish_reader_steps(root, name, data, length, replace, &mut |step| match step { | |
| 674 | 추가: PublishStep::Check => check(false), | |
| 675 | 추가: PublishStep::Commit => check(true), | |
| 676 | 추가: PublishStep::Activity => Ok(()), | |
| 677 | 추가: }) | |
| 678 | 추가: } | |
| 679 | 추가: pub(crate) enum PublishStep { | |
| 680 | 추가: Check, | |
| 681 | 추가: Activity, | |
| 682 | 추가: Commit, | |
| 683 | 추가: } | |
| 684 | 추가: struct PublicationMonitor<'a, F>(&'a mut F); | |
| 685 | 추가: impl<F: FnMut(PublishStep) -> Result<()>> Monitor for PublicationMonitor<'_, F> { | |
| 686 | 추가: fn check(&mut self) -> Result<()> { | |
| 687 | 추가: self.0(PublishStep::Check) | |
| 688 | 추가: } | |
| 689 | 추가: fn activity(&mut self) -> Result<()> { | |
| 690 | 추가: self.0(PublishStep::Activity) | |
| 691 | 추가: } | |
| 692 | 추가: } | |
| 693 | 추가: fn publication_activity( | |
| 694 | 추가: finish: &mut Result<()>, | |
| 695 | 추가: check: &mut impl FnMut(PublishStep) -> Result<()>, | |
| 696 | 추가: ) { | |
| 697 | 추가: let progress = completed(Ok(()), &mut PublicationMonitor(check)); | |
| 698 | 추가: if finish.is_ok() { | |
| 699 | 추가: *finish = progress; | |
| 700 | 추가: } | |
| 701 | 추가: } | |
| 702 | 추가: pub(crate) fn publish_reader_steps( | |
| 703 | 추가: root: &Dir, | |
| 704 | 추가: name: &str, | |
| 705 | 추가: data: &mut impl Read, | |
| 706 | 추가: length: u64, | |
| 707 | 추가: replace: Option<&Existing>, | |
| 708 | 추가: check: &mut impl FnMut(PublishStep) -> Result<()>, | |
| 630 | 709 | ) -> Published { |
| 631 | 710 | let mut result = Published { |
| 632 | 711 | created: false, |
| @@ -639,7 +718,8 @@ pub fn publish_reader_mode( | ||
| 639 | 718 | }; |
| 640 | 719 | let prepared = (|| { |
| 641 | 720 | valid_name(name, false)?; |
| 642 | 삭제: let (dir, leaf) = parent(root, name, true)?.ok_or(ErrorCode::Io)?; | |
| 721 | 추가: let (dir, leaf) = | |
| 722 | 추가: parent_with(root, name, true, &mut PublicationMonitor(check))?.ok_or(ErrorCode::Io)?; | |
| 643 | 723 | let temp = format!( |
| 644 | 724 | ".zipelo-{}-{}.tmp", |
| 645 | 725 | std::process::id(), |
| @@ -653,31 +733,49 @@ pub fn publish_reader_mode( | ||
| 653 | 733 | } |
| 654 | 734 | })?; |
| 655 | 735 | let written = (|| { |
| 656 | 삭제: crate::space::ensure(&file, length)?; | |
| 736 | 추가: completed(Ok(()), &mut PublicationMonitor(check))?; | |
| 737 | 추가: completed( | |
| 738 | 추가: crate::space::ensure(&file, length), | |
| 739 | 추가: &mut PublicationMonitor(check), | |
| 740 | 추가: )?; | |
| 657 | 741 | let mut buffer = zeroize::Zeroizing::new([0; 65536]); |
| 658 | 742 | let mut remaining = length; |
| 659 | 743 | while remaining != 0 { |
| 660 | 삭제: check(false)?; | |
| 744 | 추가: check(PublishStep::Check)?; | |
| 661 | 745 | let count = remaining.min(buffer.len() as u64) as usize; |
| 662 | 746 | let n = data.read(&mut buffer[..count]).map_err(|_| ErrorCode::Io)?; |
| 663 | 747 | if n == 0 { |
| 664 | 748 | return Err(ErrorCode::Io); |
| 665 | 749 | } |
| 666 | 삭제: crate::space::ensure(&file, n as u64)?; | |
| 667 | 삭제: file.write_all(&buffer[..n]) | |
| 668 | 삭제: .map_err(crate::space::io_error)?; | |
| 750 | 추가: completed(Ok(()), &mut PublicationMonitor(check))?; | |
| 751 | 추가: completed( | |
| 752 | 추가: crate::space::ensure(&file, n as u64), | |
| 753 | 추가: &mut PublicationMonitor(check), | |
| 754 | 추가: )?; | |
| 755 | 추가: completed( | |
| 756 | 추가: file.write_all(&buffer[..n]).map_err(crate::space::io_error), | |
| 757 | 추가: &mut PublicationMonitor(check), | |
| 758 | 추가: )?; | |
| 669 | 759 | remaining -= n as u64; |
| 670 | 760 | } |
| 671 | 삭제: file.sync_all().map_err(crate::space::io_error) | |
| 761 | 추가: completed( | |
| 762 | 추가: file.sync_all().map_err(crate::space::io_error), | |
| 763 | 추가: &mut PublicationMonitor(check), | |
| 764 | 추가: ) | |
| 672 | 765 | })(); |
| 673 | 삭제: let closed = close(file).map_err(crate::space::io_error); | |
| 766 | 추가: let closed = completed( | |
| 767 | 추가: close(file).map_err(crate::space::io_error), | |
| 768 | 추가: &mut PublicationMonitor(check), | |
| 769 | 추가: ); | |
| 674 | 770 | let mut finish = written.and(closed).and_then(|_| { |
| 675 | 771 | if let Some(expected) = replace { |
| 676 | 삭제: if dir.existing(&leaf)?.as_ref() != Some(expected) { | |
| 772 | 추가: if completed(dir.existing(&leaf), &mut PublicationMonitor(check))?.as_ref() | |
| 773 | 추가: != Some(expected) | |
| 774 | 추가: { | |
| 677 | 775 | return Err(ErrorCode::Conflict); |
| 678 | 776 | } |
| 679 | 777 | } |
| 680 | 삭제: check(true) | |
| 778 | 추가: check(PublishStep::Commit) | |
| 681 | 779 | }); |
| 682 | 780 | let mut temp_consumed = false; |
| 683 | 781 | if finish.is_ok() { |
| @@ -690,8 +788,12 @@ pub fn publish_reader_mode( | ||
| 690 | 788 | Ok(()) => { |
| 691 | 789 | temp_consumed = replace.is_some(); |
| 692 | 790 | result.created = true; |
| 791 | 추가: publication_activity(&mut finish, check); | |
| 693 | 792 | match dir.sync_checked() { |
| 694 | 삭제: Ok(durability) => result.durability = durability, | |
| 793 | 추가: Ok(durability) => { | |
| 794 | 추가: result.durability = durability; | |
| 795 | 추가: publication_activity(&mut finish, check); | |
| 796 | 추가: } | |
| 695 | 797 | Err(error) => { |
| 696 | 798 | result.durability = Durability::Failed; |
| 697 | 799 | finish = Err(error); |
| @@ -708,21 +810,27 @@ pub fn publish_reader_mode( | ||
| 708 | 810 | } |
| 709 | 811 | } |
| 710 | 812 | } |
| 711 | 삭제: if !temp_consumed && !dir.remove(&temp) { | |
| 712 | 삭제: result.cleanup = Cleanup::Failed; | |
| 713 | 삭제: result.retained = 1; | |
| 714 | 삭제: result.retained_name = Some(match name.rsplit_once('/') { | |
| 715 | 삭제: Some((prefix, _)) => format!("{prefix}/{temp}"), | |
| 716 | 삭제: None => temp.clone(), | |
| 717 | 삭제: }); | |
| 718 | 삭제: if finish.is_ok() { | |
| 719 | 삭제: finish = Err(ErrorCode::Io); | |
| 813 | 추가: if !temp_consumed { | |
| 814 | 추가: if dir.remove(&temp) { | |
| 815 | 추가: publication_activity(&mut finish, check); | |
| 816 | 추가: } else { | |
| 817 | 추가: result.cleanup = Cleanup::Failed; | |
| 818 | 추가: result.retained = 1; | |
| 819 | 추가: result.retained_name = Some(match name.rsplit_once('/') { | |
| 820 | 추가: Some((prefix, _)) => format!("{prefix}/{temp}"), | |
| 821 | 추가: None => temp.clone(), | |
| 822 | 추가: }); | |
| 823 | 추가: if finish.is_ok() { | |
| 824 | 추가: finish = Err(ErrorCode::Io); | |
| 825 | 추가: } | |
| 720 | 826 | } |
| 721 | 827 | } |
| 722 | 828 | if result.created { |
| 723 | 829 | if let Err(error) = dir.sync_checked() { |
| 724 | 830 | result.durability = Durability::Failed; |
| 725 | 831 | finish = Err(error); |
| 832 | 추가: } else { | |
| 833 | 추가: publication_activity(&mut finish, check); | |
| 726 | 834 | } |
| 727 | 835 | } |
| 728 | 836 | finish |
| @@ -414,7 +414,7 @@ impl Model { | ||
| 414 | 414 | if out.len() >= next_check { |
| 415 | 415 | check.check()?; |
| 416 | 416 | if out.len() > next_check.saturating_sub(65536) { |
| 417 | 삭제: check.activity()?; | |
| 417 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 418 | 418 | } |
| 419 | 419 | check.observe( |
| 420 | 420 | crate::protocol::ResourceUsage { |
| @@ -507,7 +507,7 @@ pub(crate) fn decode_stream( | ||
| 507 | 507 | loop { |
| 508 | 508 | check.check()?; |
| 509 | 509 | let control = byte(&mut reader)?; |
| 510 | 삭제: check.activity()?; | |
| 510 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 511 | 511 | if control == 0 { |
| 512 | 512 | let mut extra = [0]; |
| 513 | 513 | if reader.read(&mut extra).map_err(crate::space::io_error)? != 0 || out.len() != size { |
| @@ -21,6 +21,12 @@ impl<F: FnMut() -> Result<()>> Monitor for F { | ||
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 추가: pub(crate) fn completed<T>(result: Result<T>, check: &mut impl Monitor) -> Result<T> { | |
| 25 | 추가: let value = result?; | |
| 26 | 추가: check.activity()?; | |
| 27 | 추가: Ok(value) | |
| 28 | 추가: } | |
| 29 | 추가: | |
| 24 | 30 | pub(crate) struct Budget { |
| 25 | 31 | pub soft: Limits, |
| 26 | 32 | pub ceiling: Limits, |
| @@ -2,7 +2,7 @@ use crate::{ | ||
| 2 | 2 | archive, |
| 3 | 3 | filesystem::{self, Dir}, |
| 4 | 4 | protocol::*, |
| 5 | 삭제: resources::{Budget, Monitor, Watchdog}, | |
| 5 | 추가: resources::{Budget, Monitor, Watchdog, completed}, | |
| 6 | 6 | wire::{Reader, Writer}, |
| 7 | 7 | }; |
| 8 | 8 | use std::{ |
| @@ -233,9 +233,10 @@ impl<W: Write> Job<W> { | ||
| 233 | 233 | format!("{prefix}/{leaf}") |
| 234 | 234 | }; |
| 235 | 235 | archive::valid_name(&candidate, false)?; |
| 236 | 삭제: if !reserved.contains(&candidate.to_lowercase()) | |
| 237 | 삭제: && filesystem::unused(root, &candidate)? | |
| 238 | 삭제: { | |
| 236 | 추가: let unused = !reserved.contains(&candidate.to_lowercase()) | |
| 237 | 추가: && filesystem::unused_with(root, &candidate, self)?; | |
| 238 | 추가: completed(Ok(()), self)?; | |
| 239 | 추가: if unused { | |
| 239 | 240 | return Ok(candidate); |
| 240 | 241 | } |
| 241 | 242 | } |
| @@ -299,16 +300,12 @@ impl<W: Write> Job<W> { | ||
| 299 | 300 | Some(length), |
| 300 | 301 | self.terminal.created_count as u32, |
| 301 | 302 | )?; |
| 302 | 삭제: let mut first_chunk = true; | |
| 303 | 삭제: let p = filesystem::publish_reader_mode(root, name, data, length, replace, &mut |commit| { | |
| 304 | 삭제: if !first_chunk { | |
| 305 | 삭제: self.activity()?; | |
| 306 | 삭제: } | |
| 307 | 삭제: first_chunk = false; | |
| 308 | 삭제: if commit && last { | |
| 309 | 삭제: self.cutoff() | |
| 310 | 삭제: } else { | |
| 311 | 삭제: self.check() | |
| 303 | 추가: let p = filesystem::publish_reader_steps(root, name, data, length, replace, &mut |step| { | |
| 304 | 추가: match step { | |
| 305 | 추가: filesystem::PublishStep::Check => self.check(), | |
| 306 | 추가: filesystem::PublishStep::Activity => completed(Ok(()), self), | |
| 307 | 추가: filesystem::PublishStep::Commit if last => self.cutoff(), | |
| 308 | 추가: filesystem::PublishStep::Commit => self.check(), | |
| 312 | 309 | } |
| 313 | 310 | }); |
| 314 | 311 | self.terminal.retained_partial_count += p.retained; |
| @@ -351,7 +348,7 @@ impl<W: Write> Job<W> { | ||
| 351 | 348 | return Err(error); |
| 352 | 349 | } |
| 353 | 350 | if p.created { |
| 354 | 삭제: self.activity()?; | |
| 351 | 추가: completed(Ok(()), self)?; | |
| 355 | 352 | } |
| 356 | 353 | Ok(()) |
| 357 | 354 | } |
| @@ -391,8 +388,8 @@ impl<W: Write> Job<W> { | ||
| 391 | 388 | crate::spool::Snapshot::open_reporting(&path, limits.input, &mut |step| { |
| 392 | 389 | match step { |
| 393 | 390 | crate::spool::Step::Check => self.check(), |
| 391 | 추가: crate::spool::Step::Activity => completed(Ok(()), self), | |
| 394 | 392 | crate::spool::Step::Read { bytes, total } => { |
| 395 | 삭제: self.activity()?; | |
| 396 | 393 | self.progress(Stage::Read, bytes, Some(total), 0) |
| 397 | 394 | } |
| 398 | 395 | } |
| @@ -429,13 +426,15 @@ impl<W: Write> Job<W> { | ||
| 429 | 426 | if !extract { |
| 430 | 427 | for member in &catalog.members { |
| 431 | 428 | self.check()?; |
| 432 | 삭제: self.event(Message::Entry(member.entry.clone()))?; | |
| 433 | 삭제: self.activity()?; | |
| 429 | 추가: completed(self.event(Message::Entry(member.entry.clone())), self)?; | |
| 434 | 430 | } |
| 435 | 삭제: self.event(Message::ListEnd { | |
| 436 | 삭제: entry_count: catalog.members.len() as u32, | |
| 437 | 삭제: list_id, | |
| 438 | 삭제: })?; | |
| 431 | 추가: completed( | |
| 432 | 추가: self.event(Message::ListEnd { | |
| 433 | 추가: entry_count: catalog.members.len() as u32, | |
| 434 | 추가: list_id, | |
| 435 | 추가: }), | |
| 436 | 추가: self, | |
| 437 | 추가: )?; | |
| 439 | 438 | } else if let Action::Extract { |
| 440 | 439 | destination, |
| 441 | 440 | selection, |
| @@ -453,24 +452,24 @@ impl<W: Write> Job<W> { | ||
| 453 | 452 | let selected = match selection { |
| 454 | 453 | Selection::All => None, |
| 455 | 454 | Selection::EntryIds(ids) => { |
| 456 | 삭제: let n = ids.len(); | |
| 457 | 삭제: let set = ids.into_iter().collect::<BTreeSet<_>>(); | |
| 458 | 삭제: if expected.is_none() | |
| 459 | 삭제: || set.is_empty() | |
| 460 | 삭제: || n != set.len() | |
| 461 | 삭제: || set.iter().any(|id| *id as usize >= catalog.members.len()) | |
| 462 | 삭제: { | |
| 455 | 추가: if expected.is_none() || ids.is_empty() { | |
| 463 | 456 | return Err(ErrorCode::InvalidRequest); |
| 464 | 457 | } |
| 458 | 추가: let mut set = BTreeSet::new(); | |
| 459 | 추가: for id in ids { | |
| 460 | 추가: if id as usize >= catalog.members.len() || !set.insert(id) { | |
| 461 | 추가: return Err(ErrorCode::InvalidRequest); | |
| 462 | 추가: } | |
| 463 | 추가: completed(Ok(()), self)?; | |
| 464 | 추가: } | |
| 465 | 465 | Some(set) |
| 466 | 466 | } |
| 467 | 467 | }; |
| 468 | 삭제: if catalog | |
| 469 | 삭제: .members | |
| 470 | 삭제: .iter() | |
| 471 | 삭제: .any(|m| !matches!(m.entry.kind, EntryKind::File | EntryKind::Directory)) | |
| 472 | 삭제: { | |
| 473 | 삭제: return Err(ErrorCode::UnsafePath); | |
| 468 | 추가: for member in &catalog.members { | |
| 469 | 추가: if !matches!(member.entry.kind, EntryKind::File | EntryKind::Directory) { | |
| 470 | 추가: return Err(ErrorCode::UnsafePath); | |
| 471 | 추가: } | |
| 472 | 추가: completed(Ok(()), self)?; | |
| 474 | 473 | } |
| 475 | 474 | if catalog.format == Format::Gzip { |
| 476 | 475 | let name = gzip_output_name.ok_or(ErrorCode::InvalidRequest)?; |
| @@ -483,36 +482,33 @@ impl<W: Write> Job<W> { | ||
| 483 | 482 | } else if gzip_output_name.is_some() { |
| 484 | 483 | return Err(ErrorCode::InvalidRequest); |
| 485 | 484 | } |
| 486 | 삭제: let root = Dir::root(&destination.to_path()?)?; | |
| 487 | 삭제: let output_sizes = catalog | |
| 488 | 삭제: .members | |
| 489 | 삭제: .iter() | |
| 490 | 삭제: .filter(|m| { | |
| 491 | 삭제: m.entry.kind == EntryKind::File | |
| 492 | 삭제: && selected | |
| 493 | 삭제: .as_ref() | |
| 494 | 삭제: .is_none_or(|s| s.contains(&m.entry.entry_id)) | |
| 495 | 삭제: }) | |
| 496 | 삭제: .map(|m| (m.entry.name.clone(), m.entry.size)) | |
| 497 | 삭제: .collect::<Vec<_>>(); | |
| 498 | 삭제: let staged = if matches!(catalog.format, Format::Zip | Format::SevenZip) { | |
| 499 | 삭제: Some(( | |
| 500 | 삭제: &catalog.data, | |
| 501 | 삭제: catalog.members.iter().try_fold(0u64, |sum, m| { | |
| 502 | 삭제: sum.checked_add(m.entry.size).ok_or(ErrorCode::Limit) | |
| 503 | 삭제: })?, | |
| 504 | 삭제: )) | |
| 505 | 삭제: } else { | |
| 506 | 삭제: None | |
| 507 | 삭제: }; | |
| 485 | 추가: let root = completed(Dir::root(&destination.to_path()?), self)?; | |
| 486 | 추가: let mut output_sizes = Vec::new(); | |
| 487 | 추가: let mut staged_total = 0u64; | |
| 488 | 추가: let mut encrypted = false; | |
| 489 | 추가: for member in &catalog.members { | |
| 490 | 추가: if member.entry.kind == EntryKind::File | |
| 491 | 추가: && selected | |
| 492 | 추가: .as_ref() | |
| 493 | 추가: .is_none_or(|s| s.contains(&member.entry.entry_id)) | |
| 494 | 추가: { | |
| 495 | 추가: output_sizes.push((member.entry.name.clone(), member.entry.size)); | |
| 496 | 추가: } | |
| 497 | 추가: staged_total = staged_total | |
| 498 | 추가: .checked_add(member.entry.size) | |
| 499 | 추가: .ok_or(ErrorCode::Limit)?; | |
| 500 | 추가: encrypted |= member.entry.encrypted; | |
| 501 | 추가: completed(Ok(()), self)?; | |
| 502 | 추가: } | |
| 503 | 추가: let staged = matches!(catalog.format, Format::Zip | Format::SevenZip) | |
| 504 | 추가: .then_some((&catalog.data, staged_total)); | |
| 508 | 505 | // 선택 전에는 검증에 필요한 스테이징 공간만 계산함. |
| 509 | 506 | let initial_outputs = if self.interactive { |
| 510 | 507 | &[][..] |
| 511 | 508 | } else { |
| 512 | 509 | &output_sizes[..] |
| 513 | 510 | }; |
| 514 | 삭제: filesystem::preflight_space(&root, initial_outputs, staged)?; | |
| 515 | 삭제: let encrypted = catalog.members.iter().any(|m| m.entry.encrypted); | |
| 511 | 추가: filesystem::preflight_space_with(&root, initial_outputs, staged, self)?; | |
| 516 | 512 | if matches!(catalog.format, Format::Zip | Format::SevenZip) { |
| 517 | 513 | for attempt in 1..=3 { |
| 518 | 514 | let secret = if encrypted { |
| @@ -539,41 +535,46 @@ impl<W: Write> Job<W> { | ||
| 539 | 535 | } |
| 540 | 536 | let offsets = catalog.offsets; |
| 541 | 537 | let mut data = catalog.data; |
| 542 | 삭제: let members = catalog | |
| 543 | 삭제: .members | |
| 544 | 삭제: .into_iter() | |
| 545 | 삭제: .filter(|m| { | |
| 546 | 삭제: selected | |
| 547 | 삭제: .as_ref() | |
| 548 | 삭제: .is_none_or(|s| s.contains(&m.entry.entry_id)) | |
| 549 | 삭제: }) | |
| 550 | 삭제: .collect::<Vec<_>>(); | |
| 538 | 추가: let mut members = Vec::new(); | |
| 539 | 추가: for member in catalog.members { | |
| 540 | 추가: if selected | |
| 541 | 추가: .as_ref() | |
| 542 | 추가: .is_none_or(|s| s.contains(&member.entry.entry_id)) | |
| 543 | 추가: { | |
| 544 | 추가: members.push(member); | |
| 545 | 추가: } | |
| 546 | 추가: completed(Ok(()), self)?; | |
| 547 | 추가: } | |
| 551 | 548 | let dirs = archive::output_directories(&members, self)?; |
| 552 | 549 | let files = members |
| 553 | 550 | .iter() |
| 554 | 551 | .filter(|m| m.entry.kind == EntryKind::File) |
| 555 | 삭제: .collect::<Vec<_>>(); | |
| 552 | 추가: .map(|member| completed(Ok(member), self)) | |
| 553 | 추가: .collect::<Result<Vec<_>>>()?; | |
| 556 | 554 | let mut names = dirs |
| 557 | 555 | .iter() |
| 558 | 삭제: .map(|n| (n.clone(), EntryKind::Directory)) | |
| 559 | 삭제: .collect::<Vec<_>>(); | |
| 556 | 추가: .map(|name| completed(Ok((name.clone(), EntryKind::Directory)), self)) | |
| 557 | 추가: .collect::<Result<Vec<_>>>()?; | |
| 560 | 558 | names.extend( |
| 561 | 559 | files |
| 562 | 560 | .iter() |
| 563 | 삭제: .map(|m| (m.entry.name.clone(), EntryKind::File)), | |
| 561 | 추가: .map(|member| { | |
| 562 | 추가: completed(Ok((member.entry.name.clone(), EntryKind::File)), self) | |
| 563 | 추가: }) | |
| 564 | 추가: .collect::<Result<Vec<_>>>()?, | |
| 564 | 565 | ); |
| 565 | 삭제: filesystem::preflight_mode(&root, &names, self.interactive)?; | |
| 566 | 추가: filesystem::preflight_mode_with(&root, &names, self.interactive, self)?; | |
| 566 | 567 | if !self.interactive { |
| 567 | 삭제: filesystem::preflight_space(&root, &output_sizes, None)?; | |
| 568 | 추가: filesystem::preflight_space_with(&root, &output_sizes, None, self)?; | |
| 568 | 569 | } |
| 569 | 570 | let mut reserved = names |
| 570 | 571 | .iter() |
| 571 | 삭제: .map(|(name, _)| name.to_lowercase()) | |
| 572 | 삭제: .collect::<BTreeSet<_>>(); | |
| 572 | 추가: .map(|(name, _)| completed(Ok(name.to_lowercase()), self)) | |
| 573 | 추가: .collect::<Result<BTreeSet<_>>>()?; | |
| 573 | 574 | for name in dirs { |
| 574 | 575 | self.check()?; |
| 575 | 576 | let (created, durability, sync_error) = |
| 576 | 삭제: filesystem::directory(&root, &name)?; | |
| 577 | 추가: filesystem::directory_with(&root, &name, self)?; | |
| 577 | 578 | if created { |
| 578 | 579 | self.terminal.created_count += 1; |
| 579 | 580 | self.terminal.publication = Publication::Partial; |
| @@ -586,15 +587,18 @@ impl<W: Write> Job<W> { | ||
| 586 | 587 | if let Some(error) = sync_error { |
| 587 | 588 | return Err(error); |
| 588 | 589 | } |
| 589 | 삭제: self.activity()?; | |
| 590 | 추가: completed(Ok(()), self)?; | |
| 590 | 591 | } |
| 591 | 592 | } |
| 592 | 593 | for (index, m) in files.iter().enumerate() { |
| 593 | 삭제: data.seek(SeekFrom::Start(offsets[m.entry.entry_id as usize])) | |
| 594 | 삭제: .map_err(|_| ErrorCode::Io)?; | |
| 594 | 추가: completed( | |
| 595 | 추가: data.seek(SeekFrom::Start(offsets[m.entry.entry_id as usize])) | |
| 596 | 추가: .map_err(|_| ErrorCode::Io), | |
| 597 | 추가: self, | |
| 598 | 추가: )?; | |
| 595 | 599 | self.check()?; |
| 596 | 600 | let existing = if self.interactive { |
| 597 | 삭제: filesystem::existing(&root, &m.entry.name)? | |
| 601 | 추가: filesystem::existing_with(&root, &m.entry.name, self)? | |
| 598 | 602 | } else { |
| 599 | 603 | None |
| 600 | 604 | }; |
| @@ -609,21 +613,25 @@ impl<W: Write> Job<W> { | ||
| 609 | 613 | } else if choice == ConflictChoice::Overwrite { |
| 610 | 614 | replace = Some(existing); |
| 611 | 615 | } |
| 612 | 삭제: self.event(Message::ConflictResolved { | |
| 613 | 삭제: entry_id: m.entry.entry_id, | |
| 614 | 삭제: relative_name: name.clone(), | |
| 615 | 삭제: choice, | |
| 616 | 삭제: })?; | |
| 616 | 추가: completed( | |
| 617 | 추가: self.event(Message::ConflictResolved { | |
| 618 | 추가: entry_id: m.entry.entry_id, | |
| 619 | 추가: relative_name: name.clone(), | |
| 620 | 추가: choice, | |
| 621 | 추가: }), | |
| 622 | 추가: self, | |
| 623 | 추가: )?; | |
| 617 | 624 | if choice == ConflictChoice::Skip { |
| 618 | 625 | continue; |
| 619 | 626 | } |
| 620 | 627 | } |
| 621 | 628 | if self.interactive { |
| 622 | 629 | // 건너뛴 파일을 제외하고 이번에 게시할 파일의 공간을 확인함. |
| 623 | 삭제: filesystem::preflight_space( | |
| 630 | 추가: filesystem::preflight_space_with( | |
| 624 | 631 | &root, |
| 625 | 632 | &[(name.clone(), m.entry.size)], |
| 626 | 633 | None, |
| 634 | 추가: self, | |
| 627 | 635 | )?; |
| 628 | 636 | } |
| 629 | 637 | self.output_reader( |
| @@ -653,8 +661,16 @@ impl<W: Write> Job<W> { | ||
| 653 | 661 | .and_then(|n| n.to_str()) |
| 654 | 662 | .ok_or(ErrorCode::InvalidRequest)?; |
| 655 | 663 | let name = archive::valid_name(leaf, false)?; |
| 656 | 삭제: let root = Dir::root(output.parent().ok_or(ErrorCode::InvalidRequest)?)?; | |
| 657 | 삭제: filesystem::preflight(&root, &[(name.clone(), EntryKind::File)])?; | |
| 664 | 추가: let root = completed( | |
| 665 | 추가: Dir::root(output.parent().ok_or(ErrorCode::InvalidRequest)?), | |
| 666 | 추가: self, | |
| 667 | 추가: )?; | |
| 668 | 추가: filesystem::preflight_mode_with( | |
| 669 | 추가: &root, | |
| 670 | 추가: &[(name.clone(), EntryKind::File)], | |
| 671 | 추가: false, | |
| 672 | 추가: self, | |
| 673 | 추가: )?; | |
| 658 | 674 | let members = crate::create::plan(&sources, limits, self)?; |
| 659 | 675 | let secret = if encryption == Encryption::Aes256 { |
| 660 | 676 | let secret = self.password(PasswordPurpose::Encrypt, 1)?; |
| @@ -672,7 +688,7 @@ impl<W: Write> Job<W> { | ||
| 672 | 688 | secret.as_ref().map(|s| s.0.as_slice()), |
| 673 | 689 | self, |
| 674 | 690 | )?; |
| 675 | 삭제: filesystem::preflight_space(&root, &[(name.clone(), length)], None)?; | |
| 691 | 추가: filesystem::preflight_space_with(&root, &[(name.clone(), length)], None, self)?; | |
| 676 | 692 | self.output_reader(&root, &name, &mut data, length, None, true, None)?; |
| 677 | 693 | self.terminal.publication = Publication::Complete; |
| 678 | 694 | } |
| @@ -96,13 +96,17 @@ struct Streams { | ||
| 96 | 96 | folders: Vec<Folder>, |
| 97 | 97 | } |
| 98 | 98 | impl Streams { |
| 99 | 삭제: fn read(r: &mut Reader<'_>, limits: Limits) -> Result<Self> { | |
| 99 | 추가: fn read( | |
| 100 | 추가: r: &mut Reader<'_>, | |
| 101 | 추가: limits: Limits, | |
| 102 | 추가: check: &mut impl crate::resources::Monitor, | |
| 103 | 추가: ) -> Result<Self> { | |
| 100 | 104 | r.expect(6)?; |
| 101 | 105 | let position = r.number(limits.input as usize)?; |
| 102 | 106 | let count = r.number(limits.entries as usize)?; |
| 103 | 107 | r.expect(9)?; |
| 104 | 108 | let packed = (0..count) |
| 105 | 삭제: .map(|_| r.number(limits.input as usize)) | |
| 109 | 추가: .map(|_| crate::resources::completed(r.number(limits.input as usize), check)) | |
| 106 | 110 | .collect::<Result<Vec<_>>>()?; |
| 107 | 111 | let mut tag = r.byte()?; |
| 108 | 112 | let packed_crcs = if tag == 10 { |
| @@ -157,6 +161,7 @@ impl Streams { | ||
| 157 | 161 | sizes: Vec::new(), |
| 158 | 162 | crcs: Vec::new(), |
| 159 | 163 | }); |
| 164 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 160 | 165 | } |
| 161 | 166 | r.expect(12)?; |
| 162 | 167 | let mut total = 0usize; |
| @@ -166,11 +171,13 @@ impl Streams { | ||
| 166 | 171 | .checked_add(folder.size) |
| 167 | 172 | .filter(|n| *n <= limits.output as usize) |
| 168 | 173 | .ok_or(ErrorCode::Limit)?; |
| 174 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 169 | 175 | } |
| 170 | 176 | let mut tag = r.byte()?; |
| 171 | 177 | if tag == 10 { |
| 172 | 178 | for (f, crc) in folders.iter_mut().zip(r.digests(num)?) { |
| 173 | 179 | f.crc = crc; |
| 180 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 174 | 181 | } |
| 175 | 182 | tag = r.byte()?; |
| 176 | 183 | } |
| @@ -190,6 +197,7 @@ impl Streams { | ||
| 190 | 197 | .checked_add(*n) |
| 191 | 198 | .filter(|n| *n <= limits.entries as usize) |
| 192 | 199 | .ok_or(ErrorCode::Limit)?; |
| 200 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 193 | 201 | } |
| 194 | 202 | tag = r.byte()?; |
| 195 | 203 | } |
| @@ -204,6 +212,7 @@ impl Streams { | ||
| 204 | 212 | .filter(|n| *n <= folder.size) |
| 205 | 213 | .ok_or(ErrorCode::Integrity)?; |
| 206 | 214 | folder.sizes.push(n); |
| 215 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 207 | 216 | } |
| 208 | 217 | if *count > 0 { |
| 209 | 218 | folder.sizes.push(folder.size - total); |
| @@ -229,6 +238,7 @@ impl Streams { | ||
| 229 | 238 | } else { |
| 230 | 239 | (0..*n).map(|_| digests.next().unwrap()).collect() |
| 231 | 240 | }; |
| 241 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 232 | 242 | } |
| 233 | 243 | if tag != 0 { |
| 234 | 244 | return Err(ErrorCode::Integrity); |
| @@ -237,6 +247,7 @@ impl Streams { | ||
| 237 | 247 | } else { |
| 238 | 248 | for f in &mut folders { |
| 239 | 249 | f.crcs.push(f.crc); |
| 250 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 240 | 251 | } |
| 241 | 252 | } |
| 242 | 253 | if tag != 0 { |
| @@ -254,6 +265,7 @@ impl Streams { | ||
| 254 | 265 | if *n == 0 && f.size != 0 { |
| 255 | 266 | return Err(ErrorCode::Integrity); |
| 256 | 267 | } |
| 268 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 257 | 269 | } |
| 258 | 270 | Ok(Self { |
| 259 | 271 | position, |
| @@ -285,6 +297,7 @@ impl Streams { | ||
| 285 | 297 | } |
| 286 | 298 | ranges.push((at, size)); |
| 287 | 299 | at = end; |
| 300 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 288 | 301 | } |
| 289 | 302 | Ok(ranges) |
| 290 | 303 | } |
| @@ -297,7 +310,10 @@ impl Streams { | ||
| 297 | 310 | ) -> Result<()> { |
| 298 | 311 | use std::io::{Read, Seek, SeekFrom, Write}; |
| 299 | 312 | let total = self.folders.iter().try_fold(0u64, |sum, f| { |
| 300 | 삭제: sum.checked_add(f.size as u64).ok_or(ErrorCode::Limit) | |
| 313 | 추가: crate::resources::completed( | |
| 314 | 추가: sum.checked_add(f.size as u64).ok_or(ErrorCode::Limit), | |
| 315 | 추가: check, | |
| 316 | 추가: ) | |
| 301 | 317 | })?; |
| 302 | 318 | crate::space::ensure(output, total)?; |
| 303 | 319 | for (f, (start, size)) in self.folders.iter().zip(ranges) { |
| @@ -332,7 +348,7 @@ impl Streams { | ||
| 332 | 348 | .write_all(&buffer[..n]) |
| 333 | 349 | .map_err(crate::space::io_error)?; |
| 334 | 350 | remaining -= n as u64; |
| 335 | 삭제: check.activity()?; | |
| 351 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 336 | 352 | } |
| 337 | 353 | } |
| 338 | 354 | [3, 1, 1] | [0x21] => crate::lzma::decode_stream( |
| @@ -368,10 +384,14 @@ impl Streams { | ||
| 368 | 384 | } |
| 369 | 385 | } |
| 370 | 386 | at = at.checked_add(*size as u64).ok_or(ErrorCode::Integrity)?; |
| 387 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 371 | 388 | } |
| 372 | 삭제: output | |
| 373 | 삭제: .seek(SeekFrom::Start(base + f.size as u64)) | |
| 374 | 삭제: .map_err(crate::space::io_error)?; | |
| 389 | 추가: crate::resources::completed( | |
| 390 | 추가: output | |
| 391 | 추가: .seek(SeekFrom::Start(base + f.size as u64)) | |
| 392 | 추가: .map_err(crate::space::io_error), | |
| 393 | 추가: check, | |
| 394 | 추가: )?; | |
| 375 | 395 | } |
| 376 | 396 | Ok(()) |
| 377 | 397 | } |
| @@ -395,7 +415,7 @@ fn digest( | ||
| 395 | 415 | .map_err(crate::space::io_error)?; |
| 396 | 416 | crc = crc32(crc, &buffer[..n]); |
| 397 | 417 | remaining -= n as u64; |
| 398 | 삭제: check.activity()?; | |
| 418 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 399 | 419 | } |
| 400 | 420 | Ok(crc) |
| 401 | 421 | } |
| @@ -444,7 +464,7 @@ fn files( | ||
| 444 | 464 | let mut decoded = Vec::new(); |
| 445 | 465 | let mut budget = MetadataBudget::default(); |
| 446 | 466 | for _ in 0..count { |
| 447 | 삭제: check.activity()?; | |
| 467 | 추가: check.check()?; | |
| 448 | 468 | let mut units = Vec::new(); |
| 449 | 469 | loop { |
| 450 | 470 | let n = u16::from_le_bytes(value.take(2)?.try_into().unwrap()); |
| @@ -459,6 +479,7 @@ fn files( | ||
| 459 | 479 | let name = String::from_utf16(&units).map_err(|_| ErrorCode::Integrity)?; |
| 460 | 480 | budget.charge_with(&name, check.metadata_limits())?; |
| 461 | 481 | decoded.push(name); |
| 482 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 462 | 483 | } |
| 463 | 484 | names = Some(decoded); |
| 464 | 485 | } |
| @@ -471,6 +492,7 @@ fn files( | ||
| 471 | 492 | if set { |
| 472 | 493 | *attr = Some(u32::from_le_bytes(value.take(4)?.try_into().unwrap())); |
| 473 | 494 | } |
| 495 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 474 | 496 | } |
| 475 | 497 | } |
| 476 | 498 | 18..=20 => { |
| @@ -501,6 +523,7 @@ fn files( | ||
| 501 | 523 | for (folder, compressed) in streams.folders.iter().zip(&streams.packed) { |
| 502 | 524 | for (i, size) in folder.sizes.iter().enumerate() { |
| 503 | 525 | descriptions.push((*size, if i == 0 { *compressed } else { 0 })); |
| 526 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 504 | 527 | } |
| 505 | 528 | } |
| 506 | 529 | } |
| @@ -547,6 +570,7 @@ fn files( | ||
| 547 | 570 | }, |
| 548 | 571 | data: Vec::new(), |
| 549 | 572 | }); |
| 573 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 550 | 574 | } |
| 551 | 575 | if descriptions.next().is_some() { |
| 552 | 576 | return Err(ErrorCode::Integrity); |
| @@ -618,7 +642,7 @@ pub(crate) fn open( | ||
| 618 | 642 | output: check.metadata_limits().bytes as u64, |
| 619 | 643 | ..limits |
| 620 | 644 | }; |
| 621 | 삭제: let streams = Streams::read(&mut r, header_limits)?; | |
| 645 | 추가: let streams = Streams::read(&mut r, header_limits, check)?; | |
| 622 | 646 | r.end()?; |
| 623 | 647 | if streams.folders.len() != 1 || streams.folders[0].sizes.len() != 1 { |
| 624 | 648 | return Err(ErrorCode::UnsupportedFeature); |
| @@ -649,7 +673,7 @@ pub(crate) fn open( | ||
| 649 | 673 | return Err(ErrorCode::UnsupportedFeature); |
| 650 | 674 | } |
| 651 | 675 | if tag == 4 { |
| 652 | 삭제: streams = Some(Streams::read(&mut r, limits)?); | |
| 676 | 추가: streams = Some(Streams::read(&mut r, limits, check)?); | |
| 653 | 677 | tag = r.byte()?; |
| 654 | 678 | } |
| 655 | 679 | let (members, stream_indices) = if tag == 5 { |
| @@ -664,13 +688,16 @@ pub(crate) fn open( | ||
| 664 | 688 | } |
| 665 | 689 | r.end()?; |
| 666 | 690 | let total = members.iter().try_fold(0u64, |n, m| { |
| 667 | 삭제: n.checked_add(m.entry.size).ok_or(ErrorCode::Limit) | |
| 691 | 추가: crate::resources::completed(n.checked_add(m.entry.size).ok_or(ErrorCode::Limit), check) | |
| 668 | 692 | })?; |
| 669 | 693 | let packed = streams |
| 670 | 694 | .as_ref() |
| 671 | 695 | .map(|s| { |
| 672 | 696 | s.packed.iter().try_fold(0u64, |sum, size| { |
| 673 | 삭제: sum.checked_add(*size as u64).ok_or(ErrorCode::Integrity) | |
| 697 | 추가: crate::resources::completed( | |
| 698 | 추가: sum.checked_add(*size as u64).ok_or(ErrorCode::Integrity), | |
| 699 | 추가: check, | |
| 700 | 추가: ) | |
| 674 | 701 | }) |
| 675 | 702 | }) |
| 676 | 703 | .transpose()?; |
| @@ -684,7 +711,7 @@ pub(crate) fn open( | ||
| 684 | 711 | }, |
| 685 | 712 | Some(&data), |
| 686 | 713 | )?; |
| 687 | 삭제: check.activity()?; | |
| 714 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 688 | 715 | let mut offsets = vec![0; members.len()]; |
| 689 | 716 | if let Some(streams) = streams { |
| 690 | 717 | if streams.folders.iter().map(|f| f.sizes.len()).sum::<usize>() != stream_indices.len() { |
| @@ -697,6 +724,7 @@ pub(crate) fn open( | ||
| 697 | 724 | for size in &f.sizes { |
| 698 | 725 | offsets[ids.next().ok_or(ErrorCode::Integrity)?] = at; |
| 699 | 726 | at = at.checked_add(*size as u64).ok_or(ErrorCode::Limit)?; |
| 727 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 700 | 728 | } |
| 701 | 729 | } |
| 702 | 730 | if at > limits.output { |
| @@ -738,6 +766,7 @@ pub(crate) fn parse( | ||
| 738 | 766 | .take(member.entry.size) |
| 739 | 767 | .read_to_end(&mut member.data) |
| 740 | 768 | .map_err(crate::space::io_error)?; |
| 769 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 741 | 770 | } |
| 742 | 771 | } |
| 743 | 772 | Ok(catalog.members) |
| @@ -73,9 +73,23 @@ pub(crate) fn temporary() -> Result<File> { | ||
| 73 | 73 | #[derive(Clone, Copy, Debug)] |
| 74 | 74 | pub(crate) enum Step { |
| 75 | 75 | Check, |
| 76 | 추가: Activity, | |
| 76 | 77 | Read { bytes: u64, total: u64 }, |
| 77 | 78 | } |
| 78 | 79 | |
| 80 | 추가: struct Progress<'a, F>(&'a mut F); | |
| 81 | 추가: impl<F: FnMut(Step) -> Result<()>> crate::resources::Monitor for Progress<'_, F> { | |
| 82 | 추가: fn check(&mut self) -> Result<()> { | |
| 83 | 추가: self.0(Step::Check) | |
| 84 | 추가: } | |
| 85 | 추가: fn activity(&mut self) -> Result<()> { | |
| 86 | 추가: self.0(Step::Activity) | |
| 87 | 추가: } | |
| 88 | 추가: } | |
| 89 | 추가: fn completed<T>(result: Result<T>, step: &mut impl FnMut(Step) -> Result<()>) -> Result<T> { | |
| 90 | 추가: crate::resources::completed(result, &mut Progress(step)) | |
| 91 | 추가: } | |
| 92 | 추가: | |
| 79 | 93 | pub(crate) struct Snapshot { |
| 80 | 94 | pub file: File, |
| 81 | 95 | pub len: u64, |
| @@ -101,15 +115,18 @@ impl Snapshot { | ||
| 101 | 115 | use std::os::windows::fs::OpenOptionsExt; |
| 102 | 116 | options.share_mode(1); |
| 103 | 117 | } |
| 104 | 삭제: let mut source = options.open(path).map_err(|_| ErrorCode::Io)?; | |
| 118 | 추가: let mut source = completed(options.open(path).map_err(|_| ErrorCode::Io), step)?; | |
| 105 | 119 | let snapshot = Self::capture_reporting(&mut source, limit, step)?; |
| 106 | 삭제: let named = options.open(path).map_err(|_| ErrorCode::SourceChanged)?; | |
| 120 | 추가: let named = completed( | |
| 121 | 추가: options.open(path).map_err(|_| ErrorCode::SourceChanged), | |
| 122 | 추가: step, | |
| 123 | 추가: )?; | |
| 107 | 124 | if filesystem::object(&named)? != snapshot.object |
| 108 | 125 | || !named.metadata().map_err(|_| ErrorCode::Io)?.is_file() |
| 109 | 126 | { |
| 110 | 127 | return Err(ErrorCode::SourceChanged); |
| 111 | 128 | } |
| 112 | 삭제: Ok(snapshot) | |
| 129 | 추가: completed(Ok(snapshot), step) | |
| 113 | 130 | } |
| 114 | 131 | pub(crate) fn capture( |
| 115 | 132 | source: &mut File, |
| @@ -118,7 +135,8 @@ impl Snapshot { | ||
| 118 | 135 | ) -> Result<Self> { |
| 119 | 136 | Self::capture_reporting(source, limit, &mut |step| match step { |
| 120 | 137 | Step::Check => check.check(), |
| 121 | 삭제: Step::Read { .. } => check.activity(), | |
| 138 | 추가: Step::Activity => crate::resources::completed(Ok(()), check), | |
| 139 | 추가: Step::Read { .. } => check.check(), | |
| 122 | 140 | }) |
| 123 | 141 | } |
| 124 | 142 | fn capture_reporting( |
| @@ -126,7 +144,7 @@ impl Snapshot { | ||
| 126 | 144 | limit: u64, |
| 127 | 145 | step: &mut impl FnMut(Step) -> Result<()>, |
| 128 | 146 | ) -> Result<Self> { |
| 129 | 삭제: let before = source.metadata().map_err(|_| ErrorCode::Io)?; | |
| 147 | 추가: let before = completed(source.metadata().map_err(|_| ErrorCode::Io), step)?; | |
| 130 | 148 | if !before.is_file() { |
| 131 | 149 | return Err(ErrorCode::InvalidRequest); |
| 132 | 150 | } |
| @@ -135,8 +153,8 @@ impl Snapshot { | ||
| 135 | 153 | } |
| 136 | 154 | source.rewind().map_err(|_| ErrorCode::Io)?; |
| 137 | 155 | let object = filesystem::object(&source)?; |
| 138 | 삭제: let mut file = temporary()?; | |
| 139 | 삭제: crate::space::ensure(&file, before.len())?; | |
| 156 | 추가: let mut file = completed(temporary(), step)?; | |
| 157 | 추가: completed(crate::space::ensure(&file, before.len()), step)?; | |
| 140 | 158 | let mut buffer = zeroize::Zeroizing::new([0; 65536]); |
| 141 | 159 | let mut hash = Sha256::new(); |
| 142 | 160 | let mut len = 0u64; |
| @@ -144,7 +162,10 @@ impl Snapshot { | ||
| 144 | 162 | let mut reported = std::time::Instant::now(); |
| 145 | 163 | loop { |
| 146 | 164 | step(Step::Check)?; |
| 147 | 삭제: let n = source.read(&mut buffer[..]).map_err(|_| ErrorCode::Io)?; | |
| 165 | 추가: let n = completed( | |
| 166 | 추가: source.read(&mut buffer[..]).map_err(|_| ErrorCode::Io), | |
| 167 | 추가: step, | |
| 168 | 추가: )?; | |
| 148 | 169 | if n == 0 { |
| 149 | 170 | break; |
| 150 | 171 | } |
| @@ -152,8 +173,10 @@ impl Snapshot { | ||
| 152 | 173 | .checked_add(n as u64) |
| 153 | 174 | .filter(|n| *n <= limit) |
| 154 | 175 | .ok_or(ErrorCode::Limit)?; |
| 155 | 삭제: file.write_all(&buffer[..n]) | |
| 156 | 삭제: .map_err(crate::space::io_error)?; | |
| 176 | 추가: completed( | |
| 177 | 추가: file.write_all(&buffer[..n]).map_err(crate::space::io_error), | |
| 178 | 추가: step, | |
| 179 | 추가: )?; | |
| 157 | 180 | hash.update(&buffer[..n]); |
| 158 | 181 | // 큰 파일에서도 진행이 보이도록 일정 간격으로만 알림. |
| 159 | 182 | if reported.elapsed() >= std::time::Duration::from_millis(200) { |
| @@ -170,7 +193,10 @@ impl Snapshot { | ||
| 170 | 193 | { |
| 171 | 194 | return Err(ErrorCode::SourceChanged); |
| 172 | 195 | } |
| 173 | 삭제: file.seek(SeekFrom::Start(0)).map_err(|_| ErrorCode::Io)?; | |
| 196 | 추가: completed( | |
| 197 | 추가: file.seek(SeekFrom::Start(0)).map_err(|_| ErrorCode::Io), | |
| 198 | 추가: step, | |
| 199 | 추가: )?; | |
| 174 | 200 | Ok(Self { |
| 175 | 201 | file, |
| 176 | 202 | len, |
| @@ -134,7 +134,7 @@ fn tar( | ||
| 134 | 134 | if add(cursor, 512)? > len { |
| 135 | 135 | return Err(ErrorCode::Integrity); |
| 136 | 136 | } |
| 137 | 삭제: at(&mut data, cursor, &mut header)?; | |
| 137 | 추가: crate::resources::completed(at(&mut data, cursor, &mut header), check)?; | |
| 138 | 138 | if header.iter().all(|b| *b == 0) { |
| 139 | 139 | if add(cursor, 1024)? > len || len % 512 != 0 { |
| 140 | 140 | return Err(ErrorCode::Integrity); |
| @@ -149,7 +149,7 @@ fn tar( | ||
| 149 | 149 | return Err(ErrorCode::Integrity); |
| 150 | 150 | } |
| 151 | 151 | remaining -= n as u64; |
| 152 | 삭제: check.activity()?; | |
| 152 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 153 | 153 | } |
| 154 | 154 | break; |
| 155 | 155 | } |
| @@ -202,7 +202,7 @@ fn tar( | ||
| 202 | 202 | }, |
| 203 | 203 | Some(&data), |
| 204 | 204 | )?; |
| 205 | 삭제: check.activity()?; | |
| 205 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 206 | 206 | let start = add(cursor, 512)?; |
| 207 | 207 | cursor = add( |
| 208 | 208 | start, |
| @@ -225,6 +225,7 @@ fn tar( | ||
| 225 | 225 | }, |
| 226 | 226 | data: Vec::new(), |
| 227 | 227 | }); |
| 228 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 228 | 229 | } |
| 229 | 230 | archive::validate_members_with(&members, check)?; |
| 230 | 231 | Ok(Catalog { |
| @@ -265,6 +266,7 @@ fn inflate( | ||
| 265 | 266 | } |
| 266 | 267 | remaining -= have as u64; |
| 267 | 268 | used = 0; |
| 269 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 268 | 270 | } |
| 269 | 271 | let a = stream.total_in(); |
| 270 | 272 | let b = stream.total_out(); |
| @@ -286,12 +288,14 @@ fn inflate( | ||
| 286 | 288 | }, |
| 287 | 289 | Some(output), |
| 288 | 290 | )?; |
| 289 | 삭제: if n != 0 { | |
| 290 | 삭제: check.activity()?; | |
| 291 | 추가: if n != 0 || stream.total_in() != a { | |
| 292 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 291 | 293 | } |
| 292 | 294 | crc = crc32(crc, &plain[..n]); |
| 293 | 295 | crate::space::ensure(output, n as u64)?; |
| 294 | 삭제: io(output.write_all(&plain[..n]))?; | |
| 296 | 추가: if n != 0 { | |
| 297 | 추가: crate::resources::completed(io(output.write_all(&plain[..n])), check)?; | |
| 298 | 추가: } | |
| 295 | 299 | if status == Status::StreamEnd { |
| 296 | 300 | break; |
| 297 | 301 | } |
| @@ -509,6 +513,7 @@ fn zip( | ||
| 509 | 513 | return Err(ErrorCode::Integrity); |
| 510 | 514 | } |
| 511 | 515 | let h = bytes(source, cursor, 46)?; |
| 516 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 512 | 517 | if &h[..4] != b"PK\x01\x02" { |
| 513 | 518 | return Err(ErrorCode::Integrity); |
| 514 | 519 | } |
| @@ -574,7 +579,7 @@ fn zip( | ||
| 574 | 579 | }, |
| 575 | 580 | Some(source), |
| 576 | 581 | )?; |
| 577 | 삭제: check.activity()?; | |
| 582 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 578 | 583 | let mode = u32at(&h, 38) >> 16; |
| 579 | 584 | let kind = match mode & 0xf000 { |
| 580 | 585 | 0xa000 => EntryKind::Link, |
| @@ -597,6 +602,7 @@ fn zip( | ||
| 597 | 602 | return Err(ErrorCode::Integrity); |
| 598 | 603 | } |
| 599 | 604 | let lh = bytes(source, local, 30)?; |
| 605 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 600 | 606 | if &lh[..4] != b"PK\x03\x04" |
| 601 | 607 | || u16at(&lh, 6) != flags |
| 602 | 608 | || u16at(&lh, 8) != method |
| @@ -675,6 +681,7 @@ fn zip( | ||
| 675 | 681 | data: Vec::new(), |
| 676 | 682 | }); |
| 677 | 683 | cursor = next; |
| 684 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 678 | 685 | } |
| 679 | 686 | if cursor != central_end { |
| 680 | 687 | return Err(ErrorCode::Integrity); |
| @@ -686,6 +693,7 @@ fn zip( | ||
| 686 | 693 | return Err(ErrorCode::Integrity); |
| 687 | 694 | } |
| 688 | 695 | next = b; |
| 696 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 689 | 697 | } |
| 690 | 698 | if next != central { |
| 691 | 699 | return Err(ErrorCode::Integrity); |
| @@ -711,6 +719,7 @@ fn zip( | ||
| 711 | 719 | check.check()?; |
| 712 | 720 | offsets.push(io(data.stream_position())?); |
| 713 | 721 | if !decode { |
| 722 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 714 | 723 | continue; |
| 715 | 724 | } |
| 716 | 725 | let (decoder, start, length) = if packed.flags & 1 != 0 { |
| @@ -754,16 +763,17 @@ fn zip( | ||
| 754 | 763 | .checked_add(n as u64) |
| 755 | 764 | .filter(|n| *n <= member.entry.size) |
| 756 | 765 | .ok_or(ErrorCode::Integrity)?; |
| 757 | 삭제: check.activity()?; | |
| 766 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 758 | 767 | crate::space::ensure(&data, n as u64)?; |
| 759 | 768 | crc = crc32(crc, &buffer[..n]); |
| 760 | 삭제: io(data.write_all(&buffer[..n]))?; | |
| 769 | 추가: crate::resources::completed(io(data.write_all(&buffer[..n])), check)?; | |
| 761 | 770 | } |
| 762 | 771 | (total, crc) |
| 763 | 772 | }; |
| 764 | 773 | if size != member.entry.size || packed.crc.is_some_and(|c| c != crc) { |
| 765 | 774 | return Err(ErrorCode::Integrity); |
| 766 | 775 | } |
| 776 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 767 | 777 | } |
| 768 | 778 | Ok(Catalog { |
| 769 | 779 | format: Format::Zip, |
| @@ -38,7 +38,9 @@ fn run_record( | ||
| 38 | 38 | Command::new("cc") |
| 39 | 39 | .args(["-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror"]) |
| 40 | 40 | .arg(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join( |
| 41 | 삭제: if fault.starts_with("clock-") { | |
| 41 | 추가: if fault.starts_with("phase-") { | |
| 42 | 추가: "../../tests/rust-archive-worker/phase_clock.c" | |
| 43 | 추가: } else if fault.starts_with("clock-") { | |
| 42 | 44 | "../../tests/rust-archive-worker/progress_clock.c" |
| 43 | 45 | } else { |
| 44 | 46 | "../../tests/rust-archive-worker/io_fault.c" |
| @@ -938,3 +940,7 @@ fn large_selection_reaches_worker_permission_and_destination_checks() { | ||
| 938 | 940 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 939 | 941 | } |
| 940 | 942 | } |
| 943 | 추가: | |
| 944 | 추가: #[cfg(target_os = "linux")] | |
| 945 | 추가: #[path = "item_progress.rs"] | |
| 946 | 추가: mod item_progress; |
| @@ -21,6 +21,13 @@ elif case == "many-entries": | ||
| 21 | 21 | with zipfile.ZipFile(root / "input", "w") as archive: |
| 22 | 22 | for entry_id in range(200_000): |
| 23 | 23 | archive.writestr(f"e{entry_id}", b"") |
| 24 | 추가: elif case in {"phase-directories", "phase-files"}: | |
| 25 | 추가: with zipfile.ZipFile(root / "input", "w") as archive: | |
| 26 | 추가: for entry_id in range(8): | |
| 27 | 추가: archive.writestr( | |
| 28 | 추가: f"entry-{entry_id}/" if case == "phase-directories" else f"entry-{entry_id}", | |
| 29 | 추가: b"" if case == "phase-directories" else b"x", | |
| 30 | 추가: ) | |
| 24 | 31 | elif case == "selection-entries": |
| 25 | 32 | with zipfile.ZipFile(root / "input", "w") as archive: |
| 26 | 33 | for entry_id in range(32_770): |
| @@ -0,0 +1,210 @@ | ||
| 1 | 추가: use super::*; | |
| 2 | 추가: | |
| 3 | 추가: fn phase_setup(phase: &str) -> (Scratch, GuardedStart) { | |
| 4 | 추가: let s = setup(); | |
| 5 | 추가: let directories = matches!(phase, "preflight" | "directory" | "mkdir"); | |
| 6 | 추가: generate( | |
| 7 | 추가: &s, | |
| 8 | 추가: if directories { | |
| 9 | 추가: "phase-directories" | |
| 10 | 추가: } else { | |
| 11 | 추가: "phase-files" | |
| 12 | 추가: }, | |
| 13 | 추가: ); | |
| 14 | 추가: if matches!(phase, "preflight" | "directory") { | |
| 15 | 추가: for id in 0..8 { | |
| 16 | 추가: use std::os::unix::fs::DirBuilderExt; | |
| 17 | 추가: fs::DirBuilder::new() | |
| 18 | 추가: .mode(0o700) | |
| 19 | 추가: .create(s.0.join(format!("output/entry-{id}"))) | |
| 20 | 추가: .unwrap(); | |
| 21 | 추가: } | |
| 22 | 추가: } | |
| 23 | 추가: let mut start = request(&s, 64, 128); | |
| 24 | 추가: match phase { | |
| 25 | 추가: "source" | "header" => { | |
| 26 | 추가: start = create_progress_request( | |
| 27 | 추가: &s, | |
| 28 | 추가: if phase == "header" { | |
| 29 | 추가: EntryKind::Directory | |
| 30 | 추가: } else { | |
| 31 | 추가: EntryKind::File | |
| 32 | 추가: }, | |
| 33 | 추가: if phase == "header" { 0 } else { 1 }, | |
| 34 | 추가: Method::Store, | |
| 35 | 추가: ); | |
| 36 | 추가: } | |
| 37 | 추가: "list" => { | |
| 38 | 추가: start.start.action = Action::List { | |
| 39 | 추가: archive: s.path("input"), | |
| 40 | 추가: } | |
| 41 | 추가: } | |
| 42 | 추가: "rename" => { | |
| 43 | 추가: let members = [archive::Member { | |
| 44 | 추가: entry: Entry { | |
| 45 | 추가: entry_id: 0, | |
| 46 | 추가: name: "file.txt".into(), | |
| 47 | 추가: kind: EntryKind::File, | |
| 48 | 추가: size: 1, | |
| 49 | 추가: compressed_size: 1, | |
| 50 | 추가: encrypted: false, | |
| 51 | 추가: }, | |
| 52 | 추가: data: b"x".to_vec(), | |
| 53 | 추가: }]; | |
| 54 | 추가: fs::write( | |
| 55 | 추가: s.0.join("input"), | |
| 56 | 추가: archive::create_zip(&members, Method::Store, Limits::default(), &mut || Ok(())) | |
| 57 | 추가: .unwrap(), | |
| 58 | 추가: ) | |
| 59 | 추가: .unwrap(); | |
| 60 | 추가: fs::write(s.0.join("output/file.txt"), b"old").unwrap(); | |
| 61 | 추가: for id in 1..=8 { | |
| 62 | 추가: fs::write(s.0.join(format!("output/file ({id}).txt")), b"old").unwrap(); | |
| 63 | 추가: } | |
| 64 | 추가: start.interactive = true; | |
| 65 | 추가: } | |
| 66 | 추가: "overwrite" => { | |
| 67 | 추가: for id in 0..8 { | |
| 68 | 추가: fs::write(s.0.join(format!("output/entry-{id}")), b"old").unwrap(); | |
| 69 | 추가: } | |
| 70 | 추가: start.interactive = true; | |
| 71 | 추가: } | |
| 72 | 추가: _ => {} | |
| 73 | 추가: } | |
| 74 | 추가: (s, start) | |
| 75 | 추가: } | |
| 76 | 추가: | |
| 77 | 추가: fn phase_reply(event: &Message, phase: &str) -> Option<Vec<Message>> { | |
| 78 | 추가: if let Message::ConflictRequired { challenge_id, .. } = event { | |
| 79 | 추가: return Some(vec![Message::ConflictReply { | |
| 80 | 추가: challenge_id: *challenge_id, | |
| 81 | 추가: choice: if phase == "rename" { | |
| 82 | 추가: ConflictChoice::Rename | |
| 83 | 추가: } else { | |
| 84 | 추가: ConflictChoice::Overwrite | |
| 85 | 추가: }, | |
| 86 | 추가: apply_to_remaining: true, | |
| 87 | 추가: }]); | |
| 88 | 추가: } | |
| 89 | 추가: approve(event) | |
| 90 | 추가: } | |
| 91 | 추가: | |
| 92 | 추가: #[test] | |
| 93 | 추가: fn existing_directory_lookups_refresh_progress_after_permission() { | |
| 94 | 추가: for approved in [false, true] { | |
| 95 | 추가: let (s, mut start) = phase_setup("directory"); | |
| 96 | 추가: if !approved { | |
| 97 | 추가: start.ceiling = start.start.limits; | |
| 98 | 추가: } | |
| 99 | 추가: let events = run_fault(&s, start, Some("phase-directory"), approve); | |
| 100 | 추가: assert_eq!( | |
| 101 | 추가: terminal(&events).outcome, | |
| 102 | 추가: Outcome::Completed, | |
| 103 | 추가: "{approved}: {events:?}" | |
| 104 | 추가: ); | |
| 105 | 추가: assert_eq!(terminal(&events).created_count, 0); | |
| 106 | 추가: assert_eq!( | |
| 107 | 추가: fs::read_to_string(s.0.join("marker")) | |
| 108 | 추가: .unwrap() | |
| 109 | 추가: .lines() | |
| 110 | 추가: .count(), | |
| 111 | 추가: 8 | |
| 112 | 추가: ); | |
| 113 | 추가: } | |
| 114 | 추가: } | |
| 115 | 추가: | |
| 116 | 추가: #[test] | |
| 117 | 추가: fn every_processing_phase_records_completed_items_with_a_slow_clock() { | |
| 118 | 추가: for phase in [ | |
| 119 | 추가: "preflight", | |
| 120 | 추가: "mkdir", | |
| 121 | 추가: "space", | |
| 122 | 추가: "create", | |
| 123 | 추가: "sync", | |
| 124 | 추가: "list", | |
| 125 | 추가: "catalog", | |
| 126 | 추가: "source", | |
| 127 | 추가: "header", | |
| 128 | 추가: "rename", | |
| 129 | 추가: "overwrite", | |
| 130 | 추가: "write", | |
| 131 | 추가: "publish", | |
| 132 | 추가: "cleanup", | |
| 133 | 추가: "all", | |
| 134 | 추가: ] { | |
| 135 | 추가: let (s, start) = phase_setup(phase); | |
| 136 | 추가: let events = run_fault(&s, start, Some(&format!("phase-{phase}")), |event| { | |
| 137 | 추가: phase_reply(event, phase) | |
| 138 | 추가: }); | |
| 139 | 추가: assert_eq!( | |
| 140 | 추가: terminal(&events).outcome, | |
| 141 | 추가: Outcome::Completed, | |
| 142 | 추가: "{phase}: {events:?}" | |
| 143 | 추가: ); | |
| 144 | 추가: assert_eq!(terminal(&events).cleanup, Cleanup::Complete); | |
| 145 | 추가: let steps = fs::read_to_string(s.0.join("marker")) | |
| 146 | 추가: .unwrap_or_else(|error| panic!("{phase}: {error}: {events:?}")); | |
| 147 | 추가: assert!(steps.lines().count() >= 8, "{phase}: {steps}"); | |
| 148 | 추가: if phase == "rename" { | |
| 149 | 추가: assert_eq!(fs::read(s.0.join("output/file (9).txt")).unwrap(), b"x"); | |
| 150 | 추가: assert_eq!(fs::read(s.0.join("output/file.txt")).unwrap(), b"old"); | |
| 151 | 추가: } else if phase == "overwrite" || phase == "all" { | |
| 152 | 추가: for id in 0..8 { | |
| 153 | 추가: assert_eq!( | |
| 154 | 추가: fs::read(s.0.join(format!("output/entry-{id}"))).unwrap(), | |
| 155 | 추가: b"x" | |
| 156 | 추가: ); | |
| 157 | 추가: } | |
| 158 | 추가: } | |
| 159 | 추가: } | |
| 160 | 추가: } | |
| 161 | 추가: | |
| 162 | 추가: #[test] | |
| 163 | 추가: fn a_single_stalled_phase_keeps_publication_accounting_and_cleanup() { | |
| 164 | 추가: for (phase, created) in [ | |
| 165 | 추가: ("preflight", 0), | |
| 166 | 추가: ("directory", 0), | |
| 167 | 추가: ("mkdir", 1), | |
| 168 | 추가: ("write", 0), | |
| 169 | 추가: ("publish", 1), | |
| 170 | 추가: ("cleanup", 1), | |
| 171 | 추가: ] { | |
| 172 | 추가: let (s, start) = phase_setup(phase); | |
| 173 | 추가: let events = run_fault(&s, start, Some(&format!("phase-{phase}-stall")), approve); | |
| 174 | 추가: assert_eq!( | |
| 175 | 추가: terminal(&events).error, | |
| 176 | 추가: ErrorCode::Limit, | |
| 177 | 추가: "{phase}: {events:?}" | |
| 178 | 추가: ); | |
| 179 | 추가: assert_eq!( | |
| 180 | 추가: terminal(&events).outcome, | |
| 181 | 추가: Outcome::Failed, | |
| 182 | 추가: "{phase}: {events:?}" | |
| 183 | 추가: ); | |
| 184 | 추가: assert_eq!( | |
| 185 | 추가: terminal(&events).created_count, | |
| 186 | 추가: created, | |
| 187 | 추가: "{phase}: {events:?}" | |
| 188 | 추가: ); | |
| 189 | 추가: assert_eq!( | |
| 190 | 추가: terminal(&events).cleanup, | |
| 191 | 추가: Cleanup::Complete, | |
| 192 | 추가: "{phase}: {events:?}" | |
| 193 | 추가: ); | |
| 194 | 추가: assert_eq!(terminal(&events).retained_partial_count, 0); | |
| 195 | 추가: assert_eq!( | |
| 196 | 추가: terminal(&events).publication, | |
| 197 | 추가: if created == 0 { | |
| 198 | 추가: Publication::None | |
| 199 | 추가: } else { | |
| 200 | 추가: Publication::Partial | |
| 201 | 추가: } | |
| 202 | 추가: ); | |
| 203 | 추가: assert!(fs::read_dir(s.0.join("output")).unwrap().all(|e| { | |
| 204 | 추가: !e.unwrap() | |
| 205 | 추가: .file_name() | |
| 206 | 추가: .to_string_lossy() | |
| 207 | 추가: .starts_with(".zipelo-") | |
| 208 | 추가: })); | |
| 209 | 추가: } | |
| 210 | 추가: } |
| @@ -0,0 +1,181 @@ | ||
| 1 | 추가: #define _GNU_SOURCE | |
| 2 | 추가: #include <dlfcn.h> | |
| 3 | 추가: #include <errno.h> | |
| 4 | 추가: #include <fcntl.h> | |
| 5 | 추가: #include <stdarg.h> | |
| 6 | 추가: #include <stdatomic.h> | |
| 7 | 추가: #include <stdio.h> | |
| 8 | 추가: #include <stdlib.h> | |
| 9 | 추가: #include <string.h> | |
| 10 | 추가: #include <sys/stat.h> | |
| 11 | 추가: #include <sys/statvfs.h> | |
| 12 | 추가: #include <time.h> | |
| 13 | 추가: #include <unistd.h> | |
| 14 | 추가: | |
| 15 | 추가: static atomic_long elapsed; | |
| 16 | 추가: static atomic_int directories; | |
| 17 | 추가: static atomic_int existing_files; | |
| 18 | 추가: static int (*real_openat)(int, const char *, int, ...); | |
| 19 | 추가: static ssize_t (*real_read)(int, void *, size_t); | |
| 20 | 추가: static ssize_t (*real_write)(int, const void *, size_t); | |
| 21 | 추가: static int (*real_mkdirat)(int, const char *, mode_t); | |
| 22 | 추가: static int (*real_linkat)(int, const char *, int, const char *, int); | |
| 23 | 추가: static int (*real_renameat)(int, const char *, int, const char *); | |
| 24 | 추가: static int (*real_unlinkat)(int, const char *, int); | |
| 25 | 추가: static int (*real_fsync)(int); | |
| 26 | 추가: static int (*real_fstatvfs)(int, struct statvfs *); | |
| 27 | 추가: | |
| 28 | 추가: __attribute__((constructor)) static void initialize(void) { | |
| 29 | 추가: real_openat = dlsym(RTLD_NEXT, "openat"); | |
| 30 | 추가: real_read = dlsym(RTLD_NEXT, "read"); | |
| 31 | 추가: real_write = dlsym(RTLD_NEXT, "write"); | |
| 32 | 추가: real_mkdirat = dlsym(RTLD_NEXT, "mkdirat"); | |
| 33 | 추가: real_linkat = dlsym(RTLD_NEXT, "linkat"); | |
| 34 | 추가: real_renameat = dlsym(RTLD_NEXT, "renameat"); | |
| 35 | 추가: real_unlinkat = dlsym(RTLD_NEXT, "unlinkat"); | |
| 36 | 추가: real_fsync = dlsym(RTLD_NEXT, "fsync"); | |
| 37 | 추가: real_fstatvfs = dlsym(RTLD_NEXT, "fstatvfs"); | |
| 38 | 추가: } | |
| 39 | 추가: | |
| 40 | 추가: static void tick(const char *stage) { | |
| 41 | 추가: const char *mode = getenv("ZIPELO_TEST_FAULT"); | |
| 42 | 추가: char expected[80]; | |
| 43 | 추가: snprintf(expected, sizeof(expected), "phase-%s", stage); | |
| 44 | 추가: size_t n = strlen(expected); | |
| 45 | 추가: if (!mode || (strcmp(mode, "phase-all") && strcmp(mode, "phase-all-stall") | |
| 46 | 추가: && (strncmp(mode, expected, n) || (mode[n] && strcmp(mode + n, "-stall"))))) return; | |
| 47 | 추가: int saved = errno; | |
| 48 | 추가: atomic_fetch_add(&elapsed, strstr(mode, "-stall") ? 60 : 10); | |
| 49 | 추가: const char *marker = getenv("ZIPELO_TEST_MARKER"); | |
| 50 | 추가: int fd = real_openat(AT_FDCWD, marker, O_CREAT | O_APPEND | O_WRONLY, 0600); | |
| 51 | 추가: if (fd >= 0) { | |
| 52 | 추가: real_write(fd, stage, strlen(stage)); | |
| 53 | 추가: real_write(fd, "\n", 1); | |
| 54 | 추가: close(fd); | |
| 55 | 추가: } | |
| 56 | 추가: errno = saved; | |
| 57 | 추가: } | |
| 58 | 추가: | |
| 59 | 추가: static int output_fd(int fd) { | |
| 60 | 추가: char link[64], path[4096]; | |
| 61 | 추가: snprintf(link, sizeof(link), "/proc/self/fd/%d", fd); | |
| 62 | 추가: int saved = errno; | |
| 63 | 추가: ssize_t n = readlink(link, path, sizeof(path) - 1); | |
| 64 | 추가: errno = saved; | |
| 65 | 추가: if (n < 0) return 0; | |
| 66 | 추가: path[n] = 0; | |
| 67 | 추가: return strstr(path, "/output") != NULL; | |
| 68 | 추가: } | |
| 69 | 추가: | |
| 70 | 추가: int clock_gettime(clockid_t id, struct timespec *value) { | |
| 71 | 추가: int (*original)(clockid_t, struct timespec *) = dlsym(RTLD_NEXT, "clock_gettime"); | |
| 72 | 추가: int result = original(id, value); | |
| 73 | 추가: if (!result && id == CLOCK_MONOTONIC) value->tv_sec += atomic_load(&elapsed); | |
| 74 | 추가: return result; | |
| 75 | 추가: } | |
| 76 | 추가: | |
| 77 | 추가: int openat(int fd, const char *path, int flags, ...) { | |
| 78 | 추가: mode_t mode = 0; | |
| 79 | 추가: if (flags & O_CREAT) { | |
| 80 | 추가: va_list args; | |
| 81 | 추가: va_start(args, flags); | |
| 82 | 추가: mode = va_arg(args, unsigned int); | |
| 83 | 추가: va_end(args); | |
| 84 | 추가: } | |
| 85 | 추가: int result = real_openat(fd, path, flags, mode); | |
| 86 | 추가: if (!strncmp(path, "entry-", 6) && (flags & O_DIRECTORY) && result >= 0) { | |
| 87 | 추가: int n = atomic_fetch_add(&directories, 1); | |
| 88 | 추가: tick(n < 8 ? "preflight" : "directory"); | |
| 89 | 추가: } | |
| 90 | 추가: if (strstr(path, " (") && (flags & O_PATH)) tick("rename"); | |
| 91 | 추가: if (!strncmp(path, "entry-", 6) && (flags & O_PATH)) { | |
| 92 | 추가: if (output_fd(fd)) { | |
| 93 | 추가: if (result >= 0 && atomic_fetch_add(&existing_files, 1) >= 8) tick("overwrite"); | |
| 94 | 추가: tick("lookup"); | |
| 95 | 추가: } else if (result >= 0) { | |
| 96 | 추가: tick("source"); | |
| 97 | 추가: } | |
| 98 | 추가: } | |
| 99 | 추가: if (result >= 0 && (flags & O_CREAT) && !strncmp(path, ".zipelo-", 8)) tick("create"); | |
| 100 | 추가: return result; | |
| 101 | 추가: } | |
| 102 | 추가: | |
| 103 | 추가: int mkdirat(int fd, const char *path, mode_t mode) { | |
| 104 | 추가: int result = real_mkdirat(fd, path, mode); | |
| 105 | 추가: if (!result && !strncmp(path, "entry-", 6)) tick("mkdir"); | |
| 106 | 추가: return result; | |
| 107 | 추가: } | |
| 108 | 추가: | |
| 109 | 추가: ssize_t read(int fd, void *buffer, size_t count) { | |
| 110 | 추가: ssize_t result = real_read(fd, buffer, count); | |
| 111 | 추가: if (result >= 30 && (count == 30 || count == 46) | |
| 112 | 추가: && (!memcmp(buffer, "PK\003\004", 4) || !memcmp(buffer, "PK\001\002", 4))) tick("catalog"); | |
| 113 | 추가: return result; | |
| 114 | 추가: } | |
| 115 | 추가: | |
| 116 | 추가: static void written_frame(const unsigned char *bytes, size_t count) { | |
| 117 | 추가: static unsigned char header[32]; | |
| 118 | 추가: static size_t used, remaining; | |
| 119 | 추가: static unsigned int kind; | |
| 120 | 추가: while (count) { | |
| 121 | 추가: if (used < sizeof(header)) { | |
| 122 | 추가: size_t n = sizeof(header) - used; | |
| 123 | 추가: if (n > count) n = count; | |
| 124 | 추가: memcpy(header + used, bytes, n); | |
| 125 | 추가: used += n; | |
| 126 | 추가: bytes += n; | |
| 127 | 추가: count -= n; | |
| 128 | 추가: if (used != sizeof(header)) continue; | |
| 129 | 추가: if (memcmp(header, "ZAW1", 4)) abort(); | |
| 130 | 추가: kind = header[6] | (header[7] << 8); | |
| 131 | 추가: remaining = header[8] | (header[9] << 8) | (header[10] << 16) | ((size_t)header[11] << 24); | |
| 132 | 추가: } | |
| 133 | 추가: size_t n = remaining < count ? remaining : count; | |
| 134 | 추가: remaining -= n; | |
| 135 | 추가: bytes += n; | |
| 136 | 추가: count -= n; | |
| 137 | 추가: if (!remaining) { | |
| 138 | 추가: if (kind == 101) tick("list"); | |
| 139 | 추가: used = 0; | |
| 140 | 추가: } | |
| 141 | 추가: } | |
| 142 | 추가: } | |
| 143 | 추가: | |
| 144 | 추가: ssize_t write(int fd, const void *buffer, size_t count) { | |
| 145 | 추가: ssize_t result = real_write(fd, buffer, count); | |
| 146 | 추가: if (result >= 30 && count >= 30 && !memcmp(buffer, "PK\003\004", 4)) tick("header"); | |
| 147 | 추가: if (fd == STDOUT_FILENO && result > 0) written_frame(buffer, result); | |
| 148 | 추가: if (result > 0 && output_fd(fd)) tick("write"); | |
| 149 | 추가: return result; | |
| 150 | 추가: } | |
| 151 | 추가: | |
| 152 | 추가: int linkat(int fd, const char *from, int newfd, const char *to, int flags) { | |
| 153 | 추가: int result = real_linkat(fd, from, newfd, to, flags); | |
| 154 | 추가: if (!result) tick("publish"); | |
| 155 | 추가: return result; | |
| 156 | 추가: } | |
| 157 | 추가: | |
| 158 | 추가: int renameat(int fd, const char *from, int newfd, const char *to) { | |
| 159 | 추가: int result = real_renameat(fd, from, newfd, to); | |
| 160 | 추가: if (!result) tick("publish"); | |
| 161 | 추가: return result; | |
| 162 | 추가: } | |
| 163 | 추가: | |
| 164 | 추가: int unlinkat(int fd, const char *path, int flags) { | |
| 165 | 추가: int result = real_unlinkat(fd, path, flags); | |
| 166 | 추가: if (!result && !strncmp(path, ".zipelo-", 8)) tick("cleanup"); | |
| 167 | 추가: return result; | |
| 168 | 추가: } | |
| 169 | 추가: | |
| 170 | 추가: int fsync(int fd) { | |
| 171 | 추가: int result = real_fsync(fd); | |
| 172 | 추가: if (!result && output_fd(fd)) tick("sync"); | |
| 173 | 추가: return result; | |
| 174 | 추가: } | |
| 175 | 추가: | |
| 176 | 추가: int fstatvfs(int fd, struct statvfs *value) { | |
| 177 | 추가: int result = real_fstatvfs(fd, value); | |
| 178 | 추가: struct stat metadata; | |
| 179 | 추가: if (!result && !fstat(fd, &metadata) && S_ISDIR(metadata.st_mode) && output_fd(fd)) tick("space"); | |
| 180 | 추가: return result; | |
| 181 | 추가: } |
| @@ -178,3 +178,94 @@ fn granted_entry_policy_keeps_independent_metadata_budget() { | ||
| 178 | 178 | } |
| 179 | 179 | assert_eq!(metadata.charge(""), Err(ErrorCode::Limit)); |
| 180 | 180 | } |
| 181 | 추가: | |
| 182 | 추가: #[test] | |
| 183 | 추가: fn successful_item_completion_refreshes_only_live_work() { | |
| 184 | 추가: struct Clock { | |
| 185 | 추가: now: Duration, | |
| 186 | 추가: watchdog: Watchdog, | |
| 187 | 추가: } | |
| 188 | 추가: impl Monitor for Clock { | |
| 189 | 추가: fn check(&mut self) -> Result<()> { | |
| 190 | 추가: self.watchdog.check(self.now) | |
| 191 | 추가: } | |
| 192 | 추가: fn activity(&mut self) -> Result<()> { | |
| 193 | 추가: self.watchdog.activity(self.now) | |
| 194 | 추가: } | |
| 195 | 추가: } | |
| 196 | 추가: let mut clock = Clock { | |
| 197 | 추가: now: Duration::ZERO, | |
| 198 | 추가: watchdog: Watchdog::new(), | |
| 199 | 추가: }; | |
| 200 | 추가: clock.watchdog.resume(Duration::ZERO, true); | |
| 201 | 추가: for item in 1..=100 { | |
| 202 | 추가: clock.now += Duration::from_secs(10); | |
| 203 | 추가: assert_eq!(completed(Ok(item), &mut clock), Ok(item)); | |
| 204 | 추가: } | |
| 205 | 추가: clock.now += Duration::from_secs(30); | |
| 206 | 추가: assert_eq!( | |
| 207 | 추가: completed::<()>(Err(ErrorCode::Io), &mut clock), | |
| 208 | 추가: Err(ErrorCode::Io) | |
| 209 | 추가: ); | |
| 210 | 추가: for _ in 0..29 { | |
| 211 | 추가: clock.now += Duration::from_secs(1); | |
| 212 | 추가: clock.check().unwrap(); | |
| 213 | 추가: } | |
| 214 | 추가: clock.now += Duration::from_secs(1); | |
| 215 | 추가: assert_eq!(clock.check(), Err(ErrorCode::Limit)); | |
| 216 | 추가: assert_eq!(completed(Ok(()), &mut clock), Err(ErrorCode::Limit)); | |
| 217 | 추가: assert_eq!( | |
| 218 | 추가: completed::<()>(Err(ErrorCode::Io), &mut clock), | |
| 219 | 추가: Err(ErrorCode::Io) | |
| 220 | 추가: ); | |
| 221 | 추가: } | |
| 222 | 추가: | |
| 223 | 추가: #[test] | |
| 224 | 추가: fn empty_gzip_members_count_consumed_input_as_decode_progress() { | |
| 225 | 추가: use std::io::Write; | |
| 226 | 추가: struct DecodeClock { | |
| 227 | 추가: now: Duration, | |
| 228 | 추가: steps: usize, | |
| 229 | 추가: watchdog: Watchdog, | |
| 230 | 추가: } | |
| 231 | 추가: impl Monitor for DecodeClock { | |
| 232 | 추가: fn check(&mut self) -> Result<()> { | |
| 233 | 추가: self.watchdog.check(self.now) | |
| 234 | 추가: } | |
| 235 | 추가: fn activity(&mut self) -> Result<()> { | |
| 236 | 추가: self.watchdog.activity(self.now) | |
| 237 | 추가: } | |
| 238 | 추가: fn observe(&mut self, _: ResourceUsage, _: Option<&std::fs::File>) -> Result<()> { | |
| 239 | 추가: self.steps += 1; | |
| 240 | 추가: self.now += Duration::from_secs(10); | |
| 241 | 추가: self.check() | |
| 242 | 추가: } | |
| 243 | 추가: } | |
| 244 | 추가: let mut clock = DecodeClock { | |
| 245 | 추가: now: Duration::ZERO, | |
| 246 | 추가: steps: 0, | |
| 247 | 추가: watchdog: Watchdog::new(), | |
| 248 | 추가: }; | |
| 249 | 추가: clock.watchdog.resume(Duration::ZERO, true); | |
| 250 | 추가: let member = [ | |
| 251 | 추가: 31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 252 | 추가: ]; | |
| 253 | 추가: let mut input = crate::spool::temporary().unwrap(); | |
| 254 | 추가: for _ in 0..8 { | |
| 255 | 추가: input.write_all(&member).unwrap(); | |
| 256 | 추가: } | |
| 257 | 추가: let catalog = crate::streaming::Catalog::open( | |
| 258 | 추가: &mut input, | |
| 259 | 추가: 8 * member.len() as u64, | |
| 260 | 추가: Limits::default(), | |
| 261 | 추가: true, | |
| 262 | 추가: None, | |
| 263 | 추가: &mut clock, | |
| 264 | 추가: ) | |
| 265 | 추가: .unwrap(); | |
| 266 | 추가: assert_eq!(catalog.format, Format::Gzip); | |
| 267 | 추가: assert_eq!(catalog.members.len(), 1); | |
| 268 | 추가: assert_eq!(catalog.members[0].entry.size, 0); | |
| 269 | 추가: assert!(clock.steps >= 8); | |
| 270 | 추가: clock.check().unwrap(); | |
| 271 | 추가: } |