충돌 선택 공용 타입과 코덱을 추가함
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
6ee28153efb356c3eb885cc95a17f9f0647ef85d- 부모
- 38ea811
변경된 파일 6개
+376-10| @@ -57,15 +57,27 @@ revision 2의 기존 필드와 오류 tag 0~12 및 입력/출력 기본 한도 | ||
| 57 | 57 | |
| 58 | 58 | ## 공유 codec |
| 59 | 59 | |
| 60 | 삭제: `protocol.rs`는 요청과 이벤트 타입, `wire.rs`는 LE codec이며 비밀 값이 담긴 프레임 버퍼는 zeroize로 정리합니다. 앱은 이 라이브러리의 타입과 Reader/Writer를 사용할 수 있습니다. `contract.json`은 합의한 revision 2 원문입니다. | |
| 60 | 추가: `protocol.rs`는 요청과 이벤트 타입, `wire.rs`는 LE codec이며 비밀 값이 담긴 프레임 버퍼는 zeroize로 정리합니다. 앱은 이 라이브러리의 타입과 Reader/Writer를 사용할 수 있습니다. `contract.json`은 합의한 revision 3 원문이며 `extract_conflicts.status`에서 구현 상태를 구분합니다. | |
| 61 | 61 | |
| 62 | 62 | 헤더는 ZAW1, version u16=1, kind u16, body length u32, reserved u32=0, job ID u64, sequence u64의 32바이트입니다. 양방향 sequence는 각각 0부터 시작합니다. body는 최대 1 MiB이며 한 방향당 최대 1,000,000프레임입니다. 잘린 프레임, 알 수 없는 tag, 잔여 payload, 잘못된 ID/sequence를 거부합니다. |
| 63 | 63 | |
| 64 | 삭제: - kind: Start=1, Password=2, Cancel=3, Accepted=100, Entry=101, ListEnd=102, PasswordRequired=103, Progress=104, Output=105, Terminal=106, CancelAck=107입니다. | |
| 64 | 추가: - kind: Start=1, Password=2, Cancel=3, StartInteractive=4, ConflictReply=5, Accepted=100, Entry=101, ListEnd=102, PasswordRequired=103, Progress=104, Output=105, Terminal=106, CancelAck=107, ConflictRequired=108, ConflictResolved=109입니다. 새 kind의 런타임 지원 상태는 아래 revision 3 절을 따릅니다. | |
| 65 | 65 | - body 필드는 `protocol.rs` 선언 순서입니다. enum은 선언 순서의 u8 tag이며 NativePath/SourceObject만 Unix=1, Windows=2입니다. bool/Option은 0 또는 1입니다. String/Vec는 u32 길이 뒤 원소를 저장하며 String은 UTF-8 바이트 길이입니다. `[u8; N]`은 길이 없이 N바이트입니다. action variant의 필드는 선언 순서를 사용합니다. Start는 action 뒤 limits(input u64, output u64, entries u32)입니다. |
| 66 | 66 | - Password의 비밀 값은 Debug에 노출되지 않습니다. 암호 작업은 PasswordRequired의 challenge_id와 일치하는 Password를 한 번 받습니다. 오래된 ID, 중복 또는 요청 전 암호는 Protocol 오류입니다. 비밀 값은 로그나 파일에 저장하지 않습니다. |
| 67 | 67 | - CancelAck.request_sequence는 요청 헤더 sequence입니다. Requested, AlreadyRequested, TooLate, Finished는 최종 결과와 별개입니다. 종료와 경합한 요청은 읽히지 않아 응답이 없을 수 있습니다. Terminal은 마지막 프레임이며 Failed/Cancelled도 정상 전달 뒤 프로세스 exit=0입니다. 앱은 Terminal과 stdout/stderr EOF, child wait를 모두 확인해야 합니다. |
| 68 | 68 | |
| 69 | 추가: ## revision 3 충돌 계약 | |
| 70 | 추가: | |
| 71 | 추가: 공용 타입과 codec만 준비된 단계입니다. 현재 실행 경로는 revision 2의 `Start`를 유지하며 `StartInteractive`는 아직 처리하지 않습니다. 충돌 런타임 구현과 앱 연동 검증이 끝나기 전에는 새 요청을 실제 기능에 활성화하지 않습니다. 이 상태는 덮어쓰기 기능의 구현 완료를 뜻하지 않습니다. | |
| 72 | 추가: | |
| 73 | 추가: - `StartInteractive(Start)`는 kind 4이며 기존 Start body를 그대로 사용합니다. Extract만 허용하고 List와 CreateZip은 codec에서 거부합니다. 기존 Start=1의 충돌 시 중단 동작과 모든 기존 필드 및 tag는 유지하며 구버전 작업자로 자동 재시도하지 않습니다. | |
| 74 | 추가: - `ConflictChoice`는 Overwrite=0, Skip=1, Rename=2입니다. `ConflictReply`(5)는 challenge_id u64, choice u8, apply_to_remaining bool 순서입니다. | |
| 75 | 추가: - `ConflictRequired`(108)는 challenge_id u64, entry_id u32, relative_name String, incoming_size u64, existing_size u64 순서입니다. 일반 파일끼리의 충돌에 세 선택을 허용하며 폴더끼리는 합치고 파일과 폴더 충돌 및 링크는 차단합니다. | |
| 76 | 추가: - `ConflictResolved`(109)는 entry_id u32, relative_name String, choice u8 순서입니다. 일괄 적용에도 항목마다 보내며 저장 성공을 뜻하지 않습니다. 교체와 이름 변경의 게시 성공은 기존 `Output::Created`로 별도 확인하고 건너뛰기에는 Created를 보내지 않습니다. | |
| 77 | 추가: - Rename 이름은 작업자가 같은 폴더 안의 미사용 번호 이름으로 정합니다. 일괄 적용은 현재 작업의 남은 일반 파일 충돌에만 적용합니다. 질문은 한 번에 하나이며 잘못되거나 중복된 응답은 Protocol, 답변 전 EOF도 Protocol입니다. 취소를 처리하고 기존 300초 제한에 대기 시간을 포함합니다. | |
| 78 | 추가: - 전부 건너뛰고 새 출력도 없으면 Completed, Publication::None, created_count=0, Durability::NotApplicable입니다. 새 폴더가 만들어졌다면 해당 Output과 실제 집계를 유지합니다. 교체는 created_count에 포함하며 건너뛰기는 제외합니다. | |
| 79 | 추가: - 런타임의 목표는 전체 무결성 검증 후 질문하고 목적지 임시 파일 기록, 검증, sync와 close를 마친 뒤 교체하는 것입니다. 교체 전 실패에는 원본을 보존하고 교체 후 오류에는 실제 게시, 내구성과 정리 상태를 보고합니다. 전체 작업의 원상 복구를 약속하지 않습니다. | |
| 80 | 추가: | |
| 69 | 81 | ## 검증과 의존성 |
| 70 | 82 | |
| 71 | 83 | 시험은 `tests/rust-archive-worker`에 있습니다. Python 표준 라이브러리로 만든 ZIP/TAR/GZ fixture와 실제 자식 프로세스를 사용합니다. 전체 검증 명령은 저장소 루트의 `python3 tests/ci/run_rust.py local`입니다. Windows 교차 빌드는 실제 Windows 실행 검증을 대신하지 않습니다. |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | { |
| 2 | 삭제: "status": "implemented-streaming-runtime", | |
| 2 | 추가: "status": "revision-3-codec-ready-runtime-pending", | |
| 3 | 3 | "version": 1, |
| 4 | 4 | "scope": "One job per separately spawned Rust worker; shared binary codec. Process separation is not an OS sandbox.", |
| 5 | 5 | "frame": { |
| @@ -28,7 +28,9 @@ | ||
| 28 | 28 | "commands": { |
| 29 | 29 | "Start": "Exactly once: List{archive}, Extract{archive,destination,selection:All|EntryIds{ids:[u32]},list_id:optional<ListId>,gzip_output_name:optional<UTF8>}, CreateZip{sources:[source_path,archive_name],output_file,method:Store|Deflate,encryption:None|Aes256}. App supplies job_id; caller can lower worker hard limits. Extract destination is always an absolute output directory. EntryIds requires list_id; All may supply list_id to bind extraction to a displayed list.", |
| 30 | 30 | "Password": "Matching outstanding challenge_id:u64 and max1024 UTF-8 bytes; never log, Debug, echo or persist secrets.", |
| 31 | 삭제: "Cancel": "Matching header job_id and empty body; command header sequence identifies the request. See CancelAck. Request acceptance is separate from final outcome. EOF alone is not successful cancellation." | |
| 31 | 추가: "Cancel": "Matching header job_id and empty body; command header sequence identifies the request. See CancelAck. Request acceptance is separate from final outcome. EOF alone is not successful cancellation.", | |
| 32 | 추가: "StartInteractive": "Kind 4, body identical to Start with action restricted to Extract. Exactly one initial Start or StartInteractive. Invalid non-Extract action is rejected by the shared encoder and decoder. Opt in to interactive regular-file conflicts; never retry through legacy Start or an older worker automatically. Runtime support is pending in this commit.", | |
| 33 | 추가: "ConflictReply": "Kind 5: challenge_id:u64, choice:ConflictChoice(u8), apply_to_remaining:bool. Match the one outstanding conflict challenge exactly once. Applying to remaining affects only later regular-file conflicts in this job." | |
| 32 | 34 | }, |
| 33 | 35 | "events": { |
| 34 | 36 | "Accepted": "Action and capabilities; encryption capability is true for implemented ZipCrypto extraction and WinZip AES-256 extraction/creation.", |
| @@ -55,10 +57,12 @@ | ||
| 55 | 57 | "TooLate": "Final job completion/commit decision has been sealed so cancellation can no longer influence the outcome; final outcome may still be Failed or publication Uncertain. Previously created entries alone do not make a multi-entry job TooLate.", |
| 56 | 58 | "Finished": "Business outcome has already been fixed, but Terminal has not yet been emitted. Does not establish success, EOF, child exit or reaping.", |
| 57 | 59 | "ordering": "Each well-formed Cancel consumed before Terminal is acknowledged once before Terminal. Terminal is the last worker protocol frame. A Cancel racing with Terminal/exit may remain unread and have no acknowledgement; app uses Terminal plus EOF and wait, never synthesizes a worker acknowledgement or successful cancellation." |
| 58 | 삭제: } | |
| 60 | 추가: }, | |
| 61 | 추가: "ConflictRequired": "Kind 108: challenge_id:u64, entry_id:u32, relative_name:UTF8, incoming_size:u64, existing_size:u64. One ordinary-file conflict at a time, after complete archive integrity validation. All three choices are permitted; links and file/directory type conflicts remain rejected.", | |
| 62 | 추가: "ConflictResolved": "Kind 109: entry_id:u32, relative_name:UTF8, choice:ConflictChoice(u8). Emit for every resolved conflict, including automatically applied choices. This records the action and resolved name, not successful publication; successful overwrite or rename also requires Output Created. Skip emits no Output Created." | |
| 59 | 63 | }, |
| 60 | 64 | "lifecycle": [ |
| 61 | 삭제: "Start once; no automatic retry or overwrite. Password/Cancel remain readable during work.", | |
| 65 | 추가: "Exactly one Start or StartInteractive; no automatic retry or fallback. Password/Cancel remain readable during work. ConflictReply is accepted only for a matching outstanding interactive conflict.", | |
| 62 | 66 | "Parent drains both streams concurrently. Stdout is protocol only; stderr is bounded diagnostics without secrets.", |
| 63 | 67 | "Exactly one Terminal ends business results and is the final worker protocol frame; CancelAck can precede but never follow it. Worker exits0 after delivered terminal, including Failed/Cancelled. Malformed protocol or crash can exit nonzero without terminal.", |
| 64 | 68 | "App requires matching terminal, stdout/stderr EOF and owned child wait/exit before replacement/close. EOF/exit0 alone is not success.", |
| @@ -69,7 +73,7 @@ | ||
| 69 | 73 | "safe_output": [ |
| 70 | 74 | "Reject absolute/dotdot/drive/UNC/device/reserved/alternate-stream names and case/path collisions before writes.", |
| 71 | 75 | "Reject archive links/special entries on extraction. Do not follow output parent symlinks/reparse points.", |
| 72 | 삭제: "Create output files exclusively; never truncate or write pre-existing files. GZip FNAME does not choose destination.", | |
| 76 | 추가: "Legacy Start creates output files exclusively and never truncates or writes pre-existing files. StartInteractive may replace an existing ordinary file only after the agreed choice and complete temporary output validation. GZip FNAME does not choose destination.", | |
| 73 | 77 | "CRC/size/stream-end validation precedes committed output events; preserve commit/durability/cleanup distinctions." |
| 74 | 78 | ], |
| 75 | 79 | "pending": [ |
| @@ -81,12 +85,18 @@ | ||
| 81 | 85 | "implementation_verified": false, |
| 82 | 86 | "policy": "Human approved pure Rust RustCrypto under MIT/Apache. No home-grown AES or password KDF; approval alone does not enable encryption capability." |
| 83 | 87 | }, |
| 84 | 삭제: "revision": 2, | |
| 88 | 추가: "revision": 3, | |
| 85 | 89 | "coordination": { |
| 86 | 90 | "frontend_message_id": "41a0e5a5-27d0-437f-805d-d39313082096", |
| 87 | 91 | "basis": "Revision 2 list identity, explicit raw GZip output naming and cancellation acknowledgement are implemented. Field order and tags remain unchanged.", |
| 88 | 92 | "streaming_frontend_message_id": "59142fd4-22d3-4dc5-a875-5347e1b054da", |
| 89 | 삭제: "disk_full_frontend_message_id": "3b01f4c4-c9b4-4c72-a9a0-b3df39979ea1" | |
| 93 | 추가: "disk_full_frontend_message_id": "3b01f4c4-c9b4-4c72-a9a0-b3df39979ea1", | |
| 94 | 추가: "conflict_frontend_message_ids": [ | |
| 95 | 추가: "37815dda-3271-4f83-be4d-8da1a6e0c2ab", | |
| 96 | 추가: "87ff39f9-f7fe-4efc-bd2e-d73ab3246356" | |
| 97 | 추가: ], | |
| 98 | 추가: "conflict_backend_message_id": "64e29128-e8a2-45e5-8577-db84a66feaa9", | |
| 99 | 추가: "revision_3_status": "Joint agreement complete. Types and binary codec ready; conflict runtime and frontend integration are not implemented or verified by this commit. Existing revision 2 Start execution remains unchanged." | |
| 90 | 100 | }, |
| 91 | 101 | "list_identity": { |
| 92 | 102 | "ListId": { |
| @@ -114,7 +124,7 @@ | ||
| 114 | 124 | "gzip_output_name": "Required Some(nonempty validated UTF-8 single leaf filename) for raw GZIP extraction, for both All and EntryIds. Reject absolute/drive/UNC/device/alternate-stream/reserved names, separators, dot/dotdot and invalid leaf names before creating outputs. Missing/invalid value returns InvalidRequest; no implicit basename or FNAME fallback.", |
| 115 | 125 | "other_formats": "Must be None for ZIP, TAR and TAR_GZIP; reject Some as InvalidRequest rather than silently ignoring it. TAR_GZIP uses validated inner TAR member names.", |
| 116 | 126 | "gzip_catalog": "Raw GZIP is one logical stream entry with entry_id0. Its listed display name is not an output path; entry selection still requires ListId.", |
| 117 | 삭제: "publication": "Resolve the supplied leaf under destination using the same no-follow and exclusive-create guards. Existing destination files return Conflict; never overwrite, rename to an automatic alternative or retry." | |
| 127 | 추가: "publication": "Resolve the supplied leaf under destination using the same no-follow guards. Existing destination files return Conflict for legacy Start. StartInteractive follows the regular-file conflict policy; never automatically downgrade or retry through legacy Start." | |
| 118 | 128 | }, |
| 119 | 129 | "design_references": [ |
| 120 | 130 | { |
| @@ -192,5 +202,23 @@ | ||
| 192 | 202 | "limits": "All expanded file and directory entries count toward entries (default 10000). Only file logical bytes count toward min(input,output), default output 16 GiB. Preserve 8 MiB metadata and 64-component name limits. Validate the complete plan and case-insensitive/path-prefix conflicts before requesting a password.", |
| 193 | 203 | "consistency": "Capture each file from its validated open handle. Compare planned object identity, kind, size and modification time before capture and check planned objects again before publishing the completed ZIP; detected changes fail SourceChanged. This is not an atomic snapshot of an entire directory tree.", |
| 194 | 204 | "encryption": "AES-256 protects file contents using the existing AE-2 encoding. Directory entries are stored as zero-byte unencrypted directory records; entry names remain visible, as with other ZIP entries." |
| 205 | 추가: }, | |
| 206 | 추가: "conflict_choice_tags": { | |
| 207 | 추가: "Overwrite": 0, | |
| 208 | 추가: "Skip": 1, | |
| 209 | 추가: "Rename": 2 | |
| 210 | 추가: }, | |
| 211 | 추가: "extract_conflicts": { | |
| 212 | 추가: "status": "codec-ready-runtime-pending", | |
| 213 | 추가: "compatibility": "Preserve frame version 1, every existing message kind, field order and enum tag. Add StartInteractive=4, ConflictReply=5, ConflictRequired=108 and ConflictResolved=109. Older workers reject kind 4 before output. Do not automatically retry, overwrite or fall back.", | |
| 214 | 추가: "legacy": "Start keeps its existing abort-on-conflict behavior. List and CreateZip never accept interactive conflict mode. Existing limits, source identity, integrity checks and path guards remain mandatory.", | |
| 215 | 추가: "scope": "Only ordinary-file/ordinary-file collisions. Merge existing directories as before; reject file/directory type collisions, symbolic links, reparse points and other special entries. Complete integrity validation of the entire catalog precedes conflict questions and destination publication.", | |
| 216 | 추가: "rename": "Worker selects an unused numbered sibling in the same directory under the validated output root. The app never supplies an arbitrary replacement path. Revalidate the chosen destination before publication.", | |
| 217 | 추가: "wait": "At most one outstanding conflict or password challenge. Reject premature, stale or duplicate replies with Protocol. Cancel remains readable during a conflict wait. EOF without a reply fails Protocol; the existing 300-second job duration includes waits.", | |
| 218 | 추가: "apply_to_remaining": "Keep the chosen policy only for the remaining ordinary-file conflicts in this job. Emit ConflictResolved for every such entry even without another question. Never carry the policy to another job or a file/directory or link collision.", | |
| 219 | 추가: "events": "ConflictResolved reports an action and resolved relative name, not storage success. For overwrite and rename, Output Created separately confirms publication; skip has no Created output. On later errors preserve publication, durability and cleanup distinctions.", | |
| 220 | 추가: "overwrite": "Write, verify, sync and close a new owned temporary file in the destination directory before replacing the existing ordinary file. A pre-replacement failure preserves the original. After replacement, report actual publication and durability; do not claim whole-job rollback.", | |
| 221 | 추가: "counts": "created_count includes published replacement files and newly created files/directories; excludes skipped files. If all files are skipped and no new directory or other output is created, finish Completed/None with created_count=0 and Durability NotApplicable. Newly created directories retain their Output events and actual counts even if all files are skipped.", | |
| 222 | 추가: "implementation_boundary": "This commit provides the agreed protocol types and codec only. The current runtime rejects StartInteractive as an unsupported initial message. Do not enable interactive requests in a shipping client until worker implementation and integration checks finish." | |
| 195 | 223 | } |
| 196 | 224 | } |
| @@ -255,6 +255,12 @@ pub enum PasswordPurpose { | ||
| 255 | 255 | Decrypt, |
| 256 | 256 | Encrypt, |
| 257 | 257 | } |
| 258 | 추가: #[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| 259 | 추가: pub enum ConflictChoice { | |
| 260 | 추가: Overwrite, | |
| 261 | 추가: Skip, | |
| 262 | 추가: Rename, | |
| 263 | 추가: } | |
| 258 | 264 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 259 | 265 | pub struct Terminal { |
| 260 | 266 | pub outcome: Outcome, |
| @@ -285,6 +291,12 @@ pub enum Message { | ||
| 285 | 291 | secret: Secret, |
| 286 | 292 | }, |
| 287 | 293 | Cancel, |
| 294 | 추가: StartInteractive(Start), | |
| 295 | 추가: ConflictReply { | |
| 296 | 추가: challenge_id: u64, | |
| 297 | 추가: choice: ConflictChoice, | |
| 298 | 추가: apply_to_remaining: bool, | |
| 299 | 추가: }, | |
| 288 | 300 | Accepted { |
| 289 | 301 | action: ActionKind, |
| 290 | 302 | encryption: bool, |
| @@ -315,4 +327,16 @@ pub enum Message { | ||
| 315 | 327 | request_sequence: u64, |
| 316 | 328 | status: CancelStatus, |
| 317 | 329 | }, |
| 330 | 추가: ConflictRequired { | |
| 331 | 추가: challenge_id: u64, | |
| 332 | 추가: entry_id: u32, | |
| 333 | 추가: relative_name: String, | |
| 334 | 추가: incoming_size: u64, | |
| 335 | 추가: existing_size: u64, | |
| 336 | 추가: }, | |
| 337 | 추가: ConflictResolved { | |
| 338 | 추가: entry_id: u32, | |
| 339 | 추가: relative_name: String, | |
| 340 | 추가: choice: ConflictChoice, | |
| 341 | 추가: }, | |
| 318 | 342 | } |
| @@ -139,6 +139,7 @@ enumeration!(Durability{NotApplicable=0,Synced=1,Unconfirmed=2,Failed=3}); | ||
| 139 | 139 | enumeration!(Cleanup{Complete=0,Failed=1,Unconfirmed=2}); |
| 140 | 140 | enumeration!(CancelStatus{Requested=0,AlreadyRequested=1,TooLate=2,Finished=3}); |
| 141 | 141 | enumeration!(PasswordPurpose{Decrypt=0,Encrypt=1}); |
| 142 | 추가: enumeration!(ConflictChoice{Overwrite=0,Skip=1,Rename=2}); | |
| 142 | 143 | macro_rules! structure {($t:ident {$($f:ident),*})=>{impl Wire for $t { |
| 143 | 144 | fn enc(&self,e:&mut Encoder)->io::Result<()> {$(self.$f.enc(e)?;)*Ok(())} |
| 144 | 145 | fn dec(d:&mut Decoder<'_>)->io::Result<Self> {Ok(Self {$($f:Wire::dec(d)?,)*})} |
| @@ -323,6 +324,23 @@ impl Message { | ||
| 323 | 324 | 2 |
| 324 | 325 | } |
| 325 | 326 | Self::Cancel => 3, |
| 327 | 추가: Self::StartInteractive(v) => { | |
| 328 | 추가: if !matches!(&v.action, Action::Extract { .. }) { | |
| 329 | 추가: return Err(invalid()); | |
| 330 | 추가: } | |
| 331 | 추가: v.enc(&mut e)?; | |
| 332 | 추가: 4 | |
| 333 | 추가: } | |
| 334 | 추가: Self::ConflictReply { | |
| 335 | 추가: challenge_id, | |
| 336 | 추가: choice, | |
| 337 | 추가: apply_to_remaining, | |
| 338 | 추가: } => { | |
| 339 | 추가: challenge_id.enc(&mut e)?; | |
| 340 | 추가: choice.enc(&mut e)?; | |
| 341 | 추가: apply_to_remaining.enc(&mut e)?; | |
| 342 | 추가: 5 | |
| 343 | 추가: } | |
| 326 | 344 | Self::Accepted { action, encryption } => { |
| 327 | 345 | action.enc(&mut e)?; |
| 328 | 346 | encryption.enc(&mut e)?; |
| @@ -387,6 +405,30 @@ impl Message { | ||
| 387 | 405 | status.enc(&mut e)?; |
| 388 | 406 | 107 |
| 389 | 407 | } |
| 408 | 추가: Self::ConflictRequired { | |
| 409 | 추가: challenge_id, | |
| 410 | 추가: entry_id, | |
| 411 | 추가: relative_name, | |
| 412 | 추가: incoming_size, | |
| 413 | 추가: existing_size, | |
| 414 | 추가: } => { | |
| 415 | 추가: challenge_id.enc(&mut e)?; | |
| 416 | 추가: entry_id.enc(&mut e)?; | |
| 417 | 추가: relative_name.enc(&mut e)?; | |
| 418 | 추가: incoming_size.enc(&mut e)?; | |
| 419 | 추가: existing_size.enc(&mut e)?; | |
| 420 | 추가: 108 | |
| 421 | 추가: } | |
| 422 | 추가: Self::ConflictResolved { | |
| 423 | 추가: entry_id, | |
| 424 | 추가: relative_name, | |
| 425 | 추가: choice, | |
| 426 | 추가: } => { | |
| 427 | 추가: entry_id.enc(&mut e)?; | |
| 428 | 추가: relative_name.enc(&mut e)?; | |
| 429 | 추가: choice.enc(&mut e)?; | |
| 430 | 추가: 109 | |
| 431 | 추가: } | |
| 390 | 432 | }; |
| 391 | 433 | Ok((kind, e.bytes)) |
| 392 | 434 | } |
| @@ -406,6 +448,18 @@ impl Message { | ||
| 406 | 448 | } |
| 407 | 449 | } |
| 408 | 450 | 3 => Self::Cancel, |
| 451 | 추가: 4 => { | |
| 452 | 추가: let start = Start::dec(&mut d)?; | |
| 453 | 추가: if !matches!(&start.action, Action::Extract { .. }) { | |
| 454 | 추가: return Err(invalid()); | |
| 455 | 추가: } | |
| 456 | 추가: Self::StartInteractive(start) | |
| 457 | 추가: } | |
| 458 | 추가: 5 => Self::ConflictReply { | |
| 459 | 추가: challenge_id: Wire::dec(&mut d)?, | |
| 460 | 추가: choice: Wire::dec(&mut d)?, | |
| 461 | 추가: apply_to_remaining: Wire::dec(&mut d)?, | |
| 462 | 추가: }, | |
| 409 | 463 | 100 => Self::Accepted { |
| 410 | 464 | action: Wire::dec(&mut d)?, |
| 411 | 465 | encryption: Wire::dec(&mut d)?, |
| @@ -442,6 +496,18 @@ impl Message { | ||
| 442 | 496 | request_sequence: Wire::dec(&mut d)?, |
| 443 | 497 | status: Wire::dec(&mut d)?, |
| 444 | 498 | }, |
| 499 | 추가: 108 => Self::ConflictRequired { | |
| 500 | 추가: challenge_id: Wire::dec(&mut d)?, | |
| 501 | 추가: entry_id: Wire::dec(&mut d)?, | |
| 502 | 추가: relative_name: Wire::dec(&mut d)?, | |
| 503 | 추가: incoming_size: Wire::dec(&mut d)?, | |
| 504 | 추가: existing_size: Wire::dec(&mut d)?, | |
| 505 | 추가: }, | |
| 506 | 추가: 109 => Self::ConflictResolved { | |
| 507 | 추가: entry_id: Wire::dec(&mut d)?, | |
| 508 | 추가: relative_name: Wire::dec(&mut d)?, | |
| 509 | 추가: choice: Wire::dec(&mut d)?, | |
| 510 | 추가: }, | |
| 445 | 511 | _ => return Err(invalid()), |
| 446 | 512 | }; |
| 447 | 513 | if d.at != b.len() { |
| @@ -0,0 +1,234 @@ | ||
| 1 | 추가: use super::*; | |
| 2 | 추가: | |
| 3 | 추가: fn sample_start() -> Start { | |
| 4 | 추가: Start { | |
| 5 | 추가: action: Action::Extract { | |
| 6 | 추가: archive: NativePath::Unix(b"/archive".to_vec()), | |
| 7 | 추가: destination: NativePath::Unix(b"/output".to_vec()), | |
| 8 | 추가: selection: Selection::All, | |
| 9 | 추가: list_id: None, | |
| 10 | 추가: gzip_output_name: None, | |
| 11 | 추가: }, | |
| 12 | 추가: limits: Limits { | |
| 13 | 추가: input: 7, | |
| 14 | 추가: output: 8, | |
| 15 | 추가: entries: 9, | |
| 16 | 추가: }, | |
| 17 | 추가: } | |
| 18 | 추가: } | |
| 19 | 추가: | |
| 20 | 추가: fn encoded(message: &Message) -> Vec<u8> { | |
| 21 | 추가: let mut bytes = Vec::new(); | |
| 22 | 추가: Writer::new(&mut bytes, 17).send(message).unwrap(); | |
| 23 | 추가: bytes | |
| 24 | 추가: } | |
| 25 | 추가: | |
| 26 | 추가: fn decoded(bytes: &[u8]) -> Message { | |
| 27 | 추가: let mut reader = Reader::new(bytes); | |
| 28 | 추가: let (job, sequence, message) = reader.read().unwrap().unwrap(); | |
| 29 | 추가: assert_eq!((job, sequence), (17, 0)); | |
| 30 | 추가: assert!(reader.read().unwrap().is_none()); | |
| 31 | 추가: message | |
| 32 | 추가: } | |
| 33 | 추가: | |
| 34 | 추가: #[test] | |
| 35 | 추가: fn interactive_start_preserves_legacy_body_and_frame_version() { | |
| 36 | 추가: let start = sample_start(); | |
| 37 | 추가: let legacy = encoded(&Message::Start(start.clone())); | |
| 38 | 추가: let interactive = encoded(&Message::StartInteractive(start.clone())); | |
| 39 | 추가: let mut expected = legacy; | |
| 40 | 추가: expected[6..8].copy_from_slice(&4u16.to_le_bytes()); | |
| 41 | 추가: assert_eq!(interactive, expected); | |
| 42 | 추가: assert_eq!(&interactive[..6], b"ZAW1\x01\x00"); | |
| 43 | 추가: match decoded(&interactive) { | |
| 44 | 추가: Message::StartInteractive(actual) => assert_eq!(actual, start), | |
| 45 | 추가: other => panic!("unexpected frame: {other:?}"), | |
| 46 | 추가: } | |
| 47 | 추가: } | |
| 48 | 추가: | |
| 49 | 추가: #[test] | |
| 50 | 추가: fn interactive_start_rejects_list_and_create_on_both_codec_directions() { | |
| 51 | 추가: for action in [ | |
| 52 | 추가: Action::List { | |
| 53 | 추가: archive: NativePath::Unix(b"/archive".to_vec()), | |
| 54 | 추가: }, | |
| 55 | 추가: Action::CreateZip { | |
| 56 | 추가: sources: Vec::new(), | |
| 57 | 추가: output_file: NativePath::Unix(b"/output.zip".to_vec()), | |
| 58 | 추가: method: Method::Store, | |
| 59 | 추가: encryption: Encryption::None, | |
| 60 | 추가: }, | |
| 61 | 추가: ] { | |
| 62 | 추가: let start = Start { | |
| 63 | 추가: action, | |
| 64 | 추가: limits: Limits::default(), | |
| 65 | 추가: }; | |
| 66 | 추가: let mut bytes = Vec::new(); | |
| 67 | 추가: assert!( | |
| 68 | 추가: Writer::new(&mut bytes, 17) | |
| 69 | 추가: .send(&Message::StartInteractive(start.clone())) | |
| 70 | 추가: .is_err() | |
| 71 | 추가: ); | |
| 72 | 추가: assert!(bytes.is_empty()); | |
| 73 | 추가: let mut frame = encoded(&Message::Start(start)); | |
| 74 | 추가: frame[6..8].copy_from_slice(&4u16.to_le_bytes()); | |
| 75 | 추가: assert_eq!( | |
| 76 | 추가: Reader::new(frame.as_slice()).read().unwrap_err().kind(), | |
| 77 | 추가: std::io::ErrorKind::InvalidData | |
| 78 | 추가: ); | |
| 79 | 추가: } | |
| 80 | 추가: } | |
| 81 | 추가: | |
| 82 | 추가: #[test] | |
| 83 | 추가: fn conflict_reply_choices_and_apply_flag_have_stable_bytes() { | |
| 84 | 추가: for (choice, tag) in [ | |
| 85 | 추가: (ConflictChoice::Overwrite, 0), | |
| 86 | 추가: (ConflictChoice::Skip, 1), | |
| 87 | 추가: (ConflictChoice::Rename, 2), | |
| 88 | 추가: ] { | |
| 89 | 추가: for apply_to_remaining in [false, true] { | |
| 90 | 추가: let frame = encoded(&Message::ConflictReply { | |
| 91 | 추가: challenge_id: 0x0807060504030201, | |
| 92 | 추가: choice, | |
| 93 | 추가: apply_to_remaining, | |
| 94 | 추가: }); | |
| 95 | 추가: assert_eq!(&frame[6..12], &[5, 0, 10, 0, 0, 0]); | |
| 96 | 추가: assert_eq!( | |
| 97 | 추가: &frame[32..], | |
| 98 | 추가: &[1, 2, 3, 4, 5, 6, 7, 8, tag, u8::from(apply_to_remaining)] | |
| 99 | 추가: ); | |
| 100 | 추가: match decoded(&frame) { | |
| 101 | 추가: Message::ConflictReply { | |
| 102 | 추가: challenge_id, | |
| 103 | 추가: choice: actual_choice, | |
| 104 | 추가: apply_to_remaining: actual_apply, | |
| 105 | 추가: } => { | |
| 106 | 추가: assert_eq!(challenge_id, 0x0807060504030201); | |
| 107 | 추가: assert_eq!(actual_choice, choice); | |
| 108 | 추가: assert_eq!(actual_apply, apply_to_remaining); | |
| 109 | 추가: } | |
| 110 | 추가: other => panic!("unexpected frame: {other:?}"), | |
| 111 | 추가: } | |
| 112 | 추가: } | |
| 113 | 추가: } | |
| 114 | 추가: } | |
| 115 | 추가: | |
| 116 | 추가: #[test] | |
| 117 | 추가: fn conflict_metadata_round_trips_unicode_names_and_full_width_sizes() { | |
| 118 | 추가: let name = "자료/보고서.txt"; | |
| 119 | 추가: let required = encoded(&Message::ConflictRequired { | |
| 120 | 추가: challenge_id: u64::MAX, | |
| 121 | 추가: entry_id: u32::MAX, | |
| 122 | 추가: relative_name: name.to_owned(), | |
| 123 | 추가: incoming_size: u64::MAX - 1, | |
| 124 | 추가: existing_size: u64::MAX - 2, | |
| 125 | 추가: }); | |
| 126 | 추가: assert_eq!(&required[6..8], &108u16.to_le_bytes()); | |
| 127 | 추가: match decoded(&required) { | |
| 128 | 추가: Message::ConflictRequired { | |
| 129 | 추가: challenge_id, | |
| 130 | 추가: entry_id, | |
| 131 | 추가: relative_name, | |
| 132 | 추가: incoming_size, | |
| 133 | 추가: existing_size, | |
| 134 | 추가: } => { | |
| 135 | 추가: assert_eq!(challenge_id, u64::MAX); | |
| 136 | 추가: assert_eq!(entry_id, u32::MAX); | |
| 137 | 추가: assert_eq!(relative_name, name); | |
| 138 | 추가: assert_eq!(incoming_size, u64::MAX - 1); | |
| 139 | 추가: assert_eq!(existing_size, u64::MAX - 2); | |
| 140 | 추가: } | |
| 141 | 추가: other => panic!("unexpected frame: {other:?}"), | |
| 142 | 추가: } | |
| 143 | 추가: for choice in [ | |
| 144 | 추가: ConflictChoice::Overwrite, | |
| 145 | 추가: ConflictChoice::Skip, | |
| 146 | 추가: ConflictChoice::Rename, | |
| 147 | 추가: ] { | |
| 148 | 추가: let resolved = encoded(&Message::ConflictResolved { | |
| 149 | 추가: entry_id: 23, | |
| 150 | 추가: relative_name: "자료/보고서 (1).txt".to_owned(), | |
| 151 | 추가: choice, | |
| 152 | 추가: }); | |
| 153 | 추가: assert_eq!(&resolved[6..8], &109u16.to_le_bytes()); | |
| 154 | 추가: match decoded(&resolved) { | |
| 155 | 추가: Message::ConflictResolved { | |
| 156 | 추가: entry_id, | |
| 157 | 추가: relative_name, | |
| 158 | 추가: choice: actual, | |
| 159 | 추가: } => { | |
| 160 | 추가: assert_eq!(entry_id, 23); | |
| 161 | 추가: assert_eq!(relative_name, "자료/보고서 (1).txt"); | |
| 162 | 추가: assert_eq!(actual, choice); | |
| 163 | 추가: } | |
| 164 | 추가: other => panic!("unexpected frame: {other:?}"), | |
| 165 | 추가: } | |
| 166 | 추가: } | |
| 167 | 추가: } | |
| 168 | 추가: | |
| 169 | 추가: #[test] | |
| 170 | 추가: fn conflict_frames_reject_unknown_choices_flags_utf8_and_kinds() { | |
| 171 | 추가: let reply = encoded(&Message::ConflictReply { | |
| 172 | 추가: challenge_id: 1, | |
| 173 | 추가: choice: ConflictChoice::Skip, | |
| 174 | 추가: apply_to_remaining: false, | |
| 175 | 추가: }); | |
| 176 | 추가: for (offset, value) in [(40, 3), (41, 2)] { | |
| 177 | 추가: let mut invalid = reply.clone(); | |
| 178 | 추가: invalid[offset] = value; | |
| 179 | 추가: assert!(Reader::new(invalid.as_slice()).read().is_err()); | |
| 180 | 추가: } | |
| 181 | 추가: let mut required = encoded(&Message::ConflictRequired { | |
| 182 | 추가: challenge_id: 1, | |
| 183 | 추가: entry_id: 2, | |
| 184 | 추가: relative_name: "a".to_owned(), | |
| 185 | 추가: incoming_size: 3, | |
| 186 | 추가: existing_size: 4, | |
| 187 | 추가: }); | |
| 188 | 추가: required[48] = 0xff; | |
| 189 | 추가: assert!(Reader::new(required.as_slice()).read().is_err()); | |
| 190 | 추가: let mut resolved = encoded(&Message::ConflictResolved { | |
| 191 | 추가: entry_id: 1, | |
| 192 | 추가: relative_name: "a".to_owned(), | |
| 193 | 추가: choice: ConflictChoice::Rename, | |
| 194 | 추가: }); | |
| 195 | 추가: *resolved.last_mut().unwrap() = 3; | |
| 196 | 추가: assert!(Reader::new(resolved.as_slice()).read().is_err()); | |
| 197 | 추가: let mut unknown = reply; | |
| 198 | 추가: unknown[6..8].copy_from_slice(&110u16.to_le_bytes()); | |
| 199 | 추가: assert!(Reader::new(unknown.as_slice()).read().is_err()); | |
| 200 | 추가: } | |
| 201 | 추가: | |
| 202 | 추가: #[test] | |
| 203 | 추가: fn conflict_frames_reject_truncation_and_trailing_fields() { | |
| 204 | 추가: for message in [ | |
| 205 | 추가: Message::StartInteractive(sample_start()), | |
| 206 | 추가: Message::ConflictReply { | |
| 207 | 추가: challenge_id: 1, | |
| 208 | 추가: choice: ConflictChoice::Overwrite, | |
| 209 | 추가: apply_to_remaining: true, | |
| 210 | 추가: }, | |
| 211 | 추가: Message::ConflictRequired { | |
| 212 | 추가: challenge_id: 1, | |
| 213 | 추가: entry_id: 2, | |
| 214 | 추가: relative_name: "a".to_owned(), | |
| 215 | 추가: incoming_size: 3, | |
| 216 | 추가: existing_size: 4, | |
| 217 | 추가: }, | |
| 218 | 추가: Message::ConflictResolved { | |
| 219 | 추가: entry_id: 2, | |
| 220 | 추가: relative_name: "a".to_owned(), | |
| 221 | 추가: choice: ConflictChoice::Skip, | |
| 222 | 추가: }, | |
| 223 | 추가: ] { | |
| 224 | 추가: let frame = encoded(&message); | |
| 225 | 추가: for length in 1..frame.len() { | |
| 226 | 추가: assert!(Reader::new(&frame[..length]).read().is_err()); | |
| 227 | 추가: } | |
| 228 | 추가: let mut trailing = frame; | |
| 229 | 추가: trailing.push(0); | |
| 230 | 추가: let length = (trailing.len() - 32) as u32; | |
| 231 | 추가: trailing[8..12].copy_from_slice(&length.to_le_bytes()); | |
| 232 | 추가: assert!(Reader::new(trailing.as_slice()).read().is_err()); | |
| 233 | 추가: } | |
| 234 | 추가: } |
| @@ -1609,3 +1609,5 @@ fn disk_full_error_tag_preserves_previous_tags_and_rejects_unknown() { | ||
| 1609 | 1609 | mod folder_inputs; |
| 1610 | 1610 | |
| 1611 | 1611 | mod zip_names; |
| 1612 | 추가: | |
| 1613 | 추가: mod conflict_wire; |