원본 폴더 내부 저장 오탐을 수정함
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
eec85f32b6adf89c0561260d908b8edfd0ec95e3- 부모
- 71aa755
변경된 파일 6개
+381-18| @@ -67,12 +67,12 @@ | ||
| 67 | 67 | 1. 목적지 부모를 기존 Dir로 고정하고 경로/기존 목적지를 사전 검사한다. 원본과 같은 이름, 기존 파일/링크에는 쓰지 않는다. |
| 68 | 68 | 2. 원본 계획과 소스 스냅샷을 만들고 비공개 spool 임시 파일에 완성된 7z를 작성한다. finish, 구조 검사와 Plan::verify가 실패하면 게시하지 않는다. |
| 69 | 69 | 3. 완성 길이에 맞춰 목적지 공간을 확인하고 기존 publish_reader_steps의 새 파일 경로(replace=None)에 전달한다. 파일 sync와 close 오류를 확인한 뒤 배타적으로 게시한다. 사전검사 뒤 나타난 목적지도 Conflict로 거부한다. |
| 70 | 삭제: 4. 게시 직전에도 계획과 취소를 확인하며 확인과 게시 사이의 원자적 트랜잭션을 약속하지 않는다. 게시 후 부모 sync와 정리 결과를 실제 내구성/부분 출력으로 보고한다. 불명확한 결과를 덮어 재시도하지 않는다. | |
| 70 | 추가: 4. 게시 직전에도 계획과 취소를 확인한다. 원본 폴더 안에 저장할 때는 게시 임시 파일 부모의 객체 ID를 계획과 대조하고, 그 폴더만 수정 시각 대신 원래 자식 목록을 다시 확인한다. 원래 목록은 탐색 때 이미 예산에 반영한 이름을 보존한다. 게시자가 열린 파일에서 기록한 정확한 임시 이름과 객체 ID 하나만 제외하며, 같은 접두 이름의 사용자 파일, 원본 추가/누락/이름 변경과 기존 항목의 객체/종류/크기/수정 시각 변경은 거부한다. 열거 전후 폴더 시각이 바뀌어도 거부한다. 확인과 게시 사이의 원자적 트랜잭션이나 잠깐 추가됐다 사라진 항목까지 감지한다고 약속하지 않는다. 게시 후 부모 sync와 정리 결과를 실제 내구성/부분 출력으로 보고한다. 불명확한 결과를 덮어 재시도하지 않는다. | |
| 71 | 71 | 5. 비공개 입력/생성물은 핸들을 닫아 제거하고 목적지 임시 파일만 기존 소유 확인 정책으로 정리한다. 무관한 파일이나 이미 게시한 파일을 삭제하지 않는다. 강제 종료/전원 손실 뒤 자동 정리까지 보장하지 않는다. |
| 72 | 72 | |
| 73 | 73 | ## 7. 구현 후 수용 시험 |
| 74 | 74 | |
| 75 | 삭제: 아래는 수용 시험 기준이다. Linux에서 새 정수/비트맵과 인코딩 경계, 독립 7-Zip 26.00/Zipelo의 한글/보조 평면 이름 및 빈 구조 왕복, 취소/쓰기/finish/헤더 seek와 패치/게시 실패를 검증했다. 1 GiB 대표 생성은 11,168 KiB RSS와 약 20.8초를 기록했다. 이는 단일 표본 측정이며 모든 입력의 성능이나 OS 강제 상한이 아니다. 전체 local, 라이선스 시험과 플랫폼별 수행 결과는 PR 본문과 tests/work/7zc의 로그를 따른다. Windows/Wayland 실제 생성 통합과 구현 독립 리뷰는 아직 남았다. 시험 코드는 루트 tests/에만 두며 일회성 자료, 도구, 캐시와 로그는 tests/work/7zc 한 곳에 모은다. TMPDIR과 CARGO_TARGET_DIR을 그 하위에 명시하고 사본 안에 작업 폴더나 빌드 캐시를 다시 만들지 않는다. PR 병합/종료 뒤 담당자가 정리한다. | |
| 75 | 추가: 아래는 수용 시험 기준이다. Linux에서 새 정수/비트맵과 인코딩 경계, 독립 7-Zip 26.00/Zipelo의 한글/보조 평면 이름 및 빈 구조 왕복, 취소/쓰기/finish/헤더 seek와 패치/게시 실패를 검증했다. 1 GiB 대표 생성은 11,168 KiB RSS와 약 20.8초를 기록했다. 이는 단일 표본 측정이며 모든 입력의 성능이나 OS 강제 상한이 아니다. 전체 local, 라이선스 시험과 플랫폼별 수행 결과는 PR 본문과 tests/work/7zc의 로그를 따른다. 71aa755의 Windows/Wayland 실제 생성 통합은 PR 본문에 기록되어 있다. 내부 저장 오탐 수정 뒤의 GUI 실기는 재실행하지 않았으며 독립 재리뷰는 남았다. 시험 코드는 루트 tests/에만 두며 일회성 자료, 도구, 캐시와 로그는 tests/work/7zc 한 곳에 모은다. TMPDIR과 CARGO_TARGET_DIR을 그 하위에 명시하고 사본 안에 작업 폴더나 빌드 캐시를 다시 만들지 않는다. PR 병합/종료 뒤 담당자가 정리한다. | |
| 76 | 76 | |
| 77 | 77 | - 일반 파일, 압축되는/난수 내용, 한글 및 여러 단계 경로, 혼합 파일/폴더, 빈 파일, 빈 폴더, 빈 폴더만 있는 묶음과 여러 최상위 원본을 만든다. Zipelo 목록/해제와 독립 7-Zip의 테스트/목록/해제를 각각 실행해 상대 경로, 항목 종류, 파일 크기와 SHA256을 원본 manifest와 대조한다. 압축 아카이브 바이트 자체의 일치는 요구하지 않는다. |
| 78 | 78 | - 독립 설계 리뷰의 후속 기준으로 MainStreamsInfo/kEnd 계층, 32바이트 기준 NextHeaderOffset, 가변 UINT64와 고정 REAL_UINT64 구분을 확인한다. EmptyFile 비트 수는 전체 파일 수가 아닌 empty stream 수이며 혼합 빈 항목 7/8/9개와 정수 경계 127/128, 16383/16384를 포함한다. |
| @@ -87,4 +87,4 @@ | ||
| 87 | 87 | - 하나는 이 계약과 backend 작성기, 공용 타입/codec 및 작업자 회귀를 담당한다. 히나타의 계약 동의와 카논의 설계 리뷰가 확인되어 공용 타입 인계 단계에 착수했다. 실제 작성기를 반영했으며 새 파일로 Windows/Wayland 통합 검증을 인계한다. |
| 88 | 88 | - 계약 동의 뒤 공용 타입 반영 커밋을 히나타에게 전달한다. 히나타는 기존 생성 화면의 ZIP/7z 형식 선택, .7z 기본 저장 형식, 암호/방식 선택 제한, 새 ActionKind 변환과 수신 검증을 담당한다. 화면이 바뀌는 구현 PR에 --ui-scenario 목록/시험과 docs/ui-scenario-guide.md를 함께 갱신한다. 별도 디자인 변경이나 애니메이션을 추가하지 않는다. |
| 89 | 89 | - 카논의 설계와 실패 경계 리뷰는 완료되었으며 구현 후 독립 7-Zip 호환 검증 및 재리뷰는 별도 요청한다. 도구 버전/옵션, 원본과 해제 manifest 및 플랫폼별 실행 범위를 남긴다. 도구를 제품에 번들하지 않는다. |
| 90 | 삭제: - 설계 문서의 정적 검토와 링크/공백 검사는 제품 빌드나 호환 검증이 아니다. 이번 backend 추가분은 UI 변경 없음이다. 같은 PR의 형식 선택과 시나리오는 이미 반영되어 있으며 실제 파일의 Windows/Wayland 통합 및 구현 독립 리뷰가 끝날 때까지 초안을 유지한다. | |
| 90 | 추가: - 설계 문서의 정적 검토와 링크/공백 검사는 제품 빌드나 호환 검증이 아니다. 이번 backend 추가분은 UI 변경 없음이다. 같은 PR의 형식 선택과 시나리오는 이미 반영되었고 71aa755에서 Windows/Wayland 실제 파일 통합을 확인했다. 내부 저장 오탐 수정 뒤 독립 재리뷰가 끝날 때까지 초안을 유지한다. |
| @@ -180,6 +180,7 @@ pub(super) struct Planned { | ||
| 180 | 180 | path: PathBuf, |
| 181 | 181 | object: SourceObject, |
| 182 | 182 | modified: Option<SystemTime>, |
| 183 | 추가: children: Vec<String>, | |
| 183 | 184 | } |
| 184 | 185 | impl Planned { |
| 185 | 186 | pub fn open(&self) -> Result<Input> { |
| @@ -196,6 +197,56 @@ impl Planned { | ||
| 196 | 197 | && metadata.is_dir() == (self.member.entry.kind == EntryKind::Directory) |
| 197 | 198 | && (metadata.is_dir() || metadata.len() == self.member.entry.size)) |
| 198 | 199 | } |
| 200 | 추가: fn verify_with_temporary( | |
| 201 | 추가: &self, | |
| 202 | 추가: temporary: &filesystem::PublicationTemp, | |
| 203 | 추가: check: &mut impl crate::resources::Monitor, | |
| 204 | 추가: ) -> Result<()> { | |
| 205 | 추가: let input = Input::open(&self.path).map_err(|_| ErrorCode::SourceChanged)?; | |
| 206 | 추가: let before = input.file.metadata().map_err(crate::space::io_error)?; | |
| 207 | 추가: if !before.is_dir() || filesystem::object(&input.file)? != self.object { | |
| 208 | 추가: return Err(ErrorCode::SourceChanged); | |
| 209 | 추가: } | |
| 210 | 추가: // 게시 임시 파일의 부모만 시각 대신 원래 항목과 소유 객체를 대조함. | |
| 211 | 추가: let mut count = 0; | |
| 212 | 추가: let mut found = false; | |
| 213 | 추가: for entry in input.children(&self.path)? { | |
| 214 | 추가: check.check()?; | |
| 215 | 추가: let name = entry.map_err(crate::space::io_error)?.file_name(); | |
| 216 | 추가: let name = name.to_str().ok_or(ErrorCode::SourceChanged)?; | |
| 217 | 추가: if name == temporary.name { | |
| 218 | 추가: let child = input | |
| 219 | 추가: .open_child(&self.path, name) | |
| 220 | 추가: .map_err(|_| ErrorCode::SourceChanged)?; | |
| 221 | 추가: if found | |
| 222 | 추가: || !child | |
| 223 | 추가: .file | |
| 224 | 추가: .metadata() | |
| 225 | 추가: .map_err(crate::space::io_error)? | |
| 226 | 추가: .is_file() | |
| 227 | 추가: || filesystem::object(&child.file)? != temporary.object | |
| 228 | 추가: { | |
| 229 | 추가: return Err(ErrorCode::SourceChanged); | |
| 230 | 추가: } | |
| 231 | 추가: found = true; | |
| 232 | 추가: } else if self | |
| 233 | 추가: .children | |
| 234 | 추가: .binary_search_by(|leaf| leaf.as_str().cmp(name)) | |
| 235 | 추가: .is_ok() | |
| 236 | 추가: { | |
| 237 | 추가: count += 1; | |
| 238 | 추가: } else { | |
| 239 | 추가: return Err(ErrorCode::SourceChanged); | |
| 240 | 추가: } | |
| 241 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 242 | 추가: } | |
| 243 | 추가: let after = input.file.metadata().map_err(crate::space::io_error)?; | |
| 244 | 추가: if !found || count != self.children.len() || before.modified().ok() != after.modified().ok() | |
| 245 | 추가: { | |
| 246 | 추가: return Err(ErrorCode::SourceChanged); | |
| 247 | 추가: } | |
| 248 | 추가: Ok(()) | |
| 249 | 추가: } | |
| 199 | 250 | } |
| 200 | 251 | pub(super) struct Plan { |
| 201 | 252 | pub items: Vec<Planned>, |
| @@ -283,6 +334,7 @@ impl Plan { | ||
| 283 | 334 | None, |
| 284 | 335 | )?; |
| 285 | 336 | crate::resources::completed(Ok(()), check)?; |
| 337 | 추가: let index = self.items.len(); | |
| 286 | 338 | self.items.push(Planned { |
| 287 | 339 | member: Member { |
| 288 | 340 | entry: Entry { |
| @@ -302,6 +354,7 @@ impl Plan { | ||
| 302 | 354 | path: path.clone(), |
| 303 | 355 | object: crate::resources::completed(filesystem::object(&input.file), check)?, |
| 304 | 356 | modified: metadata.modified().ok(), |
| 357 | 추가: children: Vec::new(), | |
| 305 | 358 | }); |
| 306 | 359 | if directory { |
| 307 | 360 | let mut children = Vec::new(); |
| @@ -328,10 +381,11 @@ impl Plan { | ||
| 328 | 381 | crate::resources::completed(Ok(()), check)?; |
| 329 | 382 | } |
| 330 | 383 | children.sort(); |
| 331 | 삭제: for leaf in children { | |
| 332 | 삭제: let child = crate::resources::completed(input.open_child(&path, &leaf), check)?; | |
| 333 | 삭제: self.visit(path.join(&leaf), format!("{name}/{leaf}"), child, check)?; | |
| 384 | 추가: for leaf in &children { | |
| 385 | 추가: let child = crate::resources::completed(input.open_child(&path, leaf), check)?; | |
| 386 | 추가: self.visit(path.join(leaf), format!("{name}/{leaf}"), child, check)?; | |
| 334 | 387 | } |
| 388 | 추가: self.items[index].children = children; | |
| 335 | 389 | } |
| 336 | 390 | Ok(()) |
| 337 | 391 | } |
| @@ -350,6 +404,22 @@ impl Plan { | ||
| 350 | 404 | } |
| 351 | 405 | Ok(()) |
| 352 | 406 | } |
| 407 | 추가: pub fn verify_for_publication( | |
| 408 | 추가: &self, | |
| 409 | 추가: temporary: &filesystem::PublicationTemp, | |
| 410 | 추가: check: &mut impl crate::resources::Monitor, | |
| 411 | 추가: ) -> Result<()> { | |
| 412 | 추가: for item in &self.items { | |
| 413 | 추가: check.check()?; | |
| 414 | 추가: if item.member.entry.kind == EntryKind::Directory && item.object == temporary.parent { | |
| 415 | 추가: item.verify_with_temporary(temporary, check)?; | |
| 416 | 추가: } else { | |
| 417 | 추가: item.open()?; | |
| 418 | 추가: } | |
| 419 | 추가: crate::resources::completed(Ok(()), check)?; | |
| 420 | 추가: } | |
| 421 | 추가: Ok(()) | |
| 422 | 추가: } | |
| 353 | 423 | } |
| 354 | 424 | |
| 355 | 425 | #[cfg(test)] |
| @@ -615,7 +615,7 @@ pub(crate) fn directory_with( | ||
| 615 | 615 | check: &mut impl Monitor, |
| 616 | 616 | ) -> Result<(bool, Durability, Option<ErrorCode>)> { |
| 617 | 617 | directory_steps(root, name, &mut |step| match step { |
| 618 | 삭제: PublishStep::Check | PublishStep::Commit => check.check(), | |
| 618 | 추가: PublishStep::Check | PublishStep::Commit(_) => check.check(), | |
| 619 | 619 | PublishStep::Activity => check.activity(), |
| 620 | 620 | }) |
| 621 | 621 | } |
| @@ -629,7 +629,7 @@ pub(crate) fn directory_steps( | ||
| 629 | 629 | if completed(d.child(&leaf, false), &mut PublicationMonitor(check))?.is_some() { |
| 630 | 630 | return Ok((false, Durability::NotApplicable, None)); |
| 631 | 631 | } |
| 632 | 삭제: check(PublishStep::Commit)?; | |
| 632 | 추가: check(PublishStep::Commit(None))?; | |
| 633 | 633 | d.child(&leaf, true)?.ok_or(ErrorCode::Io)?; |
| 634 | 634 | let progress_error = completed(Ok(()), &mut PublicationMonitor(check)).err(); |
| 635 | 635 | Ok(match d.sync_checked() { |
| @@ -684,14 +684,19 @@ pub fn publish_reader_mode( | ||
| 684 | 684 | ) -> Published { |
| 685 | 685 | publish_reader_steps(root, name, data, length, replace, &mut |step| match step { |
| 686 | 686 | PublishStep::Check => check(false), |
| 687 | 삭제: PublishStep::Commit => check(true), | |
| 687 | 추가: PublishStep::Commit(_) => check(true), | |
| 688 | 688 | PublishStep::Activity => Ok(()), |
| 689 | 689 | }) |
| 690 | 690 | } |
| 691 | 추가: pub(crate) struct PublicationTemp { | |
| 692 | 추가: pub parent: SourceObject, | |
| 693 | 추가: pub name: String, | |
| 694 | 추가: pub object: SourceObject, | |
| 695 | 추가: } | |
| 691 | 696 | pub(crate) enum PublishStep { |
| 692 | 697 | Check, |
| 693 | 698 | Activity, |
| 694 | 삭제: Commit, | |
| 699 | 추가: Commit(Option<PublicationTemp>), | |
| 695 | 700 | } |
| 696 | 701 | struct PublicationMonitor<'a, F>(&'a mut F); |
| 697 | 702 | impl<F: FnMut(PublishStep) -> Result<()>> Monitor for PublicationMonitor<'_, F> { |
| @@ -744,7 +749,13 @@ pub(crate) fn publish_reader_steps( | ||
| 744 | 749 | crate::space::io_error(e) |
| 745 | 750 | } |
| 746 | 751 | })?; |
| 752 | 추가: let mut temporary = None; | |
| 747 | 753 | let written = (|| { |
| 754 | 추가: temporary = Some(PublicationTemp { | |
| 755 | 추가: parent: object(dir.handle())?, | |
| 756 | 추가: name: temp.clone(), | |
| 757 | 추가: object: object(&file)?, | |
| 758 | 추가: }); | |
| 748 | 759 | completed(Ok(()), &mut PublicationMonitor(check))?; |
| 749 | 760 | completed( |
| 750 | 761 | crate::space::ensure(&file, length), |
| @@ -780,7 +791,7 @@ pub(crate) fn publish_reader_steps( | ||
| 780 | 791 | &mut PublicationMonitor(check), |
| 781 | 792 | ); |
| 782 | 793 | let mut finish = written.and(closed).and_then(|_| { |
| 783 | 삭제: check(PublishStep::Commit)?; | |
| 794 | 추가: check(PublishStep::Commit(temporary))?; | |
| 784 | 795 | // 긴 원본 재검증 중 바뀐 대상은 교체 직전에 거부함. |
| 785 | 796 | if let Some(expected) = replace { |
| 786 | 797 | if completed(dir.existing(&leaf), &mut PublicationMonitor(check))?.as_ref() |
| @@ -284,10 +284,16 @@ impl<W: Write> Job<W> { | ||
| 284 | 284 | self.source_group = Some(group); |
| 285 | 285 | self.split_result(result) |
| 286 | 286 | } |
| 287 | 삭제: fn verify_before_publication(&mut self) -> Result<()> { | |
| 287 | 추가: fn verify_before_publication( | |
| 288 | 추가: &mut self, | |
| 289 | 추가: temporary: Option<&filesystem::PublicationTemp>, | |
| 290 | 추가: ) -> Result<()> { | |
| 288 | 291 | if !self.source_verified_for_publication { |
| 289 | 292 | if let Some(plan) = self.creation_plan.take() { |
| 290 | 삭제: let result = plan.verify(self); | |
| 293 | 추가: let result = match temporary { | |
| 294 | 추가: Some(temporary) => plan.verify_for_publication(temporary, self), | |
| 295 | 추가: None => plan.verify(self), | |
| 296 | 추가: }; | |
| 291 | 297 | self.creation_plan = Some(plan); |
| 292 | 298 | result?; |
| 293 | 299 | } |
| @@ -300,8 +306,8 @@ impl<W: Write> Job<W> { | ||
| 300 | 306 | match step { |
| 301 | 307 | filesystem::PublishStep::Check => self.check(), |
| 302 | 308 | filesystem::PublishStep::Activity => completed(Ok(()), self), |
| 303 | 삭제: filesystem::PublishStep::Commit => { | |
| 304 | 삭제: self.verify_before_publication()?; | |
| 309 | 추가: filesystem::PublishStep::Commit(temporary) => { | |
| 310 | 추가: self.verify_before_publication(temporary.as_ref())?; | |
| 305 | 311 | if let Some(plan) = &self.creation_plan { |
| 306 | 312 | self.progress(Stage::Commit, 0, None, plan.items.len() as u32)?; |
| 307 | 313 | } |
| @@ -888,7 +894,7 @@ impl<W: Write> Job<W> { | ||
| 888 | 894 | )?; |
| 889 | 895 | } |
| 890 | 896 | // 건너뛰기 등 실제 게시가 없을 때도 완료 전에 원본을 확인함. |
| 891 | 삭제: self.verify_before_publication()?; | |
| 897 | 추가: self.verify_before_publication(None)?; | |
| 892 | 898 | if !self.interactive || self.terminal.created_count != 0 { |
| 893 | 899 | self.terminal.publication = Publication::Complete; |
| 894 | 900 | } |
| @@ -4,8 +4,9 @@ static NEXT: AtomicU64 = AtomicU64::new(0); | ||
| 4 | 4 | struct Scratch(PathBuf); |
| 5 | 5 | impl Scratch { |
| 6 | 6 | fn new() -> Self { |
| 7 | 삭제: let root = | |
| 8 | 삭제: Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/rust-archive-worker/runs"); | |
| 7 | 추가: let root = std::env::var_os("TMPDIR") | |
| 8 | 추가: .map(PathBuf::from) | |
| 9 | 추가: .unwrap_or_else(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/work/tmp")); | |
| 9 | 10 | fs::create_dir_all(&root).unwrap(); |
| 10 | 11 | let path = root.join(format!( |
| 11 | 12 | "sources-{}-{}", |
| @@ -105,3 +106,80 @@ fn pinned_directory_enumeration_does_not_follow_replacement_link() { | ||
| 105 | 106 | assert!(input.open_child(&path, "secret").is_err()); |
| 106 | 107 | assert!(matches!(Input::open(&path), Err(ErrorCode::UnsafePath))); |
| 107 | 108 | } |
| 109 | 추가: | |
| 110 | 추가: #[test] | |
| 111 | 추가: fn publication_exception_requires_the_exact_parent_name_and_temporary_object() { | |
| 112 | 추가: for mismatch in [ | |
| 113 | 추가: "parent", | |
| 114 | 추가: "name", | |
| 115 | 추가: "object", | |
| 116 | 추가: "missing", | |
| 117 | 추가: "replacement", | |
| 118 | 추가: "directory", | |
| 119 | 추가: ] { | |
| 120 | 추가: let s = Scratch::new(); | |
| 121 | 추가: fs::create_dir(s.0.join("folder")).unwrap(); | |
| 122 | 추가: fs::write(s.0.join("folder/source"), b"original").unwrap(); | |
| 123 | 추가: let plan = Plan::new(&[s.source("folder")], Limits::default(), &mut || Ok(())).unwrap(); | |
| 124 | 추가: let path = s.0.join("folder/.zipelo-owned.tmp"); | |
| 125 | 추가: fs::write(&path, b"archive").unwrap(); | |
| 126 | 추가: let mut temporary = filesystem::PublicationTemp { | |
| 127 | 추가: parent: filesystem::object(&Input::open(&s.0.join("folder")).unwrap().file).unwrap(), | |
| 128 | 추가: name: ".zipelo-owned.tmp".into(), | |
| 129 | 추가: object: filesystem::object(&Input::open(&path).unwrap().file).unwrap(), | |
| 130 | 추가: }; | |
| 131 | 추가: assert_eq!(plan.verify(&mut || Ok(())), Err(ErrorCode::SourceChanged)); | |
| 132 | 추가: assert_eq!( | |
| 133 | 추가: plan.verify_for_publication(&temporary, &mut || Ok(())), | |
| 134 | 추가: Ok(()) | |
| 135 | 추가: ); | |
| 136 | 추가: match mismatch { | |
| 137 | 추가: "parent" => temporary.parent = temporary.object.clone(), | |
| 138 | 추가: "name" => temporary.name = ".zipelo-other.tmp".into(), | |
| 139 | 추가: "object" => temporary.object = temporary.parent.clone(), | |
| 140 | 추가: "missing" => fs::remove_file(&path).unwrap(), | |
| 141 | 추가: "replacement" => { | |
| 142 | 추가: fs::rename(&path, s.0.join("owned")).unwrap(); | |
| 143 | 추가: fs::write(&path, b"foreign").unwrap(); | |
| 144 | 추가: } | |
| 145 | 추가: "directory" => { | |
| 146 | 추가: fs::rename(s.0.join("folder"), s.0.join("previous")).unwrap(); | |
| 147 | 추가: fs::create_dir(s.0.join("folder")).unwrap(); | |
| 148 | 추가: } | |
| 149 | 추가: _ => unreachable!(), | |
| 150 | 추가: } | |
| 151 | 추가: assert_eq!( | |
| 152 | 추가: plan.verify_for_publication(&temporary, &mut || Ok(())), | |
| 153 | 추가: Err(ErrorCode::SourceChanged), | |
| 154 | 추가: "{mismatch}" | |
| 155 | 추가: ); | |
| 156 | 추가: } | |
| 157 | 추가: } | |
| 158 | 추가: | |
| 159 | 추가: #[test] | |
| 160 | 추가: fn publication_directory_enumeration_remains_cancellable() { | |
| 161 | 추가: let s = Scratch::new(); | |
| 162 | 추가: fs::create_dir(s.0.join("folder")).unwrap(); | |
| 163 | 추가: for index in 0..20 { | |
| 164 | 추가: fs::write(s.0.join(format!("folder/{index}")), b"x").unwrap(); | |
| 165 | 추가: } | |
| 166 | 추가: let plan = Plan::new(&[s.source("folder")], Limits::default(), &mut || Ok(())).unwrap(); | |
| 167 | 추가: let path = s.0.join("folder/.zipelo-owned.tmp"); | |
| 168 | 추가: fs::write(&path, b"archive").unwrap(); | |
| 169 | 추가: let temporary = filesystem::PublicationTemp { | |
| 170 | 추가: parent: filesystem::object(&Input::open(&s.0.join("folder")).unwrap().file).unwrap(), | |
| 171 | 추가: name: ".zipelo-owned.tmp".into(), | |
| 172 | 추가: object: filesystem::object(&Input::open(&path).unwrap().file).unwrap(), | |
| 173 | 추가: }; | |
| 174 | 추가: let mut calls = 0; | |
| 175 | 추가: let result = plan.verify_for_publication(&temporary, &mut || { | |
| 176 | 추가: calls += 1; | |
| 177 | 추가: if calls == 12 { | |
| 178 | 추가: Err(ErrorCode::None) | |
| 179 | 추가: } else { | |
| 180 | 추가: Ok(()) | |
| 181 | 추가: } | |
| 182 | 추가: }); | |
| 183 | 추가: assert_eq!(result, Err(ErrorCode::None)); | |
| 184 | 추가: assert_eq!(calls, 12); | |
| 185 | 추가: } |
| @@ -227,6 +227,64 @@ fn tree(root: &std::path::Path) -> std::collections::BTreeMap<String, Option<[u8 | ||
| 227 | 227 | result |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 추가: #[test] | |
| 231 | 추가: fn saving_outside_inside_and_nested_in_source_preserves_the_original_tree() { | |
| 232 | 추가: for parent in ["", "source", "source/nested"] { | |
| 233 | 추가: let c = Case::new(); | |
| 234 | 추가: private_dir(&c.0.join("source")); | |
| 235 | 추가: private_dir(&c.0.join("source/nested")); | |
| 236 | 추가: private_dir(&c.0.join("source/nested/empty")); | |
| 237 | 추가: fs::write(c.0.join("source/한글.txt"), b"original").unwrap(); | |
| 238 | 추가: fs::write(c.0.join("source/nested/empty.txt"), b"").unwrap(); | |
| 239 | 추가: let expected = tree(&c.0.join("source")); | |
| 240 | 추가: let archive = NativePath::from_path(&c.0.join(parent).join("result.7z")); | |
| 241 | 추가: let mut request = c.request(&["source"]); | |
| 242 | 추가: if let Action::CreateSevenZip { output_file, .. } = &mut request.action { | |
| 243 | 추가: *output_file = archive.clone(); | |
| 244 | 추가: } | |
| 245 | 추가: success(&c.run(Message::Start(request))); | |
| 246 | 추가: let listed = c.run(Message::Start(Start { | |
| 247 | 추가: action: Action::List { | |
| 248 | 추가: archive: archive.clone(), | |
| 249 | 추가: }, | |
| 250 | 추가: limits: Limits::default(), | |
| 251 | 추가: })); | |
| 252 | 추가: assert_eq!(terminal(&listed).outcome, Outcome::Completed, "{listed:?}"); | |
| 253 | 추가: private_dir(&c.0.join("decoded")); | |
| 254 | 추가: let extracted = c.run(Message::Start(Start { | |
| 255 | 추가: action: Action::Extract { | |
| 256 | 추가: archive: archive.clone(), | |
| 257 | 추가: destination: c.path("decoded"), | |
| 258 | 추가: selection: Selection::All, | |
| 259 | 추가: list_id: None, | |
| 260 | 추가: gzip_output_name: None, | |
| 261 | 추가: }, | |
| 262 | 추가: limits: Limits::default(), | |
| 263 | 추가: })); | |
| 264 | 추가: assert_eq!( | |
| 265 | 추가: terminal(&extracted).outcome, | |
| 266 | 추가: Outcome::Completed, | |
| 267 | 추가: "{extracted:?}" | |
| 268 | 추가: ); | |
| 269 | 추가: assert_eq!(tree(&c.0.join("decoded/source")), expected); | |
| 270 | 추가: if let Some(tool) = std::env::var_os("ZIPELO_TEST_7ZIP") { | |
| 271 | 추가: let output = Command::new(tool) | |
| 272 | 추가: .args(["x", "-y"]) | |
| 273 | 추가: .arg(archive.to_path().unwrap()) | |
| 274 | 추가: .arg(format!("-o{}", c.0.join("independent").display())) | |
| 275 | 추가: .output() | |
| 276 | 추가: .unwrap(); | |
| 277 | 추가: assert!(output.status.success(), "{output:?}"); | |
| 278 | 추가: assert_eq!(tree(&c.0.join("independent/source")), expected); | |
| 279 | 추가: } | |
| 280 | 추가: assert!( | |
| 281 | 추가: !tree(&c.0.join("source")) | |
| 282 | 추가: .keys() | |
| 283 | 추가: .any(|name| name.contains(".zipelo-")) | |
| 284 | 추가: ); | |
| 285 | 추가: } | |
| 286 | 추가: } | |
| 287 | 추가: | |
| 230 | 288 | #[test] |
| 231 | 289 | fn mixed_unicode_files_and_empty_bitmap_boundaries_round_trip() { |
| 232 | 290 | for count in [7, 8, 9] { |
| @@ -595,6 +653,146 @@ fn source_changes_new_destination_and_cancel_before_publication_are_preserved() | ||
| 595 | 653 | } |
| 596 | 654 | } |
| 597 | 655 | |
| 656 | 추가: #[cfg(target_os = "linux")] | |
| 657 | 추가: #[test] | |
| 658 | 추가: fn internal_destination_still_rejects_real_source_changes_and_cancellation() { | |
| 659 | 추가: for parent in ["source", "source/nested"] { | |
| 660 | 추가: for operation in [ | |
| 661 | 추가: "add", | |
| 662 | 추가: "foreign-temp", | |
| 663 | 추가: "remove", | |
| 664 | 추가: "rename", | |
| 665 | 추가: "modify", | |
| 666 | 추가: "replace-dir", | |
| 667 | 추가: "cancel", | |
| 668 | 추가: ] { | |
| 669 | 추가: let c = Case::new(); | |
| 670 | 추가: private_dir(&c.0.join("source")); | |
| 671 | 추가: private_dir(&c.0.join("source/nested")); | |
| 672 | 추가: let directory = c.0.join(parent); | |
| 673 | 추가: private_dir(&directory.join("empty")); | |
| 674 | 추가: fs::write(directory.join("file"), b"a".repeat(100_000)).unwrap(); | |
| 675 | 추가: let mut request = c.request(&["source"]); | |
| 676 | 추가: if let Action::CreateSevenZip { output_file, .. } = &mut request.action { | |
| 677 | 추가: *output_file = NativePath::from_path(&directory.join("result.7z")); | |
| 678 | 추가: } | |
| 679 | 추가: let marker = c.0.join("marker"); | |
| 680 | 추가: let release = c.0.join("release"); | |
| 681 | 추가: let mut command = c.command(); | |
| 682 | 추가: command | |
| 683 | 추가: .env("LD_PRELOAD", shim(&c, "io_fault.c")) | |
| 684 | 추가: .env("ZIPELO_TEST_FAULT", "pause") | |
| 685 | 추가: .env("ZIPELO_TEST_MARKER", &marker) | |
| 686 | 추가: .env("ZIPELO_TEST_RELEASE", &release); | |
| 687 | 추가: let mut changed = false; | |
| 688 | 추가: let events = c.run_with(&mut command, Message::Start(request), |event| { | |
| 689 | 추가: if changed | |
| 690 | 추가: || !matches!( | |
| 691 | 추가: event, | |
| 692 | 추가: Message::Progress { | |
| 693 | 추가: stage: Stage::Write, | |
| 694 | 추가: total_bytes: Some(_), | |
| 695 | 추가: .. | |
| 696 | 추가: } | |
| 697 | 추가: ) | |
| 698 | 추가: { | |
| 699 | 추가: return Vec::new(); | |
| 700 | 추가: } | |
| 701 | 추가: let until = std::time::Instant::now() + Duration::from_secs(5); | |
| 702 | 추가: while !marker.exists() { | |
| 703 | 추가: assert!(std::time::Instant::now() < until); | |
| 704 | 추가: std::thread::sleep(Duration::from_millis(2)); | |
| 705 | 추가: } | |
| 706 | 추가: match operation { | |
| 707 | 추가: "add" => fs::write(directory.join("new-file"), b"user addition").unwrap(), | |
| 708 | 추가: "foreign-temp" => { | |
| 709 | 추가: fs::write(directory.join(".zipelo-user.tmp"), b"user file").unwrap() | |
| 710 | 추가: } | |
| 711 | 추가: "remove" => fs::remove_file(directory.join("file")).unwrap(), | |
| 712 | 추가: "rename" => { | |
| 713 | 추가: fs::rename(directory.join("file"), directory.join("renamed")).unwrap() | |
| 714 | 추가: } | |
| 715 | 추가: "modify" => fs::write(directory.join("file"), b"user modification").unwrap(), | |
| 716 | 추가: "replace-dir" => { | |
| 717 | 추가: fs::rename(directory.join("empty"), c.0.join("old-empty")).unwrap(); | |
| 718 | 추가: private_dir(&directory.join("empty")); | |
| 719 | 추가: } | |
| 720 | 추가: _ => {} | |
| 721 | 추가: } | |
| 722 | 추가: changed = true; | |
| 723 | 추가: fs::write(&release, b"resume").unwrap(); | |
| 724 | 추가: if operation == "cancel" { | |
| 725 | 추가: vec![Message::Cancel] | |
| 726 | 추가: } else { | |
| 727 | 추가: Vec::new() | |
| 728 | 추가: } | |
| 729 | 추가: }); | |
| 730 | 추가: assert!(changed); | |
| 731 | 추가: failure( | |
| 732 | 추가: &events, | |
| 733 | 추가: if operation == "cancel" { | |
| 734 | 추가: ErrorCode::None | |
| 735 | 추가: } else { | |
| 736 | 추가: ErrorCode::SourceChanged | |
| 737 | 추가: }, | |
| 738 | 추가: ); | |
| 739 | 추가: assert!(!directory.join("result.7z").exists()); | |
| 740 | 추가: let expected_temp = if operation == "foreign-temp" { 1 } else { 0 }; | |
| 741 | 추가: assert_eq!( | |
| 742 | 추가: fs::read_dir(&directory) | |
| 743 | 추가: .unwrap() | |
| 744 | 추가: .filter(|entry| { | |
| 745 | 추가: entry | |
| 746 | 추가: .as_ref() | |
| 747 | 추가: .unwrap() | |
| 748 | 추가: .file_name() | |
| 749 | 추가: .to_string_lossy() | |
| 750 | 추가: .starts_with(".zipelo-") | |
| 751 | 추가: }) | |
| 752 | 추가: .count(), | |
| 753 | 추가: expected_temp | |
| 754 | 추가: ); | |
| 755 | 추가: if operation == "foreign-temp" { | |
| 756 | 추가: assert_eq!( | |
| 757 | 추가: fs::read(directory.join(".zipelo-user.tmp")).unwrap(), | |
| 758 | 추가: b"user file" | |
| 759 | 추가: ); | |
| 760 | 추가: } | |
| 761 | 추가: if operation == "modify" { | |
| 762 | 추가: assert_eq!( | |
| 763 | 추가: fs::read(directory.join("file")).unwrap(), | |
| 764 | 추가: b"user modification" | |
| 765 | 추가: ); | |
| 766 | 추가: } | |
| 767 | 추가: } | |
| 768 | 추가: } | |
| 769 | 추가: } | |
| 770 | 추가: | |
| 771 | 추가: #[cfg(target_os = "linux")] | |
| 772 | 추가: #[test] | |
| 773 | 추가: fn internal_destination_write_failures_clean_only_the_owned_temporary() { | |
| 774 | 추가: for fault in ["full", "sync-full"] { | |
| 775 | 추가: let c = Case::new(); | |
| 776 | 추가: private_dir(&c.0.join("source")); | |
| 777 | 추가: fs::write(c.0.join("source/file"), b"original").unwrap(); | |
| 778 | 추가: fs::write(c.0.join("source/.zipelo-user.tmp"), b"keep").unwrap(); | |
| 779 | 추가: let expected = tree(&c.0.join("source")); | |
| 780 | 추가: let mut request = c.request(&["source"]); | |
| 781 | 추가: if let Action::CreateSevenZip { output_file, .. } = &mut request.action { | |
| 782 | 추가: *output_file = c.path("source/result.7z"); | |
| 783 | 추가: } | |
| 784 | 추가: let mut command = c.command(); | |
| 785 | 추가: command | |
| 786 | 추가: .env("LD_PRELOAD", shim(&c, "io_fault.c")) | |
| 787 | 추가: .env("ZIPELO_TEST_FAULT", fault); | |
| 788 | 추가: failure( | |
| 789 | 추가: &c.run_with(&mut command, Message::Start(request), |_| Vec::new()), | |
| 790 | 추가: ErrorCode::DiskFull, | |
| 791 | 추가: ); | |
| 792 | 추가: assert_eq!(tree(&c.0.join("source")), expected); | |
| 793 | 추가: } | |
| 794 | 추가: } | |
| 795 | 추가: | |
| 598 | 796 | #[cfg(target_os = "linux")] |
| 599 | 797 | #[test] |
| 600 | 798 | fn encoder_finish_header_write_seek_and_patch_errors_publish_nothing() { |