main을 병합하고 7z와 암호 ZIP 검증을 보존함
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
8614f8431a6d7f1967822c233a812d383e574000
변경된 파일 40개
+1,941-42변경 내용이 커서 일부 파일의 Diff를 생략했어요. 생략한 파일은 파일 보기나 Raw로 확인할 수 있어요.
| @@ -2,6 +2,18 @@ | ||
| 2 | 2 | # It is not intended for manual editing. |
| 3 | 3 | version = 4 |
| 4 | 4 | |
| 5 | 추가: [[package]] | |
| 6 | 추가: name = "aes" | |
| 7 | 추가: version = "0.8.4" | |
| 8 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | 추가: checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" | |
| 10 | 추가: dependencies = [ | |
| 11 | 추가: "cfg-if", | |
| 12 | 추가: "cipher", | |
| 13 | 추가: "cpufeatures", | |
| 14 | 추가: "zeroize", | |
| 15 | 추가: ] | |
| 16 | 추가: | |
| 5 | 17 | [[package]] |
| 6 | 18 | name = "block-buffer" |
| 7 | 19 | version = "0.10.4" |
| @@ -17,6 +29,16 @@ version = "1.0.5" | ||
| 17 | 29 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 18 | 30 | checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" |
| 19 | 31 | |
| 32 | 추가: [[package]] | |
| 33 | 추가: name = "cipher" | |
| 34 | 추가: version = "0.4.4" | |
| 35 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 36 | 추가: checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" | |
| 37 | 추가: dependencies = [ | |
| 38 | 추가: "crypto-common", | |
| 39 | 추가: "inout", | |
| 40 | 추가: ] | |
| 41 | 추가: | |
| 20 | 42 | [[package]] |
| 21 | 43 | name = "cpufeatures" |
| 22 | 44 | version = "0.2.17" |
| @@ -44,6 +66,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | ||
| 44 | 66 | dependencies = [ |
| 45 | 67 | "block-buffer", |
| 46 | 68 | "crypto-common", |
| 69 | 추가: "subtle", | |
| 47 | 70 | ] |
| 48 | 71 | |
| 49 | 72 | [[package]] |
| @@ -56,12 +79,51 @@ dependencies = [ | ||
| 56 | 79 | "version_check", |
| 57 | 80 | ] |
| 58 | 81 | |
| 82 | 추가: [[package]] | |
| 83 | 추가: name = "hmac" | |
| 84 | 추가: version = "0.12.1" | |
| 85 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 86 | 추가: checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" | |
| 87 | 추가: dependencies = [ | |
| 88 | 추가: "digest", | |
| 89 | 추가: ] | |
| 90 | 추가: | |
| 91 | 추가: [[package]] | |
| 92 | 추가: name = "inout" | |
| 93 | 추가: version = "0.1.4" | |
| 94 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 95 | 추가: checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" | |
| 96 | 추가: dependencies = [ | |
| 97 | 추가: "generic-array", | |
| 98 | 추가: ] | |
| 99 | 추가: | |
| 59 | 100 | [[package]] |
| 60 | 101 | name = "libc" |
| 61 | 102 | version = "0.2.191" |
| 62 | 103 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 63 | 104 | checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" |
| 64 | 105 | |
| 106 | 추가: [[package]] | |
| 107 | 추가: name = "pbkdf2" | |
| 108 | 추가: version = "0.12.2" | |
| 109 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 110 | 추가: checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" | |
| 111 | 추가: dependencies = [ | |
| 112 | 추가: "digest", | |
| 113 | 추가: "hmac", | |
| 114 | 추가: ] | |
| 115 | 추가: | |
| 116 | 추가: [[package]] | |
| 117 | 추가: name = "sha1" | |
| 118 | 추가: version = "0.10.7" | |
| 119 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 120 | 추가: checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" | |
| 121 | 추가: dependencies = [ | |
| 122 | 추가: "cfg-if", | |
| 123 | 추가: "cpufeatures", | |
| 124 | 추가: "digest", | |
| 125 | 추가: ] | |
| 126 | 추가: | |
| 65 | 127 | [[package]] |
| 66 | 128 | name = "sha2" |
| 67 | 129 | version = "0.10.9" |
| @@ -73,6 +135,12 @@ dependencies = [ | ||
| 73 | 135 | "digest", |
| 74 | 136 | ] |
| 75 | 137 | |
| 138 | 추가: [[package]] | |
| 139 | 추가: name = "subtle" | |
| 140 | 추가: version = "2.6.1" | |
| 141 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 142 | 추가: checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" | |
| 143 | 추가: | |
| 76 | 144 | [[package]] |
| 77 | 145 | name = "typenum" |
| 78 | 146 | version = "1.20.1" |
| @@ -85,11 +153,23 @@ version = "0.9.5" | ||
| 85 | 153 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 86 | 154 | checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" |
| 87 | 155 | |
| 156 | 추가: [[package]] | |
| 157 | 추가: name = "zeroize" | |
| 158 | 추가: version = "1.9.1" | |
| 159 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 160 | 추가: checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" | |
| 161 | 추가: | |
| 88 | 162 | [[package]] |
| 89 | 163 | name = "zipelo-archive-worker" |
| 90 | 164 | version = "0.1.0" |
| 91 | 165 | dependencies = [ |
| 166 | 추가: "aes", | |
| 167 | 추가: "hmac", | |
| 168 | 추가: "pbkdf2", | |
| 169 | 추가: "sha1", | |
| 92 | 170 | "sha2", |
| 171 | 추가: "subtle", | |
| 172 | 추가: "zeroize", | |
| 93 | 173 | "zlib-rs", |
| 94 | 174 | ] |
| 95 | 175 |
| @@ -7,6 +7,12 @@ publish = false | ||
| 7 | 7 | autotests = false |
| 8 | 8 | |
| 9 | 9 | [dependencies] |
| 10 | 추가: aes = { version = "=0.8.4", features = ["zeroize"] } | |
| 11 | 추가: hmac = "=0.12.1" | |
| 12 | 추가: pbkdf2 = { version = "=0.12.2", default-features = false, features = ["hmac"] } | |
| 13 | 추가: sha1 = "=0.10.7" | |
| 14 | 추가: subtle = "=2.6.1" | |
| 15 | 추가: zeroize = "=1.9.1" | |
| 10 | 16 | sha2 = "=0.10.9" |
| 11 | 17 | zlib-rs = { version = "=0.6.8", default-features = false, features = ["rust-allocator"] } |
| 12 | 18 |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | # Rust archive worker |
| 2 | 2 | |
| 3 | 삭제: 별도 프로세스의 stdin/stdout으로 revision 2 요청을 처리합니다. 제품 앱 연결과 OS sandbox를 제공하는 단계는 아닙니다. 암호 기능은 capability=false이며 암호 ZIP 해제 및 AES 생성 요청은 UnsupportedFeature로 종료합니다. | |
| 3 | 추가: 별도 프로세스의 stdin/stdout으로 revision 2 요청을 처리합니다. 제품 앱 연결과 OS sandbox를 제공하는 단계는 아닙니다. 암호 기능은 capability=true이며 ZipCrypto 해제, WinZip AES-256 AE-1/AE-2 해제와 AE-2 생성을 지원합니다. | |
| 4 | 4 | |
| 5 | 5 | - ZIP32 Store/Deflate 목록, 해제, 생성, 기본 TAR/USTAR, GZ, TAR.GZ, 비암호화 7z 해제를 지원합니다. GZ 연결 멤버는 하나의 논리 스트림으로 합칩니다. ZIP64, 다중 볼륨, 비 UTF-8 ZIP 이름, PAX/GNU 확장과 특수 항목 해제는 미지원입니다. |
| 6 | 6 | - 입력은 최대 64 MiB, 해독/생성 출력은 최대 128 MiB, 항목은 최대 10,000개입니다. 요청 limits는 이 값을 낮출 수 있습니다. 입력과 검증 완료 payload를 메모리에 보관해 모든 선택 출력의 CRC, 크기와 경로를 쓰기 전에 검사합니다. checkpoint마다 취소와 300초 한도를 확인합니다. |
| @@ -22,15 +22,25 @@ | ||
| 22 | 22 | - 합성 표본은 Python 표준 lzma로 생성합니다. 별도로 시스템 libarchive가 만든 LZMA1/LZMA2 표본을 해제하고, 합성 표본도 libarchive 읽기 API로 검사합니다. libarchive는 Linux 시험의 독립 참조 도구이며 제품 의존성이 아닙니다. 시험 도구와 표본은 tests/rust-archive-worker 아래에 있습니다. |
| 23 | 23 | - 히나타 님과 합의한 확장은 Format::SevenZip=4뿐입니다. 기존 값 0~3과 필드, 메시지 tag, 프레임 version은 유지합니다. 구버전 앱은 값 4를 거부하므로 앱 Format과 양방향 변환도 갱신해야 합니다. 이 백엔드 변경은 frontend 코드를 수정하지 않습니다. |
| 24 | 24 | |
| 25 | 추가: ## 암호 ZIP | |
| 26 | 추가: | |
| 27 | 추가: - AES는 [WinZip AE-1/AE-2 명세](https://www.winzip.com/en/support/aes-encryption/)의 method 99, 0x9901 추가 필드, PBKDF2-HMAC-SHA1 1000회, 16바이트 salt, AES-256 CTR와 HMAC-SHA1-80 형식을 사용합니다. 새 파일은 CRC를 노출하지 않는 AE-2입니다. AE-1은 인증과 CRC를 모두 검증합니다. AES-128/192와 PKWARE Strong Encryption은 미지원입니다. | |
| 28 | 추가: - AES 인증값을 상수 시간 비교로 확인한 뒤 복호화/압축 해제합니다. 모든 파일의 인증, CRC, 크기와 경로 검증이 끝나기 전에는 출력하지 않습니다. ZIP 파일명과 목록 메타데이터는 암호화되거나 인증되지 않으며, 목록 성공은 파일 내용 인증 성공을 의미하지 않습니다. | |
| 29 | 추가: - [ZipCrypto](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)는 기존 파일 해제만 지원합니다. 보안성이 약하며 암호학적 인증이 없습니다. 12바이트 헤더 검사 후 압축 스트림, 크기와 CRC를 확인합니다. 새 암호 ZIP은 AES-256만 생성합니다. | |
| 30 | 추가: - 목록은 암호 없이 표시합니다. 해제 시 한 번 입력한 암호를 ZIP 전체에 적용하며 WrongPassword일 때 새 challenge_id로 최대 3회 요청합니다. 항목마다 다른 암호인 ZIP은 지원하지 않습니다. 헤더 확인값이 우연히 일치한 잘못된 암호는 Integrity로 끝날 수 있습니다. 인증 실패 후에는 다시 요청하거나 쓰지 않습니다. | |
| 31 | 추가: - 생성은 PasswordPurpose::Encrypt로 한 번 요청하며 빈 암호는 거부합니다. 암호는 최대 1024 UTF-8 바이트입니다. 대기 중 Cancel도 처리하고, 답변 없이 입력 EOF가 오면 Protocol로 종료합니다. 기존 300초 작업 제한에 암호 입력 대기 시간도 포함됩니다. | |
| 32 | 추가: - salt는 Linux /dev/urandom 또는 Windows BCryptGenRandom에서 얻으며 실패 시 생성을 중단합니다. 암호, 파생 키와 임시 복호화 버퍼는 zeroize로 정리하고 AES 키 일정의 zeroize 기능을 켭니다. HMAC 내부 상태, OS 메모리 복사본과 전체 평문 메모리의 완전 소거를 보장하지 않습니다. | |
| 33 | 추가: - Python hashlib/hmac과 OpenSSL로 만든 AES 표본 4개, Info-ZIP으로 만든 ZipCrypto 표본 2개를 tests/ 아래에 보관합니다. 생성한 AES ZIP도 Linux에서 독립 Python/OpenSSL 검증기로 확인합니다. OpenSSL/Info-ZIP은 시험 도구이며 제품 의존성이 아닙니다. | |
| 34 | 추가: | |
| 25 | 35 | ## 공유 codec |
| 26 | 36 | |
| 27 | 삭제: `protocol.rs`는 요청과 이벤트 타입, `wire.rs`는 의존성 없는 LE codec입니다. 앱은 이 라이브러리의 타입과 Reader/Writer를 사용할 수 있습니다. `contract.json`은 합의한 revision 2 원문입니다. | |
| 37 | 추가: `protocol.rs`는 요청과 이벤트 타입, `wire.rs`는 LE codec이며 비밀 값이 담긴 프레임 버퍼는 zeroize로 정리합니다. 앱은 이 라이브러리의 타입과 Reader/Writer를 사용할 수 있습니다. `contract.json`은 합의한 revision 2 원문입니다. | |
| 28 | 38 | |
| 29 | 39 | 헤더는 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를 거부합니다. |
| 30 | 40 | |
| 31 | 41 | - kind: Start=1, Password=2, Cancel=3, Accepted=100, Entry=101, ListEnd=102, PasswordRequired=103, Progress=104, Output=105, Terminal=106, CancelAck=107입니다. |
| 32 | 42 | - 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)입니다. |
| 33 | 삭제: - Password의 비밀 값은 Debug에 노출되지 않습니다. 이 버전은 PasswordRequired를 보내지 않으므로 들어온 Password는 Protocol 오류입니다. 비밀 값은 로그나 파일에 저장하지 않습니다. | |
| 43 | 추가: - Password의 비밀 값은 Debug에 노출되지 않습니다. 암호 작업은 PasswordRequired의 challenge_id와 일치하는 Password를 한 번 받습니다. 오래된 ID, 중복 또는 요청 전 암호는 Protocol 오류입니다. 비밀 값은 로그나 파일에 저장하지 않습니다. | |
| 34 | 44 | - CancelAck.request_sequence는 요청 헤더 sequence입니다. Requested, AlreadyRequested, TooLate, Finished는 최종 결과와 별개입니다. 종료와 경합한 요청은 읽히지 않아 응답이 없을 수 있습니다. Terminal은 마지막 프레임이며 Failed/Cancelled도 정상 전달 뒤 프로세스 exit=0입니다. 앱은 Terminal과 stdout/stderr EOF, child wait를 모두 확인해야 합니다. |
| 35 | 45 | |
| 36 | 46 | ## 검증과 의존성 |
| @@ -38,3 +48,5 @@ | ||
| 38 | 48 | 시험은 `tests/rust-archive-worker`에 있습니다. Python 표준 라이브러리로 만든 ZIP/TAR/GZ fixture와 실제 자식 프로세스를 사용합니다. 전체 검증 명령은 저장소 루트의 `python3 tests/ci/run_rust.py local`입니다. Windows 교차 빌드는 실제 Windows 실행 검증을 대신하지 않습니다. |
| 39 | 49 | |
| 40 | 50 | 직접 의존성은 기존 zlib-rs=0.6.8와 허용된 RustCrypto sha2=0.10.9입니다. 2026-11-11에 확인한 [zlib-rs RUSTSEC-2024-0401](https://rustsec.org/advisories/RUSTSEC-2024-0401.html)은 >=0.4.0, [sha2 RUSTSEC-2021-0100](https://rustsec.org/advisories/RUSTSEC-2021-0100.html)은 >=0.9.8을 수정 버전으로 명시합니다. 선택 버전은 이 수정 범위에 들어갑니다. 이는 전체 전이 의존성의 취약점 부재나 완전한 보안 감사를 의미하지 않습니다. |
| 51 | 추가: | |
| 52 | 추가: 암호 구현에 RustCrypto aes=0.8.4(zeroize 기능), hmac=0.12.1, pbkdf2=0.12.2, sha1=0.10.7, zeroize=1.9.1과 상수 시간 비교용 subtle=2.6.1을 추가했습니다. SHA-1은 ZIP 호환용 HMAC/KDF에만 사용합니다. 고정 버전과 전이 의존성은 Cargo.lock에 있습니다. 로컬 RustSec DB(1645308, 2026-10-23)의 해당 패키지 기록과 공개 RustSec 검색을 확인했지만 cargo-audit 명령이 없어 최신 DB 전체 자동 감사는 수행하지 못했습니다. 이 확인은 취약점 부재나 전체 보안 감사의 증거가 아닙니다. |
| @@ -314,10 +314,45 @@ fn tar( | ||
| 314 | 314 | validate_members(&members)?; |
| 315 | 315 | Ok(members) |
| 316 | 316 | } |
| 317 | 추가: #[derive(Clone, Copy, PartialEq, Eq)] | |
| 318 | 추가: struct AesExtra { | |
| 319 | 추가: version: u16, | |
| 320 | 추가: method: u16, | |
| 321 | 추가: } | |
| 322 | 추가: fn aes_extra(extra: &[u8]) -> Result<Option<AesExtra>> { | |
| 323 | 추가: let mut at = 0; | |
| 324 | 추가: let mut found = None; | |
| 325 | 추가: while at < extra.len() { | |
| 326 | 추가: let tag = u16at(extra, at)?; | |
| 327 | 추가: let len = u16at(extra, at + 2)? as usize; | |
| 328 | 추가: let value = part(extra, at + 4, len)?; | |
| 329 | 추가: if tag == 1 { | |
| 330 | 추가: return Err(ErrorCode::UnsupportedFeature); | |
| 331 | 추가: } | |
| 332 | 추가: if tag == 0x9901 { | |
| 333 | 추가: if found.is_some() || len < 7 { | |
| 334 | 추가: return Err(ErrorCode::Integrity); | |
| 335 | 추가: } | |
| 336 | 추가: let version = u16at(value, 0)?; | |
| 337 | 추가: let method = u16at(value, 5)?; | |
| 338 | 추가: if !matches!(version, 1 | 2) | |
| 339 | 추가: || &value[2..4] != b"AE" | |
| 340 | 추가: || value[4] != 3 | |
| 341 | 추가: || !matches!(method, 0 | 8) | |
| 342 | 추가: { | |
| 343 | 추가: return Err(ErrorCode::UnsupportedFeature); | |
| 344 | 추가: } | |
| 345 | 추가: found = Some(AesExtra { version, method }); | |
| 346 | 추가: } | |
| 347 | 추가: at += 4 + len; | |
| 348 | 추가: } | |
| 349 | 추가: Ok(found) | |
| 350 | 추가: } | |
| 317 | 351 | fn zip( |
| 318 | 352 | input: &[u8], |
| 319 | 353 | limits: Limits, |
| 320 | 354 | decode: bool, |
| 355 | 추가: password: Option<&[u8]>, | |
| 321 | 356 | check: &mut impl FnMut() -> Result<()>, |
| 322 | 357 | ) -> Result<Vec<Member>> { |
| 323 | 358 | if input.len() < 22 { |
| @@ -363,7 +398,7 @@ fn zip( | ||
| 363 | 398 | } |
| 364 | 399 | let flags = u16at(h, 8)?; |
| 365 | 400 | let method = u16at(h, 10)?; |
| 366 | 삭제: if flags & !0x080f != 0 || !matches!(method, 0 | 8) || u16at(h, 34)? != 0 { | |
| 401 | 추가: if flags & !0x080f != 0 || !matches!(method, 0 | 8 | 99) || u16at(h, 34)? != 0 { | |
| 367 | 402 | return Err(ErrorCode::UnsupportedFeature); |
| 368 | 403 | } |
| 369 | 404 | let crc = u32at(h, 16)?; |
| @@ -379,6 +414,14 @@ fn zip( | ||
| 379 | 414 | let name_len = u16at(h, 28)? as usize; |
| 380 | 415 | let extra_len = u16at(h, 30)? as usize; |
| 381 | 416 | let comment_len = u16at(h, 32)? as usize; |
| 417 | 추가: let extra = aes_extra(part(input, at + 46 + name_len, extra_len)?)?; | |
| 418 | 추가: let encrypted = flags & 1 != 0; | |
| 419 | 추가: if (method == 99) != extra.is_some() || (method == 99 && !encrypted) { | |
| 420 | 추가: return Err(ErrorCode::Integrity); | |
| 421 | 추가: } | |
| 422 | 추가: if extra.is_some_and(|e| e.version == 2) && crc != 0 { | |
| 423 | 추가: return Err(ErrorCode::Integrity); | |
| 424 | 추가: } | |
| 382 | 425 | let raw = part(input, at + 46, name_len)?; |
| 383 | 426 | if flags & 0x0800 == 0 && !raw.is_ascii() { |
| 384 | 427 | return Err(ErrorCode::UnsupportedFeature); |
| @@ -406,7 +449,10 @@ fn zip( | ||
| 406 | 449 | } |
| 407 | 450 | let ln = u16at(lh, 26)? as usize; |
| 408 | 451 | let le = u16at(lh, 28)? as usize; |
| 409 | 삭제: if part(input, local + 30, ln)? != raw { | |
| 452 | 추가: if aes_extra(part(input, local + 30 + ln, le)?)? != extra | |
| 453 | 추가: || u16at(lh, 10)? != u16at(h, 12)? | |
| 454 | 추가: || part(input, local + 30, ln)? != raw | |
| 455 | 추가: { | |
| 410 | 456 | return Err(ErrorCode::Integrity); |
| 411 | 457 | } |
| 412 | 458 | if flags & 8 == 0 |
| @@ -437,21 +483,43 @@ fn zip( | ||
| 437 | 483 | return Err(ErrorCode::Integrity); |
| 438 | 484 | } |
| 439 | 485 | spans.push((local, stop)); |
| 440 | 삭제: let encrypted = flags & 1 != 0; | |
| 441 | 삭제: let data = if decode && !encrypted { | |
| 442 | 삭제: let bytes = if method == 0 { | |
| 443 | 삭제: if compressed != size { | |
| 486 | 추가: if encrypted && compressed < if extra.is_some() { 28 } else { 12 } { | |
| 487 | 추가: return Err(ErrorCode::Integrity); | |
| 488 | 추가: } | |
| 489 | 추가: let data = if decode { | |
| 490 | 추가: let decrypted; | |
| 491 | 추가: let packed = if encrypted { | |
| 492 | 추가: let password = password.ok_or(ErrorCode::WrongPassword)?; | |
| 493 | 추가: decrypted = if extra.is_some() { | |
| 494 | 추가: crate::crypto::aes_decrypt(packed, password, check)? | |
| 495 | 추가: } else { | |
| 496 | 추가: let verifier = if flags & 8 != 0 { | |
| 497 | 추가: (u16at(h, 12)? >> 8) as u8 | |
| 498 | 추가: } else { | |
| 499 | 추가: (crc >> 24) as u8 | |
| 500 | 추가: }; | |
| 501 | 추가: crate::crypto::zipcrypto_decrypt(packed, password, verifier, check)? | |
| 502 | 추가: }; | |
| 503 | 추가: decrypted.as_slice() | |
| 504 | 추가: } else { | |
| 505 | 추가: packed | |
| 506 | 추가: }; | |
| 507 | 추가: let actual_method = extra.map_or(method, |e| e.method); | |
| 508 | 추가: let bytes = if actual_method == 0 { | |
| 509 | 추가: if packed.len() != size { | |
| 444 | 510 | return Err(ErrorCode::Integrity); |
| 445 | 511 | } |
| 446 | 512 | packed.to_vec() |
| 447 | 513 | } else { |
| 448 | 514 | let (out, used) = inflate(packed, false, size as u64, check)?; |
| 449 | 삭제: if used != compressed { | |
| 515 | 추가: if used != packed.len() { | |
| 450 | 516 | return Err(ErrorCode::Integrity); |
| 451 | 517 | } |
| 452 | 518 | out |
| 453 | 519 | }; |
| 454 | 삭제: if bytes.len() != size || crc32(0, &bytes) != crc { | |
| 520 | 추가: if bytes.len() != size | |
| 521 | 추가: || (extra.is_none_or(|e| e.version == 1) && crc32(0, &bytes) != crc) | |
| 522 | 추가: { | |
| 455 | 523 | return Err(ErrorCode::Integrity); |
| 456 | 524 | } |
| 457 | 525 | bytes |
| @@ -498,6 +566,15 @@ pub fn parse( | ||
| 498 | 566 | limits: Limits, |
| 499 | 567 | decode: bool, |
| 500 | 568 | check: &mut impl FnMut() -> Result<()>, |
| 569 | 추가: ) -> Result<Catalog> { | |
| 570 | 추가: parse_with_password(input, limits, decode, None, check) | |
| 571 | 추가: } | |
| 572 | 추가: pub fn parse_with_password( | |
| 573 | 추가: input: &[u8], | |
| 574 | 추가: limits: Limits, | |
| 575 | 추가: decode: bool, | |
| 576 | 추가: password: Option<&[u8]>, | |
| 577 | 추가: check: &mut impl FnMut() -> Result<()>, | |
| 501 | 578 | ) -> Result<Catalog> { |
| 502 | 579 | if !limits.valid() || input.len() as u64 > limits.input { |
| 503 | 580 | return Err(ErrorCode::Limit); |
| @@ -511,7 +588,7 @@ pub fn parse( | ||
| 511 | 588 | if input.starts_with(b"PK\x03\x04") || input.starts_with(b"PK\x05\x06") { |
| 512 | 589 | return Ok(Catalog { |
| 513 | 590 | format: Format::Zip, |
| 514 | 삭제: members: zip(input, limits, decode, check)?, | |
| 591 | 추가: members: zip(input, limits, decode, password, check)?, | |
| 515 | 592 | }); |
| 516 | 593 | } |
| 517 | 594 | if input.starts_with(&[31, 139]) { |
| @@ -581,6 +658,15 @@ pub fn create_zip( | ||
| 581 | 658 | method: Method, |
| 582 | 659 | limits: Limits, |
| 583 | 660 | check: &mut impl FnMut() -> Result<()>, |
| 661 | 추가: ) -> Result<Vec<u8>> { | |
| 662 | 추가: create_zip_with_password(members, method, limits, None, check) | |
| 663 | 추가: } | |
| 664 | 추가: pub fn create_zip_with_password( | |
| 665 | 추가: members: &[Member], | |
| 666 | 추가: method: Method, | |
| 667 | 추가: limits: Limits, | |
| 668 | 추가: password: Option<&[u8]>, | |
| 669 | 추가: check: &mut impl FnMut() -> Result<()>, | |
| 584 | 670 | ) -> Result<Vec<u8>> { |
| 585 | 671 | if members.len() > limits.entries as usize || members.len() >= 65535 { |
| 586 | 672 | return Err(ErrorCode::Limit); |
| @@ -599,7 +685,11 @@ pub fn create_zip( | ||
| 599 | 685 | return Err(ErrorCode::UnsupportedFeature); |
| 600 | 686 | } |
| 601 | 687 | let name = m.entry.name.as_bytes(); |
| 602 | 삭제: let crc = crc32(0, &m.data); | |
| 688 | 추가: let crc = if password.is_some() { | |
| 689 | 추가: 0 | |
| 690 | 추가: } else { | |
| 691 | 추가: crc32(0, &m.data) | |
| 692 | 추가: }; | |
| 603 | 693 | let offset = out.len() as u32; |
| 604 | 694 | let packed = match method { |
| 605 | 695 | Method::Store => m.data.clone(), |
| @@ -609,9 +699,23 @@ pub fn create_zip( | ||
| 609 | 699 | Method::Store => 0, |
| 610 | 700 | Method::Deflate => 8, |
| 611 | 701 | }; |
| 702 | 추가: let mut extra = Vec::new(); | |
| 703 | 추가: let flags = if password.is_some() { 0x0801 } else { 0x0800 }; | |
| 704 | 추가: let version = if password.is_some() { 51 } else { 20 }; | |
| 705 | 추가: let (method, packed) = if let Some(password) = password { | |
| 706 | 추가: put16(&mut extra, 0x9901); | |
| 707 | 추가: put16(&mut extra, 7); | |
| 708 | 추가: put16(&mut extra, 2); | |
| 709 | 추가: extra.extend(b"AE"); | |
| 710 | 추가: extra.push(3); | |
| 711 | 추가: put16(&mut extra, method); | |
| 712 | 추가: (99, crate::crypto::aes_encrypt(&packed, password, check)?) | |
| 713 | 추가: } else { | |
| 714 | 추가: (method, packed) | |
| 715 | 추가: }; | |
| 612 | 716 | out.extend(b"PK\x03\x04"); |
| 613 | 삭제: put16(&mut out, 20); | |
| 614 | 삭제: put16(&mut out, 0x0800); | |
| 717 | 추가: put16(&mut out, version); | |
| 718 | 추가: put16(&mut out, flags); | |
| 615 | 719 | put16(&mut out, method); |
| 616 | 720 | put16(&mut out, 0); |
| 617 | 721 | put16(&mut out, 33); |
| @@ -619,13 +723,14 @@ pub fn create_zip( | ||
| 619 | 723 | put32(&mut out, packed.len() as u32); |
| 620 | 724 | put32(&mut out, m.data.len() as u32); |
| 621 | 725 | put16(&mut out, name.len() as u16); |
| 622 | 삭제: put16(&mut out, 0); | |
| 726 | 추가: put16(&mut out, extra.len() as u16); | |
| 623 | 727 | out.extend(name); |
| 728 | 추가: out.extend(&extra); | |
| 624 | 729 | bounded_append(&mut out, &packed, limits.output)?; |
| 625 | 730 | cd.extend(b"PK\x01\x02"); |
| 626 | 731 | put16(&mut cd, 0x0314); |
| 627 | 삭제: put16(&mut cd, 20); | |
| 628 | 삭제: put16(&mut cd, 0x0800); | |
| 732 | 추가: put16(&mut cd, version); | |
| 733 | 추가: put16(&mut cd, flags); | |
| 629 | 734 | put16(&mut cd, method); |
| 630 | 735 | put16(&mut cd, 0); |
| 631 | 736 | put16(&mut cd, 33); |
| @@ -633,13 +738,14 @@ pub fn create_zip( | ||
| 633 | 738 | put32(&mut cd, packed.len() as u32); |
| 634 | 739 | put32(&mut cd, m.data.len() as u32); |
| 635 | 740 | put16(&mut cd, name.len() as u16); |
| 636 | 삭제: put16(&mut cd, 0); | |
| 741 | 추가: put16(&mut cd, extra.len() as u16); | |
| 637 | 742 | put16(&mut cd, 0); |
| 638 | 743 | put16(&mut cd, 0); |
| 639 | 744 | put16(&mut cd, 0); |
| 640 | 745 | put32(&mut cd, 0o100600 << 16); |
| 641 | 746 | put32(&mut cd, offset); |
| 642 | 747 | cd.extend(name); |
| 748 | 추가: cd.extend(&extra); | |
| 643 | 749 | } |
| 644 | 750 | let offset = out.len(); |
| 645 | 751 | bounded_append(&mut out, &cd, limits.output)?; |
| @@ -0,0 +1,174 @@ | ||
| 1 | 추가: use crate::protocol::ErrorCode; | |
| 2 | 추가: use aes::{ | |
| 3 | 추가: Aes256, | |
| 4 | 추가: cipher::{BlockEncrypt, KeyInit}, | |
| 5 | 추가: }; | |
| 6 | 추가: use hmac::{Hmac, Mac}; | |
| 7 | 추가: use sha1::Sha1; | |
| 8 | 추가: use subtle::ConstantTimeEq; | |
| 9 | 추가: use zeroize::{Zeroize, Zeroizing}; | |
| 10 | 추가: | |
| 11 | 추가: type Result<T> = std::result::Result<T, ErrorCode>; | |
| 12 | 추가: type Sha1Mac = Hmac<Sha1>; | |
| 13 | 추가: | |
| 14 | 추가: fn keys(password: &[u8], salt: &[u8]) -> Zeroizing<[u8; 66]> { | |
| 15 | 추가: let mut result = Zeroizing::new([0; 66]); | |
| 16 | 추가: pbkdf2::pbkdf2_hmac::<Sha1>(password, salt, 1000, result.as_mut()); | |
| 17 | 추가: result | |
| 18 | 추가: } | |
| 19 | 추가: fn ctr(bytes: &mut [u8], key: &[u8], check: &mut impl FnMut() -> Result<()>) -> Result<()> { | |
| 20 | 추가: let cipher = Aes256::new_from_slice(key).map_err(|_| ErrorCode::Internal)?; | |
| 21 | 추가: for (index, chunk) in bytes.chunks_mut(16).enumerate() { | |
| 22 | 추가: if index % 4096 == 0 { | |
| 23 | 추가: check()?; | |
| 24 | 추가: } | |
| 25 | 추가: // WinZip은 1부터 시작하는 리틀엔디언 카운터를 사용함. | |
| 26 | 추가: let mut block = ((index as u128) + 1).to_le_bytes().into(); | |
| 27 | 추가: cipher.encrypt_block(&mut block); | |
| 28 | 추가: for (byte, mask) in chunk.iter_mut().zip(block.iter()) { | |
| 29 | 추가: *byte ^= mask; | |
| 30 | 추가: } | |
| 31 | 추가: block.as_mut_slice().zeroize(); | |
| 32 | 추가: } | |
| 33 | 추가: Ok(()) | |
| 34 | 추가: } | |
| 35 | 추가: fn authenticate( | |
| 36 | 추가: key: &[u8], | |
| 37 | 추가: bytes: &[u8], | |
| 38 | 추가: check: &mut impl FnMut() -> Result<()>, | |
| 39 | 추가: ) -> Result<Sha1Mac> { | |
| 40 | 추가: let mut mac = <Sha1Mac as Mac>::new_from_slice(key).map_err(|_| ErrorCode::Internal)?; | |
| 41 | 추가: for chunk in bytes.chunks(65536) { | |
| 42 | 추가: check()?; | |
| 43 | 추가: mac.update(chunk); | |
| 44 | 추가: } | |
| 45 | 추가: Ok(mac) | |
| 46 | 추가: } | |
| 47 | 추가: pub(crate) fn aes_decrypt( | |
| 48 | 추가: packed: &[u8], | |
| 49 | 추가: password: &[u8], | |
| 50 | 추가: check: &mut impl FnMut() -> Result<()>, | |
| 51 | 추가: ) -> Result<Zeroizing<Vec<u8>>> { | |
| 52 | 추가: if packed.len() < 28 { | |
| 53 | 추가: return Err(ErrorCode::Integrity); | |
| 54 | 추가: } | |
| 55 | 추가: check()?; | |
| 56 | 추가: let key = keys(password, &packed[..16]); | |
| 57 | 추가: if !bool::from(key[64..].ct_eq(&packed[16..18])) { | |
| 58 | 추가: return Err(ErrorCode::WrongPassword); | |
| 59 | 추가: } | |
| 60 | 추가: let end = packed.len() - 10; | |
| 61 | 추가: // 인증이 성공하기 전에는 복호화나 압축 해제를 시작하지 않음. | |
| 62 | 추가: authenticate(&key[32..64], &packed[18..end], check)? | |
| 63 | 추가: .verify_truncated_left(&packed[end..]) | |
| 64 | 추가: .map_err(|_| ErrorCode::Integrity)?; | |
| 65 | 추가: let mut bytes = Zeroizing::new(packed[18..end].to_vec()); | |
| 66 | 추가: ctr(&mut bytes, &key[..32], check)?; | |
| 67 | 추가: Ok(bytes) | |
| 68 | 추가: } | |
| 69 | 추가: pub(crate) fn aes_encrypt( | |
| 70 | 추가: packed: &[u8], | |
| 71 | 추가: password: &[u8], | |
| 72 | 추가: check: &mut impl FnMut() -> Result<()>, | |
| 73 | 추가: ) -> Result<Vec<u8>> { | |
| 74 | 추가: check()?; | |
| 75 | 추가: let mut salt = [0; 16]; | |
| 76 | 추가: random(&mut salt)?; | |
| 77 | 추가: let key = keys(password, &salt); | |
| 78 | 추가: let mut bytes = packed.to_vec(); | |
| 79 | 추가: ctr(&mut bytes, &key[..32], check)?; | |
| 80 | 추가: let mac = authenticate(&key[32..64], &bytes, check)? | |
| 81 | 추가: .finalize() | |
| 82 | 추가: .into_bytes(); | |
| 83 | 추가: let mut result = Vec::with_capacity(bytes.len() + 28); | |
| 84 | 추가: result.extend(salt); | |
| 85 | 추가: result.extend(&key[64..]); | |
| 86 | 추가: result.extend(bytes); | |
| 87 | 추가: result.extend(&mac[..10]); | |
| 88 | 추가: Ok(result) | |
| 89 | 추가: } | |
| 90 | 추가: fn random(bytes: &mut [u8]) -> Result<()> { | |
| 91 | 추가: #[cfg(target_os = "linux")] | |
| 92 | 추가: { | |
| 93 | 추가: use std::io::Read; | |
| 94 | 추가: std::fs::File::open("/dev/urandom") | |
| 95 | 추가: .and_then(|mut file| file.read_exact(bytes)) | |
| 96 | 추가: .map_err(|_| ErrorCode::Io) | |
| 97 | 추가: } | |
| 98 | 추가: #[cfg(windows)] | |
| 99 | 추가: { | |
| 100 | 추가: #[link(name = "bcrypt")] | |
| 101 | 추가: unsafe extern "system" { | |
| 102 | 추가: fn BCryptGenRandom( | |
| 103 | 추가: algorithm: *mut core::ffi::c_void, | |
| 104 | 추가: buffer: *mut u8, | |
| 105 | 추가: length: u32, | |
| 106 | 추가: flags: u32, | |
| 107 | 추가: ) -> i32; | |
| 108 | 추가: } | |
| 109 | 추가: let len = u32::try_from(bytes.len()).map_err(|_| ErrorCode::Limit)?; | |
| 110 | 추가: if unsafe { BCryptGenRandom(std::ptr::null_mut(), bytes.as_mut_ptr(), len, 2) } >= 0 { | |
| 111 | 추가: Ok(()) | |
| 112 | 추가: } else { | |
| 113 | 추가: Err(ErrorCode::Io) | |
| 114 | 추가: } | |
| 115 | 추가: } | |
| 116 | 추가: #[cfg(not(any(target_os = "linux", windows)))] | |
| 117 | 추가: { | |
| 118 | 추가: let _ = bytes; | |
| 119 | 추가: Err(ErrorCode::UnsupportedFeature) | |
| 120 | 추가: } | |
| 121 | 추가: } | |
| 122 | 추가: const CRC_TABLE: [u32; 256] = { | |
| 123 | 추가: let mut table = [0; 256]; | |
| 124 | 추가: let mut i = 0; | |
| 125 | 추가: while i < 256 { | |
| 126 | 추가: let mut crc = i as u32; | |
| 127 | 추가: let mut bit = 0; | |
| 128 | 추가: while bit < 8 { | |
| 129 | 추가: crc = (crc >> 1) ^ (0xedb88320 & 0u32.wrapping_sub(crc & 1)); | |
| 130 | 추가: bit += 1; | |
| 131 | 추가: } | |
| 132 | 추가: table[i] = crc; | |
| 133 | 추가: i += 1; | |
| 134 | 추가: } | |
| 135 | 추가: table | |
| 136 | 추가: }; | |
| 137 | 추가: pub(crate) fn zipcrypto_decrypt( | |
| 138 | 추가: packed: &[u8], | |
| 139 | 추가: password: &[u8], | |
| 140 | 추가: verifier: u8, | |
| 141 | 추가: check: &mut impl FnMut() -> Result<()>, | |
| 142 | 추가: ) -> Result<Zeroizing<Vec<u8>>> { | |
| 143 | 추가: if packed.len() < 12 { | |
| 144 | 추가: return Err(ErrorCode::Integrity); | |
| 145 | 추가: } | |
| 146 | 추가: let mut key = Zeroizing::new([0x12345678u32, 0x23456789, 0x34567890]); | |
| 147 | 추가: fn update(key: &mut [u32; 3], byte: u8) { | |
| 148 | 추가: key[0] = (key[0] >> 8) ^ CRC_TABLE[((key[0] as u8) ^ byte) as usize]; | |
| 149 | 추가: key[1] = key[1] | |
| 150 | 추가: .wrapping_add(key[0] & 255) | |
| 151 | 추가: .wrapping_mul(134775813) | |
| 152 | 추가: .wrapping_add(1); | |
| 153 | 추가: key[2] = (key[2] >> 8) ^ CRC_TABLE[((key[2] as u8) ^ ((key[1] >> 24) as u8)) as usize]; | |
| 154 | 추가: } | |
| 155 | 추가: for &byte in password { | |
| 156 | 추가: update(&mut key, byte); | |
| 157 | 추가: } | |
| 158 | 추가: let mut out = Zeroizing::new(Vec::with_capacity(packed.len() - 12)); | |
| 159 | 추가: for (index, &byte) in packed.iter().enumerate() { | |
| 160 | 추가: if index % 65536 == 0 { | |
| 161 | 추가: check()?; | |
| 162 | 추가: } | |
| 163 | 추가: let temp = key[2] | 2; | |
| 164 | 추가: let plain = byte ^ ((temp.wrapping_mul(temp ^ 1) >> 8) as u8); | |
| 165 | 추가: update(&mut key, plain); | |
| 166 | 추가: if index == 11 && plain != verifier { | |
| 167 | 추가: return Err(ErrorCode::WrongPassword); | |
| 168 | 추가: } | |
| 169 | 추가: if index >= 12 { | |
| 170 | 추가: out.push(plain); | |
| 171 | 추가: } | |
| 172 | 추가: } | |
| 173 | 추가: Ok(out) | |
| 174 | 추가: } |
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | pub mod archive; |
| 2 | 추가: mod crypto; | |
| 2 | 3 | pub mod filesystem; |
| 3 | 4 | mod lzma; |
| 4 | 5 | pub mod protocol; |
| @@ -265,7 +265,7 @@ impl std::fmt::Debug for Secret { | ||
| 265 | 265 | } |
| 266 | 266 | impl Drop for Secret { |
| 267 | 267 | fn drop(&mut self) { |
| 268 | 삭제: self.0.fill(0); | |
| 268 | 추가: zeroize::Zeroize::zeroize(&mut self.0); | |
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | #[derive(Debug)] |
| @@ -7,7 +7,7 @@ use crate::{ | ||
| 7 | 7 | use std::{ |
| 8 | 8 | collections::BTreeSet, |
| 9 | 9 | io::{Read, Write}, |
| 10 | 삭제: sync::{Arc, Mutex}, | |
| 10 | 추가: sync::{Arc, Condvar, Mutex}, | |
| 11 | 11 | time::{Duration, Instant}, |
| 12 | 12 | }; |
| 13 | 13 | |
| @@ -17,13 +17,57 @@ struct State<W> { | ||
| 17 | 17 | cancelled: bool, |
| 18 | 18 | phase: u8, |
| 19 | 19 | fault: Option<ErrorCode>, |
| 20 | 추가: challenge: Option<u64>, | |
| 21 | 추가: password: Option<Secret>, | |
| 22 | 추가: input_closed: bool, | |
| 20 | 23 | } |
| 21 | 24 | struct Job<W> { |
| 22 | 25 | state: Arc<Mutex<State<W>>>, |
| 26 | 추가: wake: Arc<Condvar>, | |
| 27 | 추가: next_challenge: u64, | |
| 23 | 28 | started: Instant, |
| 24 | 29 | terminal: Terminal, |
| 25 | 30 | } |
| 26 | 31 | impl<W: Write> Job<W> { |
| 32 | 추가: fn password(&mut self, purpose: PasswordPurpose, attempt: u32) -> Result<Secret> { | |
| 33 | 추가: self.check()?; | |
| 34 | 추가: self.next_challenge = self.next_challenge.checked_add(1).ok_or(ErrorCode::Limit)?; | |
| 35 | 추가: let id = self.next_challenge; | |
| 36 | 추가: let state_ref = Arc::clone(&self.state); | |
| 37 | 추가: let mut state = state_ref.lock().map_err(|_| ErrorCode::Internal)?; | |
| 38 | 추가: state.challenge = Some(id); | |
| 39 | 추가: state | |
| 40 | 추가: .writer | |
| 41 | 추가: .send(&Message::PasswordRequired { | |
| 42 | 추가: challenge_id: id, | |
| 43 | 추가: attempt, | |
| 44 | 추가: purpose, | |
| 45 | 추가: }) | |
| 46 | 추가: .map_err(|_| ErrorCode::Io)?; | |
| 47 | 추가: loop { | |
| 48 | 추가: if let Some(error) = state.fault { | |
| 49 | 추가: return Err(error); | |
| 50 | 추가: } | |
| 51 | 추가: if state.cancelled { | |
| 52 | 추가: return Err(ErrorCode::None); | |
| 53 | 추가: } | |
| 54 | 추가: if let Some(secret) = state.password.take() { | |
| 55 | 추가: return Ok(secret); | |
| 56 | 추가: } | |
| 57 | 추가: if state.input_closed { | |
| 58 | 추가: return Err(ErrorCode::Protocol); | |
| 59 | 추가: } | |
| 60 | 추가: if self.started.elapsed() > Duration::from_secs(300) { | |
| 61 | 추가: return Err(ErrorCode::Limit); | |
| 62 | 추가: } | |
| 63 | 추가: state = self | |
| 64 | 추가: .wake | |
| 65 | 추가: .wait_timeout(state, Duration::from_millis(50)) | |
| 66 | 추가: .map_err(|_| ErrorCode::Internal)? | |
| 67 | 추가: .0; | |
| 68 | 추가: } | |
| 69 | 추가: } | |
| 70 | 추가: | |
| 27 | 71 | fn event(&mut self, event: Message) -> Result<()> { |
| 28 | 72 | let mut state = self.state.lock().map_err(|_| ErrorCode::Internal)?; |
| 29 | 73 | state.writer.send(&event).map_err(|_| { |
| @@ -136,7 +180,7 @@ impl<W: Write> Job<W> { | ||
| 136 | 180 | } |
| 137 | 181 | self.event(Message::Accepted { |
| 138 | 182 | action: start.action.kind(), |
| 139 | 삭제: encryption: false, | |
| 183 | 추가: encryption: true, | |
| 140 | 184 | })?; |
| 141 | 185 | self.check()?; |
| 142 | 186 | match start.action { |
| @@ -172,7 +216,7 @@ impl<W: Write> Job<W> { | ||
| 172 | 216 | 0, |
| 173 | 217 | )?; |
| 174 | 218 | let mut catalog = |
| 175 | 삭제: archive::parse(&snapshot.bytes, start.limits, extract, &mut || self.check())?; | |
| 219 | 추가: archive::parse(&snapshot.bytes, start.limits, false, &mut || self.check())?; | |
| 176 | 220 | let list_id = ListId { |
| 177 | 221 | catalog_version: 1, |
| 178 | 222 | format: catalog.format, |
| @@ -218,9 +262,6 @@ impl<W: Write> Job<W> { | ||
| 218 | 262 | Some(set) |
| 219 | 263 | } |
| 220 | 264 | }; |
| 221 | 삭제: if catalog.members.iter().any(|m| m.entry.encrypted) { | |
| 222 | 삭제: return Err(ErrorCode::UnsupportedFeature); | |
| 223 | 삭제: } | |
| 224 | 265 | if catalog |
| 225 | 266 | .members |
| 226 | 267 | .iter() |
| @@ -228,6 +269,28 @@ impl<W: Write> Job<W> { | ||
| 228 | 269 | { |
| 229 | 270 | return Err(ErrorCode::UnsafePath); |
| 230 | 271 | } |
| 272 | 추가: let encrypted = catalog.members.iter().any(|m| m.entry.encrypted); | |
| 273 | 추가: for attempt in 1..=3 { | |
| 274 | 추가: let secret = if encrypted { | |
| 275 | 추가: Some(self.password(PasswordPurpose::Decrypt, attempt)?) | |
| 276 | 추가: } else { | |
| 277 | 추가: None | |
| 278 | 추가: }; | |
| 279 | 추가: match archive::parse_with_password( | |
| 280 | 추가: &snapshot.bytes, | |
| 281 | 추가: start.limits, | |
| 282 | 추가: true, | |
| 283 | 추가: secret.as_ref().map(|s| s.0.as_slice()), | |
| 284 | 추가: &mut || self.check(), | |
| 285 | 추가: ) { | |
| 286 | 추가: Ok(decoded) => { | |
| 287 | 추가: catalog = decoded; | |
| 288 | 추가: break; | |
| 289 | 추가: } | |
| 290 | 추가: Err(ErrorCode::WrongPassword) if attempt < 3 => continue, | |
| 291 | 추가: Err(error) => return Err(error), | |
| 292 | 추가: } | |
| 293 | 추가: } | |
| 231 | 294 | if catalog.format == Format::Gzip { |
| 232 | 295 | let name = gzip_output_name.ok_or(ErrorCode::InvalidRequest)?; |
| 233 | 296 | let checked = archive::valid_name(&name, false) |
| @@ -299,9 +362,6 @@ impl<W: Write> Job<W> { | ||
| 299 | 362 | method, |
| 300 | 363 | encryption, |
| 301 | 364 | } => { |
| 302 | 삭제: if encryption != Encryption::None { | |
| 303 | 삭제: return Err(ErrorCode::UnsupportedFeature); | |
| 304 | 삭제: } | |
| 305 | 365 | if sources.len() > start.limits.entries as usize { |
| 306 | 366 | return Err(ErrorCode::Limit); |
| 307 | 367 | } |
| @@ -328,8 +388,22 @@ impl<W: Write> Job<W> { | ||
| 328 | 388 | data: snapshot.bytes, |
| 329 | 389 | }); |
| 330 | 390 | } |
| 331 | 삭제: let bytes = | |
| 332 | 삭제: archive::create_zip(&members, method, start.limits, &mut || self.check())?; | |
| 391 | 추가: let secret = if encryption == Encryption::Aes256 { | |
| 392 | 추가: let secret = self.password(PasswordPurpose::Encrypt, 1)?; | |
| 393 | 추가: if secret.0.is_empty() { | |
| 394 | 추가: return Err(ErrorCode::InvalidRequest); | |
| 395 | 추가: } | |
| 396 | 추가: Some(secret) | |
| 397 | 추가: } else { | |
| 398 | 추가: None | |
| 399 | 추가: }; | |
| 400 | 추가: let bytes = archive::create_zip_with_password( | |
| 401 | 추가: &members, | |
| 402 | 추가: method, | |
| 403 | 추가: start.limits, | |
| 404 | 추가: secret.as_ref().map(|s| s.0.as_slice()), | |
| 405 | 추가: &mut || self.check(), | |
| 406 | 추가: )?; | |
| 333 | 407 | let output = output_file.to_path()?; |
| 334 | 408 | let leaf = output |
| 335 | 409 | .file_name() |
| @@ -365,18 +439,23 @@ pub fn serve<R: Read + Send + 'static, W: Write + Send + 'static>( | ||
| 365 | 439 | cancelled: false, |
| 366 | 440 | phase: 0, |
| 367 | 441 | fault: None, |
| 442 | 추가: challenge: None, | |
| 443 | 추가: password: None, | |
| 444 | 추가: input_closed: false, | |
| 368 | 445 | })); |
| 446 | 추가: let wake = Arc::new(Condvar::new()); | |
| 447 | 추가: let control_wake = Arc::clone(&wake); | |
| 369 | 448 | let control = Arc::clone(&state); |
| 370 | 449 | std::thread::spawn(move || { |
| 371 | 450 | loop { |
| 372 | 451 | let command = reader.read(); |
| 373 | 452 | let Ok(Some((_, sequence, message))) = command else { |
| 374 | 삭제: if command.is_err() { | |
| 375 | 삭제: if let Ok(mut state) = control.lock() { | |
| 376 | 삭제: if state.phase < 2 { | |
| 377 | 삭제: state.fault = Some(ErrorCode::Protocol); | |
| 378 | 삭제: } | |
| 453 | 추가: if let Ok(mut state) = control.lock() { | |
| 454 | 추가: state.input_closed = true; | |
| 455 | 추가: if command.is_err() && state.phase < 2 { | |
| 456 | 추가: state.fault = Some(ErrorCode::Protocol); | |
| 379 | 457 | } |
| 458 | 추가: control_wake.notify_all(); | |
| 380 | 459 | } |
| 381 | 460 | break; |
| 382 | 461 | }; |
| @@ -387,6 +466,23 @@ pub fn serve<R: Read + Send + 'static, W: Write + Send + 'static>( | ||
| 387 | 466 | break; |
| 388 | 467 | } |
| 389 | 468 | match message { |
| 469 | 추가: Message::Password { | |
| 470 | 추가: challenge_id, | |
| 471 | 추가: secret, | |
| 472 | 추가: } => { | |
| 473 | 추가: if state.phase != 0 | |
| 474 | 추가: || state.challenge != Some(challenge_id) | |
| 475 | 추가: || state.password.is_some() | |
| 476 | 추가: { | |
| 477 | 추가: state.fault = Some(ErrorCode::Protocol); | |
| 478 | 추가: } else { | |
| 479 | 추가: state.challenge = None; | |
| 480 | 추가: if !state.cancelled { | |
| 481 | 추가: state.password = Some(secret); | |
| 482 | 추가: } | |
| 483 | 추가: } | |
| 484 | 추가: control_wake.notify_all(); | |
| 485 | 추가: } | |
| 390 | 486 | Message::Cancel => { |
| 391 | 487 | let status = match state.phase { |
| 392 | 488 | 2 => CancelStatus::Finished, |
| @@ -397,6 +493,7 @@ pub fn serve<R: Read + Send + 'static, W: Write + Send + 'static>( | ||
| 397 | 493 | CancelStatus::Requested |
| 398 | 494 | } |
| 399 | 495 | }; |
| 496 | 추가: control_wake.notify_all(); | |
| 400 | 497 | if state |
| 401 | 498 | .writer |
| 402 | 499 | .send(&Message::CancelAck { |
| @@ -418,6 +515,8 @@ pub fn serve<R: Read + Send + 'static, W: Write + Send + 'static>( | ||
| 418 | 515 | }); |
| 419 | 516 | let mut context = Job { |
| 420 | 517 | state: Arc::clone(&state), |
| 518 | 추가: wake, | |
| 519 | 추가: next_challenge: 0, | |
| 421 | 520 | started: Instant::now(), |
| 422 | 521 | terminal: Terminal { |
| 423 | 522 | outcome: Outcome::Completed, |
| @@ -443,6 +542,8 @@ pub fn serve<R: Read + Send + 'static, W: Write + Send + 'static>( | ||
| 443 | 542 | .lock() |
| 444 | 543 | .map_err(|_| std::io::Error::other("worker state poisoned"))?; |
| 445 | 544 | state.phase = 2; |
| 545 | 추가: state.challenge = None; | |
| 546 | 추가: state.password = None; | |
| 446 | 547 | if let Some(error) = state.fault.or(error) { |
| 447 | 548 | context.terminal.error = error; |
| 448 | 549 | context.terminal.outcome = if error == ErrorCode::None { |
| @@ -495,7 +495,7 @@ impl<R: Read> Reader<R> { | ||
| 495 | 495 | } |
| 496 | 496 | self.job = Some(job); |
| 497 | 497 | self.sequence += 1; |
| 498 | 삭제: let mut b = vec![0; len]; | |
| 498 | 추가: let mut b = zeroize::Zeroizing::new(vec![0; len]); | |
| 499 | 499 | self.input.read_exact(&mut b)?; |
| 500 | 500 | let message = Message::decode(u16::from_le_bytes(h[6..8].try_into().unwrap()), &b)?; |
| 501 | 501 | self.terminal = matches!(message, Message::Terminal(_)); |
| @@ -522,6 +522,7 @@ impl<W: Write> Writer<W> { | ||
| 522 | 522 | return Err(invalid()); |
| 523 | 523 | } |
| 524 | 524 | let (kind, b) = m.encode()?; |
| 525 | 추가: let b = zeroize::Zeroizing::new(b); | |
| 525 | 526 | let mut h = Vec::with_capacity(32); |
| 526 | 527 | h.extend(b"ZAW1"); |
| 527 | 528 | h.extend(1u16.to_le_bytes()); |
| @@ -3948,6 +3948,14 @@ dependencies = [ | ||
| 3948 | 3948 | "zipelo-rust-memory-zip-create", |
| 3949 | 3949 | ] |
| 3950 | 3950 | |
| 3951 | 추가: [[package]] | |
| 3952 | 추가: name = "zipelo-archive-worker" | |
| 3953 | 추가: version = "0.1.0" | |
| 3954 | 추가: dependencies = [ | |
| 3955 | 추가: "sha2", | |
| 3956 | 추가: "zlib-rs", | |
| 3957 | 추가: ] | |
| 3958 | 추가: | |
| 3951 | 3959 | [[package]] |
| 3952 | 3960 | name = "zipelo-memory-gzip-reader" |
| 3953 | 3961 | version = "0.1.0" |
| @@ -3976,6 +3984,7 @@ version = "0.1.0" | ||
| 3976 | 3984 | dependencies = [ |
| 3977 | 3985 | "eframe", |
| 3978 | 3986 | "zipelo-app-core-memory", |
| 3987 | 추가: "zipelo-archive-worker", | |
| 3979 | 3988 | ] |
| 3980 | 3989 | |
| 3981 | 3990 | [[package]] |
| @@ -18,6 +18,7 @@ ui = ["dep:eframe"] | ||
| 18 | 18 | ui-fixture = ["ui"] |
| 19 | 19 | |
| 20 | 20 | [dependencies] |
| 21 | 추가: worker_protocol = { package = "zipelo-archive-worker", path = "../rust-archive-worker" } | |
| 21 | 22 | core_memory = { package = "zipelo-app-core-memory", path = "../rust-app-core-memory" } |
| 22 | 23 | eframe = { version = "=0.37.0", optional = true, default-features = false, features = ["accesskit", "clipboard", "glow", "system_fonts", "wayland", "x11"] } |
| 23 | 24 | |
| @@ -33,3 +34,7 @@ path = "../../tests/rust-ui-memory-app/regressions.rs" | ||
| 33 | 34 | [[test]] |
| 34 | 35 | name = "archive_ui" |
| 35 | 36 | path = "../../tests/rust-app-ui/regressions.rs" |
| 37 | 추가: | |
| 38 | 추가: [[test]] | |
| 39 | 추가: name = "real_worker" | |
| 40 | 추가: path = "../../tests/rust-app-real-worker/flows.rs" |
| @@ -0,0 +1,675 @@ | ||
| 1 | 추가: use crate::archive_ui as ui; | |
| 2 | 추가: use std::{ | |
| 3 | 추가: cell::RefCell, | |
| 4 | 추가: io::{self, Read, Write}, | |
| 5 | 추가: path::PathBuf, | |
| 6 | 추가: process::{Command, Stdio}, | |
| 7 | 추가: rc::Rc, | |
| 8 | 추가: sync::{ | |
| 9 | 추가: Arc, Mutex, | |
| 10 | 추가: atomic::{AtomicBool, Ordering}, | |
| 11 | 추가: mpsc::{self, Receiver, SyncSender}, | |
| 12 | 추가: }, | |
| 13 | 추가: thread::{self, JoinHandle}, | |
| 14 | 추가: time::{Duration, Instant}, | |
| 15 | 추가: }; | |
| 16 | 추가: use worker_protocol::{protocol as wire, wire as codec}; | |
| 17 | 추가: | |
| 18 | 추가: macro_rules! convert_enum { | |
| 19 | 추가: ($name:ident, $from:ty, $to:ty, $($variant:ident),+) => { | |
| 20 | 추가: fn $name(value: $from) -> $to { | |
| 21 | 추가: match value { $(<$from>::$variant => <$to>::$variant),+ } | |
| 22 | 추가: } | |
| 23 | 추가: }; | |
| 24 | 추가: } | |
| 25 | 추가: convert_enum!( | |
| 26 | 추가: format_to_wire, | |
| 27 | 추가: ui::Format, | |
| 28 | 추가: wire::Format, | |
| 29 | 추가: Zip, | |
| 30 | 추가: Tar, | |
| 31 | 추가: Gzip, | |
| 32 | 추가: TarGzip | |
| 33 | 추가: ); | |
| 34 | 추가: convert_enum!( | |
| 35 | 추가: format_to_ui, | |
| 36 | 추가: wire::Format, | |
| 37 | 추가: ui::Format, | |
| 38 | 추가: Zip, | |
| 39 | 추가: Tar, | |
| 40 | 추가: Gzip, | |
| 41 | 추가: TarGzip | |
| 42 | 추가: ); | |
| 43 | 추가: convert_enum!( | |
| 44 | 추가: kind_to_ui, | |
| 45 | 추가: wire::EntryKind, | |
| 46 | 추가: ui::Kind, | |
| 47 | 추가: File, | |
| 48 | 추가: Directory, | |
| 49 | 추가: Link, | |
| 50 | 추가: Other | |
| 51 | 추가: ); | |
| 52 | 추가: convert_enum!( | |
| 53 | 추가: stage_to_ui, | |
| 54 | 추가: wire::Stage, | |
| 55 | 추가: ui::Stage, | |
| 56 | 추가: Scan, | |
| 57 | 추가: Read, | |
| 58 | 추가: Decode, | |
| 59 | 추가: Write, | |
| 60 | 추가: Verify, | |
| 61 | 추가: Commit | |
| 62 | 추가: ); | |
| 63 | 추가: convert_enum!( | |
| 64 | 추가: disposition_to_ui, | |
| 65 | 추가: wire::Disposition, | |
| 66 | 추가: ui::Disposition, | |
| 67 | 추가: Created, | |
| 68 | 추가: PartialRetained, | |
| 69 | 추가: Removed, | |
| 70 | 추가: CommitUncertain | |
| 71 | 추가: ); | |
| 72 | 추가: convert_enum!( | |
| 73 | 추가: outcome_to_ui, | |
| 74 | 추가: wire::Outcome, | |
| 75 | 추가: ui::Outcome, | |
| 76 | 추가: Completed, | |
| 77 | 추가: Failed, | |
| 78 | 추가: Cancelled | |
| 79 | 추가: ); | |
| 80 | 추가: convert_enum!( | |
| 81 | 추가: publication_to_ui, | |
| 82 | 추가: wire::Publication, | |
| 83 | 추가: ui::Publication, | |
| 84 | 추가: None, | |
| 85 | 추가: Partial, | |
| 86 | 추가: Complete, | |
| 87 | 추가: Uncertain | |
| 88 | 추가: ); | |
| 89 | 추가: convert_enum!( | |
| 90 | 추가: durability_to_ui, | |
| 91 | 추가: wire::Durability, | |
| 92 | 추가: ui::Durability, | |
| 93 | 추가: NotApplicable, | |
| 94 | 추가: Synced, | |
| 95 | 추가: Unconfirmed, | |
| 96 | 추가: Failed | |
| 97 | 추가: ); | |
| 98 | 추가: convert_enum!( | |
| 99 | 추가: cleanup_to_ui, | |
| 100 | 추가: wire::Cleanup, | |
| 101 | 추가: ui::Cleanup, | |
| 102 | 추가: Complete, | |
| 103 | 추가: Failed, | |
| 104 | 추가: Unconfirmed | |
| 105 | 추가: ); | |
| 106 | 추가: convert_enum!( | |
| 107 | 추가: cancel_to_ui, | |
| 108 | 추가: wire::CancelStatus, | |
| 109 | 추가: ui::CancelStatus, | |
| 110 | 추가: Requested, | |
| 111 | 추가: AlreadyRequested, | |
| 112 | 추가: TooLate, | |
| 113 | 추가: Finished | |
| 114 | 추가: ); | |
| 115 | 추가: fn list_to_wire(id: ui::ListId) -> wire::ListId { | |
| 116 | 추가: wire::ListId { | |
| 117 | 추가: catalog_version: id.catalog_version, | |
| 118 | 추가: format: format_to_wire(id.format), | |
| 119 | 추가: source_object: match id.source_object { | |
| 120 | 추가: ui::SourceObject::Unix { device, inode } => wire::SourceObject::Unix { device, inode }, | |
| 121 | 추가: ui::SourceObject::Windows { volume, file_id } => wire::SourceObject::Windows { | |
| 122 | 추가: volume_serial: volume, | |
| 123 | 추가: file_id, | |
| 124 | 추가: }, | |
| 125 | 추가: }, | |
| 126 | 추가: archive_bytes: id.archive_bytes, | |
| 127 | 추가: archive_sha256: id.archive_sha256, | |
| 128 | 추가: } | |
| 129 | 추가: } | |
| 130 | 추가: fn list_to_ui(id: wire::ListId) -> ui::ListId { | |
| 131 | 추가: ui::ListId { | |
| 132 | 추가: catalog_version: id.catalog_version, | |
| 133 | 추가: format: format_to_ui(id.format), | |
| 134 | 추가: source_object: match id.source_object { | |
| 135 | 추가: wire::SourceObject::Unix { device, inode } => ui::SourceObject::Unix { device, inode }, | |
| 136 | 추가: wire::SourceObject::Windows { | |
| 137 | 추가: volume_serial, | |
| 138 | 추가: file_id, | |
| 139 | 추가: } => ui::SourceObject::Windows { | |
| 140 | 추가: volume: volume_serial, | |
| 141 | 추가: file_id, | |
| 142 | 추가: }, | |
| 143 | 추가: }, | |
| 144 | 추가: archive_bytes: id.archive_bytes, | |
| 145 | 추가: archive_sha256: id.archive_sha256, | |
| 146 | 추가: } | |
| 147 | 추가: } | |
| 148 | 추가: fn start_to_wire(start: ui::Start) -> wire::Start { | |
| 149 | 추가: let action = match start { | |
| 150 | 추가: ui::Start::List { archive } => wire::Action::List { | |
| 151 | 추가: archive: wire::NativePath::from_path(&archive), | |
| 152 | 추가: }, | |
| 153 | 추가: ui::Start::Extract { | |
| 154 | 추가: archive, | |
| 155 | 추가: destination, | |
| 156 | 추가: selection, | |
| 157 | 추가: list_id, | |
| 158 | 추가: gzip_output_name, | |
| 159 | 추가: } => wire::Action::Extract { | |
| 160 | 추가: archive: wire::NativePath::from_path(&archive), | |
| 161 | 추가: destination: wire::NativePath::from_path(&destination), | |
| 162 | 추가: selection: match selection { | |
| 163 | 추가: ui::Selection::All => wire::Selection::All, | |
| 164 | 추가: ui::Selection::EntryIds(ids) => wire::Selection::EntryIds(ids), | |
| 165 | 추가: }, | |
| 166 | 추가: list_id: Some(list_to_wire(list_id)), | |
| 167 | 추가: gzip_output_name, | |
| 168 | 추가: }, | |
| 169 | 추가: ui::Start::CreateZip { | |
| 170 | 추가: sources, | |
| 171 | 추가: output_file, | |
| 172 | 추가: method, | |
| 173 | 추가: aes256, | |
| 174 | 추가: } => wire::Action::CreateZip { | |
| 175 | 추가: sources: sources | |
| 176 | 추가: .into_iter() | |
| 177 | 추가: .map(|(path, archive_name)| wire::Source { | |
| 178 | 추가: path: wire::NativePath::from_path(&path), | |
| 179 | 추가: archive_name, | |
| 180 | 추가: }) | |
| 181 | 추가: .collect(), | |
| 182 | 추가: output_file: wire::NativePath::from_path(&output_file), | |
| 183 | 추가: method: match method { | |
| 184 | 추가: ui::Method::Store => wire::Method::Store, | |
| 185 | 추가: ui::Method::Deflate => wire::Method::Deflate, | |
| 186 | 추가: }, | |
| 187 | 추가: encryption: if aes256 { | |
| 188 | 추가: wire::Encryption::Aes256 | |
| 189 | 추가: } else { | |
| 190 | 추가: wire::Encryption::None | |
| 191 | 추가: }, | |
| 192 | 추가: }, | |
| 193 | 추가: }; | |
| 194 | 추가: wire::Start { | |
| 195 | 추가: action, | |
| 196 | 추가: limits: wire::Limits::default(), | |
| 197 | 추가: } | |
| 198 | 추가: } | |
| 199 | 추가: fn error_to_ui(error: wire::ErrorCode) -> Option<ui::ErrorCode> { | |
| 200 | 추가: Some(match error { | |
| 201 | 추가: wire::ErrorCode::None => return None, | |
| 202 | 추가: wire::ErrorCode::Integrity => ui::ErrorCode::Integrity, | |
| 203 | 추가: wire::ErrorCode::UnsupportedFormat => ui::ErrorCode::UnsupportedFormat, | |
| 204 | 추가: wire::ErrorCode::UnsupportedFeature => ui::ErrorCode::UnsupportedFeature, | |
| 205 | 추가: wire::ErrorCode::WrongPassword => ui::ErrorCode::WrongPassword, | |
| 206 | 추가: wire::ErrorCode::UnsafePath => ui::ErrorCode::UnsafePath, | |
| 207 | 추가: wire::ErrorCode::Conflict => ui::ErrorCode::Conflict, | |
| 208 | 추가: wire::ErrorCode::Limit => ui::ErrorCode::Limit, | |
| 209 | 추가: wire::ErrorCode::Io => ui::ErrorCode::Io, | |
| 210 | 추가: wire::ErrorCode::Protocol => ui::ErrorCode::Protocol, | |
| 211 | 추가: wire::ErrorCode::Internal => ui::ErrorCode::Internal, | |
| 212 | 추가: wire::ErrorCode::SourceChanged => ui::ErrorCode::SourceChanged, | |
| 213 | 추가: wire::ErrorCode::InvalidRequest => ui::ErrorCode::InvalidRequest, | |
| 214 | 추가: }) | |
| 215 | 추가: } | |
| 216 | 추가: fn event_to_ui( | |
| 217 | 추가: message: wire::Message, | |
| 218 | 추가: expected: Option<wire::ActionKind>, | |
| 219 | 추가: ) -> Result<ui::Event, ()> { | |
| 220 | 추가: Ok(match message { | |
| 221 | 추가: wire::Message::Accepted { action, encryption } if expected == Some(action) => { | |
| 222 | 추가: ui::Event::Accepted { encryption } | |
| 223 | 추가: } | |
| 224 | 추가: wire::Message::Entry(entry) => ui::Event::Entry(ui::Entry { | |
| 225 | 추가: id: entry.entry_id, | |
| 226 | 추가: name: entry.name, | |
| 227 | 추가: kind: kind_to_ui(entry.kind), | |
| 228 | 추가: bytes: Some(entry.size), | |
| 229 | 추가: packed: Some(entry.compressed_size), | |
| 230 | 추가: encrypted: entry.encrypted, | |
| 231 | 추가: }), | |
| 232 | 추가: wire::Message::ListEnd { | |
| 233 | 추가: entry_count, | |
| 234 | 추가: list_id, | |
| 235 | 추가: } => ui::Event::ListEnd { | |
| 236 | 추가: entry_count, | |
| 237 | 추가: list_id: list_to_ui(list_id), | |
| 238 | 추가: }, | |
| 239 | 추가: wire::Message::PasswordRequired { | |
| 240 | 추가: challenge_id, | |
| 241 | 추가: attempt, | |
| 242 | 추가: purpose, | |
| 243 | 추가: } => ui::Event::PasswordRequired { | |
| 244 | 추가: challenge_id, | |
| 245 | 추가: attempt, | |
| 246 | 추가: encrypt: purpose == wire::PasswordPurpose::Encrypt, | |
| 247 | 추가: }, | |
| 248 | 추가: wire::Message::Progress { | |
| 249 | 추가: stage, | |
| 250 | 추가: processed_bytes, | |
| 251 | 추가: total_bytes, | |
| 252 | 추가: completed_entries, | |
| 253 | 추가: } => ui::Event::Progress { | |
| 254 | 추가: stage: stage_to_ui(stage), | |
| 255 | 추가: processed: processed_bytes, | |
| 256 | 추가: total: total_bytes, | |
| 257 | 추가: completed_entries: completed_entries.into(), | |
| 258 | 추가: }, | |
| 259 | 추가: wire::Message::Output { | |
| 260 | 추가: entry_id, | |
| 261 | 추가: relative_name, | |
| 262 | 추가: disposition, | |
| 263 | 추가: } => ui::Event::Output { | |
| 264 | 추가: entry_id, | |
| 265 | 추가: relative_name, | |
| 266 | 추가: disposition: disposition_to_ui(disposition), | |
| 267 | 추가: }, | |
| 268 | 추가: wire::Message::CancelAck { | |
| 269 | 추가: request_sequence, | |
| 270 | 추가: status, | |
| 271 | 추가: } => ui::Event::CancelAck { | |
| 272 | 추가: request_sequence, | |
| 273 | 추가: status: cancel_to_ui(status), | |
| 274 | 추가: }, | |
| 275 | 추가: wire::Message::Terminal(terminal) => ui::Event::Terminal(ui::Terminal { | |
| 276 | 추가: outcome: outcome_to_ui(terminal.outcome), | |
| 277 | 추가: error: error_to_ui(terminal.error), | |
| 278 | 추가: publication: publication_to_ui(terminal.publication), | |
| 279 | 추가: created_count: terminal.created_count, | |
| 280 | 추가: retained_partial_count: terminal.retained_partial_count, | |
| 281 | 추가: durability: durability_to_ui(terminal.durability), | |
| 282 | 추가: cleanup: cleanup_to_ui(terminal.cleanup), | |
| 283 | 추가: }), | |
| 284 | 추가: _ => return Err(()), | |
| 285 | 추가: }) | |
| 286 | 추가: } | |
| 287 | 추가: | |
| 288 | 추가: // 실제 파이프 쓰기는 백그라운드에서 수행하고 UI에서는 한 프레임만 직렬화함. | |
| 289 | 추가: #[derive(Clone, Default)] | |
| 290 | 추가: struct FrameBuffer(Rc<RefCell<Vec<u8>>>); | |
| 291 | 추가: impl Write for FrameBuffer { | |
| 292 | 추가: fn write(&mut self, bytes: &[u8]) -> io::Result<usize> { | |
| 293 | 추가: let mut buffer = self.0.borrow_mut(); | |
| 294 | 추가: if buffer.len().saturating_add(bytes.len()) > codec::MAX_BODY + 32 { | |
| 295 | 추가: return Err(io::Error::other("요청 프레임 한도 초과")); | |
| 296 | 추가: } | |
| 297 | 추가: buffer.extend_from_slice(bytes); | |
| 298 | 추가: Ok(bytes.len()) | |
| 299 | 추가: } | |
| 300 | 추가: fn flush(&mut self) -> io::Result<()> { | |
| 301 | 추가: Ok(()) | |
| 302 | 추가: } | |
| 303 | 추가: } | |
| 304 | 추가: struct Frame(Vec<u8>, bool); | |
| 305 | 추가: impl Drop for Frame { | |
| 306 | 추가: fn drop(&mut self) { | |
| 307 | 추가: self.0.fill(0); | |
| 308 | 추가: } | |
| 309 | 추가: } | |
| 310 | 추가: fn notify(events: &SyncSender<ui::HostEvent>, event: ui::HostEvent) -> bool { | |
| 311 | 추가: events.send(event).is_ok() | |
| 312 | 추가: } | |
| 313 | 추가: fn fault(events: &SyncSender<ui::HostEvent>, stop: &AtomicBool, message: &str) { | |
| 314 | 추가: stop.store(true, Ordering::Release); | |
| 315 | 추가: notify(events, ui::HostEvent::Fault(message.into())); | |
| 316 | 추가: } | |
| 317 | 추가: | |
| 318 | 추가: pub struct ProcessFactory { | |
| 319 | 추가: worker: PathBuf, | |
| 320 | 추가: } | |
| 321 | 추가: impl ProcessFactory { | |
| 322 | 추가: pub fn new(worker: PathBuf) -> Self { | |
| 323 | 추가: Self { worker } | |
| 324 | 추가: } | |
| 325 | 추가: pub fn sibling() -> Result<Self, String> { | |
| 326 | 추가: let executable = | |
| 327 | 추가: std::env::current_exe().map_err(|_| "앱 실행 위치를 확인하지 못했습니다")?; | |
| 328 | 추가: let parent = executable.parent().ok_or("앱 실행 폴더가 없습니다")?; | |
| 329 | 추가: Ok(Self::new(parent.join(if cfg!(windows) { | |
| 330 | 추가: "zipelo-archive-worker.exe" | |
| 331 | 추가: } else { | |
| 332 | 추가: "zipelo-archive-worker" | |
| 333 | 추가: }))) | |
| 334 | 추가: } | |
| 335 | 추가: } | |
| 336 | 추가: impl ui::Factory for ProcessFactory { | |
| 337 | 추가: fn connect(&mut self, job_id: u64) -> Result<Box<dyn ui::Connection>, String> { | |
| 338 | 추가: if !self.worker.is_absolute() || job_id == 0 { | |
| 339 | 추가: return Err("작업자 경로 또는 작업 ID가 올바르지 않습니다".into()); | |
| 340 | 추가: } | |
| 341 | 추가: let (send, requests) = mpsc::sync_channel::<Frame>(8); | |
| 342 | 추가: let (events, receive) = mpsc::sync_channel(64); | |
| 343 | 추가: let (ready, started) = mpsc::sync_channel(1); | |
| 344 | 추가: let stop = Arc::new(AtomicBool::new(false)); | |
| 345 | 추가: let done = Arc::new(AtomicBool::new(false)); | |
| 346 | 추가: let expected = Arc::new(Mutex::new(None)); | |
| 347 | 추가: let worker = self.worker.clone(); | |
| 348 | 추가: let worker_stop = stop.clone(); | |
| 349 | 추가: let worker_done = done.clone(); | |
| 350 | 추가: let worker_expected = expected.clone(); | |
| 351 | 추가: let supervisor = thread::Builder::new() | |
| 352 | 추가: .name("zipelo-worker-owner".into()) | |
| 353 | 추가: .spawn(move || { | |
| 354 | 추가: let mut command = Command::new(worker); | |
| 355 | 추가: command | |
| 356 | 추가: .stdin(Stdio::piped()) | |
| 357 | 추가: .stdout(Stdio::piped()) | |
| 358 | 추가: .stderr(Stdio::piped()); | |
| 359 | 추가: #[cfg(windows)] | |
| 360 | 추가: { | |
| 361 | 추가: use std::os::windows::process::CommandExt; | |
| 362 | 추가: command.creation_flags(0x08000000); | |
| 363 | 추가: } | |
| 364 | 추가: let child = match command.spawn() { | |
| 365 | 추가: Ok(child) => child, | |
| 366 | 추가: Err(_) => { | |
| 367 | 추가: let _ = ready.send(Err( | |
| 368 | 추가: "작업자를 실행하지 못했습니다. 앱과 작업자를 함께 설치하세요" | |
| 369 | 추가: .to_string(), | |
| 370 | 추가: )); | |
| 371 | 추가: return; | |
| 372 | 추가: } | |
| 373 | 추가: }; | |
| 374 | 추가: if ready.send(Ok(())).is_err() { | |
| 375 | 추가: let mut child = child; | |
| 376 | 추가: let _ = child.kill(); | |
| 377 | 추가: let _ = child.wait(); | |
| 378 | 추가: return; | |
| 379 | 추가: } | |
| 380 | 추가: supervise( | |
| 381 | 추가: child, | |
| 382 | 추가: job_id, | |
| 383 | 추가: requests, | |
| 384 | 추가: events, | |
| 385 | 추가: worker_stop, | |
| 386 | 추가: worker_done, | |
| 387 | 추가: worker_expected, | |
| 388 | 추가: ); | |
| 389 | 추가: }) | |
| 390 | 추가: .map_err(|_| "작업자 관리 스레드를 시작하지 못했습니다")?; | |
| 391 | 추가: match started.recv() { | |
| 392 | 추가: Ok(Ok(())) => { | |
| 393 | 추가: let buffer = FrameBuffer::default(); | |
| 394 | 추가: Ok(Box::new(ProcessConnection { | |
| 395 | 추가: job_id, | |
| 396 | 추가: next: 0, | |
| 397 | 추가: writer: codec::Writer::new(buffer.clone(), job_id), | |
| 398 | 추가: buffer, | |
| 399 | 추가: send: Some(send), | |
| 400 | 추가: receive: Some(receive), | |
| 401 | 추가: stop, | |
| 402 | 추가: supervisor: Some(supervisor), | |
| 403 | 추가: expected, | |
| 404 | 추가: done, | |
| 405 | 추가: disconnected: false, | |
| 406 | 추가: reaped: false, | |
| 407 | 추가: })) | |
| 408 | 추가: } | |
| 409 | 추가: result => { | |
| 410 | 추가: stop.store(true, Ordering::Release); | |
| 411 | 추가: drop(send); | |
| 412 | 추가: drop(receive); | |
| 413 | 추가: let _ = supervisor.join(); | |
| 414 | 추가: Err(result | |
| 415 | 추가: .ok() | |
| 416 | 추가: .and_then(Result::err) | |
| 417 | 추가: .unwrap_or_else(|| "작업자 시작 결과가 없습니다".into())) | |
| 418 | 추가: } | |
| 419 | 추가: } | |
| 420 | 추가: } | |
| 421 | 추가: } | |
| 422 | 추가: struct ProcessConnection { | |
| 423 | 추가: job_id: u64, | |
| 424 | 추가: next: u64, | |
| 425 | 추가: writer: codec::Writer<FrameBuffer>, | |
| 426 | 추가: buffer: FrameBuffer, | |
| 427 | 추가: send: Option<SyncSender<Frame>>, | |
| 428 | 추가: receive: Option<Receiver<ui::HostEvent>>, | |
| 429 | 추가: stop: Arc<AtomicBool>, | |
| 430 | 추가: supervisor: Option<JoinHandle<()>>, | |
| 431 | 추가: expected: Arc<Mutex<Option<wire::ActionKind>>>, | |
| 432 | 추가: done: Arc<AtomicBool>, | |
| 433 | 추가: disconnected: bool, | |
| 434 | 추가: reaped: bool, | |
| 435 | 추가: } | |
| 436 | 추가: impl ui::Connection for ProcessConnection { | |
| 437 | 추가: fn send(&mut self, request: ui::Request) -> Result<(), String> { | |
| 438 | 추가: if self.stop.load(Ordering::Acquire) | |
| 439 | 추가: || request.job_id != self.job_id | |
| 440 | 추가: || request.sequence != self.next | |
| 441 | 추가: || self.next >= codec::MAX_FRAMES | |
| 442 | 추가: { | |
| 443 | 추가: self.stop.store(true, Ordering::Release); | |
| 444 | 추가: return Err("작업자 요청 채널이 닫혔거나 순서가 올바르지 않습니다".into()); | |
| 445 | 추가: } | |
| 446 | 추가: let is_cancel = matches!(request.command, ui::Command::Cancel); | |
| 447 | 추가: let message = match request.command { | |
| 448 | 추가: ui::Command::Start(start) => { | |
| 449 | 추가: let start = start_to_wire(start); | |
| 450 | 추가: *self.expected.lock().map_err(|_| { | |
| 451 | 추가: self.stop.store(true, Ordering::Release); | |
| 452 | 추가: "작업자 요청 상태 오류" | |
| 453 | 추가: })? = Some(start.action.kind()); | |
| 454 | 추가: wire::Message::Start(start) | |
| 455 | 추가: } | |
| 456 | 추가: ui::Command::Cancel => wire::Message::Cancel, | |
| 457 | 추가: ui::Command::Password { | |
| 458 | 추가: challenge_id, | |
| 459 | 추가: secret, | |
| 460 | 추가: } => wire::Message::Password { | |
| 461 | 추가: challenge_id, | |
| 462 | 추가: secret: wire::Secret(secret.as_bytes().to_vec()), | |
| 463 | 추가: }, | |
| 464 | 추가: }; | |
| 465 | 추가: if self.writer.send(&message).is_err() { | |
| 466 | 추가: self.buffer.0.borrow_mut().fill(0); | |
| 467 | 추가: self.buffer.0.borrow_mut().clear(); | |
| 468 | 추가: self.stop.store(true, Ordering::Release); | |
| 469 | 추가: return Err("작업자 요청을 직렬화하지 못했습니다".into()); | |
| 470 | 추가: } | |
| 471 | 추가: let bytes = Frame(std::mem::take(&mut *self.buffer.0.borrow_mut()), is_cancel); | |
| 472 | 추가: if self.send.as_ref().unwrap().try_send(bytes).is_err() { | |
| 473 | 추가: if is_cancel && self.done.load(Ordering::Acquire) { | |
| 474 | 추가: self.next += 1; | |
| 475 | 추가: return Ok(()); | |
| 476 | 추가: } | |
| 477 | 추가: self.stop.store(true, Ordering::Release); | |
| 478 | 추가: return Err("작업자 요청 대기열이 닫혔거나 가득 찼습니다".into()); | |
| 479 | 추가: } | |
| 480 | 추가: self.next += 1; | |
| 481 | 추가: Ok(()) | |
| 482 | 추가: } | |
| 483 | 추가: fn poll(&mut self) -> Option<ui::HostEvent> { | |
| 484 | 추가: match self.receive.as_ref()?.try_recv() { | |
| 485 | 추가: Ok(event) => { | |
| 486 | 추가: if matches!(event, ui::HostEvent::Exited { .. }) { | |
| 487 | 추가: self.reaped = true; | |
| 488 | 추가: } | |
| 489 | 추가: Some(event) | |
| 490 | 추가: } | |
| 491 | 추가: Err(mpsc::TryRecvError::Empty) => None, | |
| 492 | 추가: Err(mpsc::TryRecvError::Disconnected) if !self.reaped && !self.disconnected => { | |
| 493 | 추가: self.disconnected = true; | |
| 494 | 추가: Some(ui::HostEvent::Fault( | |
| 495 | 추가: "작업자 통신 스레드가 종료됐습니다".into(), | |
| 496 | 추가: )) | |
| 497 | 추가: } | |
| 498 | 추가: Err(_) => None, | |
| 499 | 추가: } | |
| 500 | 추가: } | |
| 501 | 추가: } | |
| 502 | 추가: impl Drop for ProcessConnection { | |
| 503 | 추가: fn drop(&mut self) { | |
| 504 | 추가: self.stop.store(true, Ordering::Release); | |
| 505 | 추가: self.send.take(); | |
| 506 | 추가: self.receive.take(); | |
| 507 | 추가: if let Some(supervisor) = self.supervisor.take() { | |
| 508 | 추가: let _ = supervisor.join(); | |
| 509 | 추가: } | |
| 510 | 추가: } | |
| 511 | 추가: } | |
| 512 | 추가: | |
| 513 | 추가: fn supervise( | |
| 514 | 추가: mut child: std::process::Child, | |
| 515 | 추가: job_id: u64, | |
| 516 | 추가: requests: Receiver<Frame>, | |
| 517 | 추가: events: SyncSender<ui::HostEvent>, | |
| 518 | 추가: stop: Arc<AtomicBool>, | |
| 519 | 추가: done: Arc<AtomicBool>, | |
| 520 | 추가: expected: Arc<Mutex<Option<wire::ActionKind>>>, | |
| 521 | 추가: ) { | |
| 522 | 추가: let mut input = child.stdin.take().unwrap(); | |
| 523 | 추가: let mut output = child.stdout.take().unwrap(); | |
| 524 | 추가: let mut errors = child.stderr.take().unwrap(); | |
| 525 | 추가: let mut threads = Vec::new(); | |
| 526 | 추가: let cancel_write_failed = Arc::new(AtomicBool::new(false)); | |
| 527 | 추가: let terminal_received = Arc::new(AtomicBool::new(false)); | |
| 528 | 추가: let failed_cancel = cancel_write_failed.clone(); | |
| 529 | 추가: let tx = events.clone(); | |
| 530 | 추가: let abort = stop.clone(); | |
| 531 | 추가: let finished = done.clone(); | |
| 532 | 추가: threads.push( | |
| 533 | 추가: thread::Builder::new() | |
| 534 | 추가: .name("zipelo-worker-input".into()) | |
| 535 | 추가: .spawn(move || { | |
| 536 | 추가: while !finished.load(Ordering::Acquire) && !abort.load(Ordering::Acquire) { | |
| 537 | 추가: match requests.recv_timeout(Duration::from_millis(10)) { | |
| 538 | 추가: Ok(frame) => { | |
| 539 | 추가: if input | |
| 540 | 추가: .write_all(&frame.0) | |
| 541 | 추가: .and_then(|_| input.flush()) | |
| 542 | 추가: .is_err() | |
| 543 | 추가: { | |
| 544 | 추가: if frame.1 { | |
| 545 | 추가: // 취소 쓰기 실패는 응답과 실제 종료 결과를 확인한 뒤 판단함. | |
| 546 | 추가: failed_cancel.store(true, Ordering::Release); | |
| 547 | 추가: } else { | |
| 548 | 추가: fault(&tx, &abort, "작업자 요청 파이프 쓰기에 실패했습니다"); | |
| 549 | 추가: } | |
| 550 | 추가: break; | |
| 551 | 추가: } | |
| 552 | 추가: } | |
| 553 | 추가: Err(mpsc::RecvTimeoutError::Timeout) => {} | |
| 554 | 추가: Err(_) => break, | |
| 555 | 추가: } | |
| 556 | 추가: } | |
| 557 | 추가: }), | |
| 558 | 추가: ); | |
| 559 | 추가: let tx = events.clone(); | |
| 560 | 추가: let abort = stop.clone(); | |
| 561 | 추가: let received_terminal = terminal_received.clone(); | |
| 562 | 추가: threads.push( | |
| 563 | 추가: thread::Builder::new() | |
| 564 | 추가: .name("zipelo-worker-output".into()) | |
| 565 | 추가: .spawn(move || { | |
| 566 | 추가: let eof; | |
| 567 | 추가: { | |
| 568 | 추가: let mut reader = codec::Reader::new(&mut output); | |
| 569 | 추가: eof = loop { | |
| 570 | 추가: match reader.read() { | |
| 571 | 추가: Ok(Some((job, sequence, message))) => { | |
| 572 | 추가: let action = expected.lock().ok().and_then(|value| *value); | |
| 573 | 추가: let event = event_to_ui(message, action); | |
| 574 | 추가: if job != job_id || event.is_err() { | |
| 575 | 추가: fault(&tx, &abort, "작업자 응답이 요청과 일치하지 않습니다"); | |
| 576 | 추가: break false; | |
| 577 | 추가: } | |
| 578 | 추가: if matches!(event, Ok(ui::Event::Terminal(_))) { | |
| 579 | 추가: received_terminal.store(true, Ordering::Release); | |
| 580 | 추가: } | |
| 581 | 추가: if !notify( | |
| 582 | 추가: &tx, | |
| 583 | 추가: ui::HostEvent::Frame { | |
| 584 | 추가: job_id: job, | |
| 585 | 추가: sequence, | |
| 586 | 추가: event: event.unwrap(), | |
| 587 | 추가: }, | |
| 588 | 추가: ) { | |
| 589 | 추가: return; | |
| 590 | 추가: } | |
| 591 | 추가: } | |
| 592 | 추가: Ok(None) => break true, | |
| 593 | 추가: Err(_) => { | |
| 594 | 추가: fault(&tx, &abort, "작업자 응답 프레임을 읽지 못했습니다"); | |
| 595 | 추가: break false; | |
| 596 | 추가: } | |
| 597 | 추가: } | |
| 598 | 추가: }; | |
| 599 | 추가: } | |
| 600 | 추가: if eof || io::copy(&mut output, &mut io::sink()).is_ok() { | |
| 601 | 추가: notify(&tx, ui::HostEvent::StdoutEof); | |
| 602 | 추가: } | |
| 603 | 추가: }), | |
| 604 | 추가: ); | |
| 605 | 추가: let tx = events.clone(); | |
| 606 | 추가: let abort = stop.clone(); | |
| 607 | 추가: threads.push( | |
| 608 | 추가: thread::Builder::new() | |
| 609 | 추가: .name("zipelo-worker-errors".into()) | |
| 610 | 추가: .spawn(move || { | |
| 611 | 추가: let mut bytes = [0u8; 4096]; | |
| 612 | 추가: loop { | |
| 613 | 추가: match errors.read(&mut bytes) { | |
| 614 | 추가: Ok(0) => { | |
| 615 | 추가: notify(&tx, ui::HostEvent::StderrEof); | |
| 616 | 추가: break; | |
| 617 | 추가: } | |
| 618 | 추가: Ok(_) => {} | |
| 619 | 추가: Err(error) if error.kind() == io::ErrorKind::Interrupted => {} | |
| 620 | 추가: Err(_) => { | |
| 621 | 추가: fault(&tx, &abort, "작업자 오류 파이프를 읽지 못했습니다"); | |
| 622 | 추가: break; | |
| 623 | 추가: } | |
| 624 | 추가: } | |
| 625 | 추가: } | |
| 626 | 추가: }), | |
| 627 | 추가: ); | |
| 628 | 추가: let mut handles = Vec::new(); | |
| 629 | 추가: for result in threads { | |
| 630 | 추가: match result { | |
| 631 | 추가: Ok(handle) => handles.push(handle), | |
| 632 | 추가: Err(_) => fault(&events, &stop, "작업자 통신 스레드를 시작하지 못했습니다"), | |
| 633 | 추가: } | |
| 634 | 추가: } | |
| 635 | 추가: let started = Instant::now(); | |
| 636 | 추가: let status = loop { | |
| 637 | 추가: if started.elapsed() >= Duration::from_secs(310) { | |
| 638 | 추가: fault(&events, &stop, "작업자 처리 제한 시간을 초과했습니다"); | |
| 639 | 추가: } | |
| 640 | 추가: if stop.load(Ordering::Acquire) { | |
| 641 | 추가: let _ = child.kill(); | |
| 642 | 추가: } | |
| 643 | 추가: match child.try_wait() { | |
| 644 | 추가: Ok(Some(status)) => break Some(status), | |
| 645 | 추가: Ok(None) => thread::sleep(Duration::from_millis(10)), | |
| 646 | 추가: Err(_) => { | |
| 647 | 추가: fault(&events, &stop, "작업자 종료 상태를 확인하지 못했습니다"); | |
| 648 | 추가: let _ = child.kill(); | |
| 649 | 추가: break child.wait().ok(); | |
| 650 | 추가: } | |
| 651 | 추가: } | |
| 652 | 추가: }; | |
| 653 | 추가: done.store(true, Ordering::Release); | |
| 654 | 추가: for handle in handles { | |
| 655 | 추가: if handle.join().is_err() { | |
| 656 | 추가: fault(&events, &stop, "작업자 통신 스레드 회수에 실패했습니다"); | |
| 657 | 추가: } | |
| 658 | 추가: } | |
| 659 | 추가: if cancel_write_failed.load(Ordering::Acquire) | |
| 660 | 추가: && !(terminal_received.load(Ordering::Acquire) | |
| 661 | 추가: && status.as_ref().is_some_and(|status| status.success())) | |
| 662 | 추가: { | |
| 663 | 추가: fault(&events, &stop, "작업자 요청 파이프 쓰기에 실패했습니다"); | |
| 664 | 추가: } | |
| 665 | 추가: if let Some(status) = status { | |
| 666 | 추가: // 회수와 모든 파이프 핸들 정리가 끝난 뒤에만 닫기 허용 근거를 전달함. | |
| 667 | 추가: notify(&events, ui::HostEvent::CleanupComplete); | |
| 668 | 추가: notify( | |
| 669 | 추가: &events, | |
| 670 | 추가: ui::HostEvent::Exited { | |
| 671 | 추가: success: status.success(), | |
| 672 | 추가: }, | |
| 673 | 추가: ); | |
| 674 | 추가: } | |
| 675 | 추가: } |
| @@ -200,6 +200,8 @@ pub enum Event { | ||
| 200 | 200 | Terminal(Terminal), |
| 201 | 201 | } |
| 202 | 202 | pub enum HostEvent { |
| 203 | 추가: Fault(String), | |
| 204 | 추가: CleanupComplete, | |
| 203 | 205 | Frame { |
| 204 | 206 | job_id: u64, |
| 205 | 207 | sequence: u64, |
| @@ -237,6 +239,7 @@ struct Running { | ||
| 237 | 239 | entries: Vec<Entry>, |
| 238 | 240 | list_end: Option<(u32, ListId)>, |
| 239 | 241 | stdout_eof: bool, |
| 242 | 추가: transport_closed: bool, | |
| 240 | 243 | stderr_eof: bool, |
| 241 | 244 | exit: Option<bool>, |
| 242 | 245 | cancel_sequence: Option<u64>, |
| @@ -380,6 +383,7 @@ impl Model { | ||
| 380 | 383 | entries: Vec::new(), |
| 381 | 384 | list_end: None, |
| 382 | 385 | stdout_eof: false, |
| 386 | 추가: transport_closed: false, | |
| 383 | 387 | stderr_eof: false, |
| 384 | 388 | exit: None, |
| 385 | 389 | cancel_sequence: None, |
| @@ -509,10 +513,10 @@ impl Model { | ||
| 509 | 513 | }; |
| 510 | 514 | self.receive(event); |
| 511 | 515 | } |
| 512 | 삭제: let complete = self | |
| 513 | 삭제: .running | |
| 514 | 삭제: .as_ref() | |
| 515 | 삭제: .is_some_and(|r| r.stdout_eof && r.stderr_eof && r.exit.is_some()); | |
| 516 | 추가: let complete = self.running.as_ref().is_some_and(|r| { | |
| 517 | 추가: r.exit.is_some() | |
| 518 | 추가: && ((r.stdout_eof && r.stderr_eof) || (r.transport_closed && self.error.is_some())) | |
| 519 | 추가: }); | |
| 516 | 520 | if complete { |
| 517 | 521 | let run = self.running.take().unwrap(); |
| 518 | 522 | self.confirmed = |
| @@ -559,6 +563,8 @@ impl Model { | ||
| 559 | 563 | fn receive(&mut self, host: HostEvent) { |
| 560 | 564 | let run = self.running.as_mut().unwrap(); |
| 561 | 565 | match host { |
| 566 | 추가: HostEvent::Fault(message) => self.error = Some(message), | |
| 567 | 추가: HostEvent::CleanupComplete => run.transport_closed = true, | |
| 562 | 568 | HostEvent::StdoutEof => run.stdout_eof = true, |
| 563 | 569 | HostEvent::StderrEof => run.stderr_eof = true, |
| 564 | 570 | HostEvent::Exited { success } => run.exit = Some(success), |
| @@ -58,7 +58,10 @@ fn main() -> eframe::Result { | ||
| 58 | 58 | ))); |
| 59 | 59 | } |
| 60 | 60 | } else { |
| 61 | 삭제: Box::new(zipelo_ui_memory_app::archive_ui::Unavailable) | |
| 61 | 추가: Box::new( | |
| 62 | 추가: zipelo_ui_memory_app::archive_process::ProcessFactory::sibling() | |
| 63 | 추가: .map_err(std::io::Error::other)?, | |
| 64 | 추가: ) | |
| 62 | 65 | }; |
| 63 | 66 | Ok(Box::new( |
| 64 | 67 | zipelo_ui_memory_app::archive_screen::ArchiveApp::new(factory, startup, fixture), |
| @@ -9,3 +9,5 @@ pub mod archive_ui; | ||
| 9 | 9 | |
| 10 | 10 | #[cfg(feature = "ui")] |
| 11 | 11 | pub mod archive_screen; |
| 12 | 추가: | |
| 13 | 추가: pub mod archive_process; |
| @@ -0,0 +1,47 @@ | ||
| 1 | 추가: # Rust Windows 개발판 설치 파일 | |
| 2 | 추가: | |
| 3 | 추가: NSIS를 사용해 Linux에서 Windows x64 설치 EXE를 생성합니다. Rust 앱과 별도 작업자를 | |
| 4 | 추가: 교차 빌드하며 가짜 작업자 기능은 활성화하지 않습니다. | |
| 5 | 추가: | |
| 6 | 추가: ```sh | |
| 7 | 추가: python3 packaging/windows/rust/build.py \ | |
| 8 | 추가: --app-manifest /path/to/app/experiments/rust-ui-memory-app/Cargo.toml \ | |
| 9 | 추가: --worker-manifest /path/to/worker/experiments/rust-archive-worker/Cargo.toml \ | |
| 10 | 추가: --target-dir /path/to/cargo-target \ | |
| 11 | 추가: --output /path/to/new-installer-output | |
| 12 | 추가: ``` | |
| 13 | 추가: | |
| 14 | 추가: Cargo 1.99.1, Windows GNU Rust target, MinGW-w64와 makensis가 필요합니다. | |
| 15 | 추가: 도구는 자동 설치하지 않습니다. 기본 profile은 release이고 개발 검증에는 --profile dev를 사용할 수 있습니다. | |
| 16 | 추가: 출력 폴더는 새 경로여야 하며 기존 파일을 덮어쓰지 않습니다. 입력 저장소는 커밋된 상태여야 합니다. 캐시는 실행 파일과 소스 커밋별로 분리하며 빌드 중 소스 변경을 거부합니다. | |
| 17 | 추가: 앱과 작업자 PR이 병합되기 전에는 각 PR의 별도 소스 경로를 인자로 지정합니다. | |
| 18 | 추가: 빌드 정보에는 소스 커밋, 실행 파일 SHA-256, target, profile, 기능 목록을 기록합니다. | |
| 19 | 추가: | |
| 20 | 추가: 설치 파일을 더블클릭하면 현재 사용자의 LocalAppData/Programs/Zipelo-Dev에 | |
| 21 | 추가: Zipelo.exe, zipelo-archive-worker.exe, MIT LICENSE, BUILD-INFO.json과 제거 프로그램을 설치합니다. | |
| 22 | 추가: 설치 경로는 위 위치로 고정되며 명령행 /D로 다른 위치를 지정해도 파일 쓰기 전에 고정 위치를 적용합니다. | |
| 23 | 추가: 설치와 제거는 같은 경로 상수를 사용합니다. | |
| 24 | 추가: 기존 폴더나 등록이 있으면 중단하며 덮어쓰기 업데이트는 지원하지 않습니다. | |
| 25 | 추가: 시작 메뉴에 Zipelo 개발판 바로가기를 추가합니다. | |
| 26 | 추가: | |
| 27 | 추가: 마지막 화면의 [적용]을 누르면 HKCU의 ZipeloDev.Archive ProgID와 RegisteredApplications에 | |
| 28 | 추가: .zip, .tar, .gz, .tgz 연결 후보를 등록하고 ms-settings:defaultapps를 엽니다. | |
| 29 | 추가: .tar.gz는 마지막 확장자 .gz로 연결됩니다. 기본 앱은 사용자가 Windows 설정에서 직접 선택합니다. | |
| 30 | 추가: JAR, RAR, 7z는 등록하지 않습니다. [마침]만 누르면 연결 후보를 등록하지 않습니다. | |
| 31 | 추가: 관리자 권한, HKLM, UserChoice 변경을 사용하지 않습니다. | |
| 32 | 추가: 제거 시 알려진 앱 파일과 등록 값만 정리하며 폴더 전체를 재귀 삭제하지 않습니다. | |
| 33 | 추가: 실행 파일 삭제 실패 시 등록과 제거 프로그램을 보존하여 재시도할 수 있습니다. | |
| 34 | 추가: | |
| 35 | 추가: 현재는 개발 검증용입니다. PR62 화면의 실제 작업자 연결, Windows에서의 설치/제거와 설정 실행, | |
| 36 | 추가: 지원 형식별 실제 파일 열기, 재설치/권한 실패/잠긴 파일 검증, 포함 의존성의 배포 고지 검토는 남아 있습니다. | |
| 37 | 추가: 이번 EXE 생성만으로 해당 항목을 인증하거나 출시하지 않습니다. | |
| 38 | 추가: Windows 실행 검증 전에는 README 다운로드 버튼이나 release에 배포하지 않습니다. | |
| 39 | 추가: | |
| 40 | 추가: 검증은 저장소 루트에서 python3 tests/ci/run_rust.py local을 실행하고 위 명령으로 | |
| 41 | 추가: 실제 앱과 작업자를 교차 빌드하여 NSIS를 컴파일합니다. BUILD-INFO.json과 설치 EXE의 | |
| 42 | 추가: 해시를 함께 확인합니다. NSIS 부트스트랩은 32비트 PE일 수 있으며 설치되는 두 앱은 x64 PE입니다. | |
| 43 | 추가: | |
| 44 | 추가: 연결 등록은 [Microsoft 기본 프로그램 문서](https://learn.microsoft.com/en-us/windows/win32/shell/default-programs)의 | |
| 45 | 추가: Capabilities/RegisteredApplications 구조를 사용하며, | |
| 46 | 추가: [Windows 기본 앱 설정 열기](https://learn.microsoft.com/en-us/windows/apps/develop/launch/launch-default-apps-settings)의 | |
| 47 | 추가: ms-settings URI를 사용합니다. |
| @@ -0,0 +1,104 @@ | ||
| 1 | 추가: """Rust 앱과 작업자를 교차 빌드해 Windows 개발용 설치 파일을 생성함.""" | |
| 2 | 추가: | |
| 3 | 추가: import argparse | |
| 4 | 추가: import hashlib | |
| 5 | 추가: import json | |
| 6 | 추가: import os | |
| 7 | 추가: from pathlib import Path | |
| 8 | 추가: import shutil | |
| 9 | 추가: import struct | |
| 10 | 추가: import subprocess | |
| 11 | 추가: | |
| 12 | 추가: ROOT = Path(__file__).resolve().parents[3] | |
| 13 | 추가: TARGET = "x86_64-pc-windows-gnu" | |
| 14 | 추가: | |
| 15 | 추가: | |
| 16 | 추가: def pe_machine(path): | |
| 17 | 추가: with Path(path).open("rb") as stream: | |
| 18 | 추가: header = stream.read(64) | |
| 19 | 추가: if len(header) != 64 or header[:2] != b"MZ": | |
| 20 | 추가: raise ValueError("PE 실행 파일이 아님") | |
| 21 | 추가: stream.seek(struct.unpack_from("<I", header, 60)[0]) | |
| 22 | 추가: signature = stream.read(6) | |
| 23 | 추가: if len(signature) != 6 or signature[:4] != b"PE\0\0": | |
| 24 | 추가: raise ValueError("PE 헤더가 잘못됨") | |
| 25 | 추가: return struct.unpack_from("<H", signature, 4)[0] | |
| 26 | 추가: | |
| 27 | 추가: | |
| 28 | 추가: def build_binary(manifest, binary, target_dir, profile, features=()): | |
| 29 | 추가: manifest = Path(manifest).resolve(strict=True) | |
| 30 | 추가: commit = subprocess.check_output( | |
| 31 | 추가: ["git", "-C", str(manifest.parent), "rev-parse", "HEAD"], text=True | |
| 32 | 추가: ).strip() | |
| 33 | 추가: dirty = subprocess.check_output( | |
| 34 | 추가: ["git", "-C", str(manifest.parent), "status", "--porcelain"], text=True | |
| 35 | 추가: ) | |
| 36 | 추가: if dirty.strip(): | |
| 37 | 추가: raise ValueError("소스에 커밋하지 않은 변경이 있음") | |
| 38 | 추가: # 작업 복사본 간 mtime 기반 캐시 혼합을 방지함. | |
| 39 | 추가: target_dir = target_dir / binary / commit | |
| 40 | 추가: command = ["cargo", "+1.99.1", "build", "--locked", "--manifest-path", str(manifest), | |
| 41 | 추가: "--target", TARGET, "--target-dir", str(target_dir), "--profile", profile, | |
| 42 | 추가: "--bin", binary] | |
| 43 | 추가: if features: | |
| 44 | 추가: command += ["--features", ",".join(features)] | |
| 45 | 추가: environment = dict(os.environ) | |
| 46 | 추가: linker = environment.get("CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER") | |
| 47 | 추가: linker = linker or shutil.which("x86_64-w64-mingw32-gcc") or shutil.which("x86_64-w64-mingw32-gcc-posix") | |
| 48 | 추가: if not linker or not shutil.which(linker): | |
| 49 | 추가: raise ValueError("MinGW-w64 교차 링커를 찾지 못함") | |
| 50 | 추가: environment["CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER"] = linker | |
| 51 | 추가: subprocess.run(command, env=environment, check=True) | |
| 52 | 추가: output = target_dir / TARGET / ("debug" if profile == "dev" else profile) / (binary + ".exe") | |
| 53 | 추가: if pe_machine(output) != 0x8664: | |
| 54 | 추가: raise ValueError("x64 Windows 실행 파일이 아님") | |
| 55 | 추가: current_commit = subprocess.check_output( | |
| 56 | 추가: ["git", "-C", str(manifest.parent), "rev-parse", "HEAD"], text=True | |
| 57 | 추가: ).strip() | |
| 58 | 추가: dirty = subprocess.check_output( | |
| 59 | 추가: ["git", "-C", str(manifest.parent), "status", "--porcelain"], text=True | |
| 60 | 추가: ) | |
| 61 | 추가: if current_commit != commit or dirty.strip(): | |
| 62 | 추가: raise ValueError("빌드 중 소스가 바뀜") | |
| 63 | 추가: return output, {"commit": commit, "sha256": hashlib.sha256(output.read_bytes()).hexdigest(), | |
| 64 | 추가: "binary": binary, "features": list(features)} | |
| 65 | 추가: | |
| 66 | 추가: | |
| 67 | 추가: def build(args): | |
| 68 | 추가: output = Path(args.output).resolve() | |
| 69 | 추가: output.mkdir(parents=True, exist_ok=False) | |
| 70 | 추가: target_dir = Path(args.target_dir).resolve() | |
| 71 | 추가: records = {} | |
| 72 | 추가: payload = output / "payload" | |
| 73 | 추가: payload.mkdir() | |
| 74 | 추가: for name, manifest, binary, features in ( | |
| 75 | 추가: ("Zipelo.exe", args.app_manifest, "zipelo-ui-memory-app", ("ui",)), | |
| 76 | 추가: ("zipelo-archive-worker.exe", args.worker_manifest, "zipelo-archive-worker", ()), | |
| 77 | 추가: ): | |
| 78 | 추가: source, records[name] = build_binary(manifest, binary, target_dir, args.profile, features) | |
| 79 | 추가: shutil.copyfile(source, payload / name) | |
| 80 | 추가: shutil.copyfile(ROOT / "LICENSE", payload / "LICENSE") | |
| 81 | 추가: records = {"development_only": True, "windows_execution_verified": False, | |
| 82 | 추가: "profile": args.profile, "target": TARGET, "files": records} | |
| 83 | 추가: (payload / "BUILD-INFO.json").write_text(json.dumps(records, indent=4) + "\n", encoding="utf-8") | |
| 84 | 추가: shutil.copyfile(Path(__file__).with_name("installer.nsi"), output / "installer.nsi") | |
| 85 | 추가: subprocess.run(["makensis", "-WX", "installer.nsi"], cwd=output, check=True) | |
| 86 | 추가: installer = output / "Zipelo-0.1.0-dev-windows-x64-setup.exe" | |
| 87 | 추가: if pe_machine(installer) not in (0x14C, 0x8664): | |
| 88 | 추가: raise ValueError("NSIS 설치 실행 파일이 아님") | |
| 89 | 추가: print(installer) | |
| 90 | 추가: print("SHA-256 " + hashlib.sha256(installer.read_bytes()).hexdigest()) | |
| 91 | 추가: | |
| 92 | 추가: | |
| 93 | 추가: def main(): | |
| 94 | 추가: parser = argparse.ArgumentParser(description=__doc__) | |
| 95 | 추가: parser.add_argument("--app-manifest", required=True) | |
| 96 | 추가: parser.add_argument("--worker-manifest", required=True) | |
| 97 | 추가: parser.add_argument("--output", required=True) | |
| 98 | 추가: parser.add_argument("--target-dir", required=True) | |
| 99 | 추가: parser.add_argument("--profile", choices=("dev", "release"), default="release") | |
| 100 | 추가: build(parser.parse_args()) | |
| 101 | 추가: | |
| 102 | 추가: | |
| 103 | 추가: if __name__ == "__main__": | |
| 104 | 추가: main() |
| @@ -0,0 +1,264 @@ | ||
| 1 | 추가: Unicode true | |
| 2 | 추가: !include "MUI2.nsh" | |
| 3 | 추가: !include "nsDialogs.nsh" | |
| 4 | 추가: !include "LogicLib.nsh" | |
| 5 | 추가: !include "x64.nsh" | |
| 6 | 추가: !include "FileFunc.nsh" | |
| 7 | 추가: Name "Zipelo 개발판" | |
| 8 | 추가: OutFile "Zipelo-0.1.0-dev-windows-x64-setup.exe" | |
| 9 | 추가: !define INSTALLROOT "$LOCALAPPDATA\Programs\Zipelo-Dev" | |
| 10 | 추가: InstallDir "${INSTALLROOT}" | |
| 11 | 추가: RequestExecutionLevel user | |
| 12 | 추가: SetCompressor /SOLID lzma | |
| 13 | 추가: SetOverwrite off | |
| 14 | 추가: AllowSkipFiles off | |
| 15 | 추가: ShowInstDetails show | |
| 16 | 추가: !define MUI_ABORTWARNING | |
| 17 | 추가: !define MUI_CUSTOMFUNCTION_ABORT Rollback | |
| 18 | 추가: !insertmacro MUI_PAGE_WELCOME | |
| 19 | 추가: !insertmacro MUI_PAGE_INSTFILES | |
| 20 | 추가: Page custom FinishCreate | |
| 21 | 추가: !insertmacro MUI_UNPAGE_CONFIRM | |
| 22 | 추가: !insertmacro MUI_UNPAGE_INSTFILES | |
| 23 | 추가: !insertmacro MUI_LANGUAGE "Korean" | |
| 24 | 추가: Var Dialog | |
| 25 | 추가: Var ApplyButton | |
| 26 | 추가: Var Mutex | |
| 27 | 추가: Var RootOwned | |
| 28 | 추가: Var ShortcutOwned | |
| 29 | 추가: Var UninstallOwned | |
| 30 | 추가: Var InstallComplete | |
| 31 | 추가: !define APPKEY "Software\Zipelo-Dev" | |
| 32 | 추가: !define PROGKEY "Software\Classes\ZipeloDev.Archive" | |
| 33 | 추가: !define UNKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Zipelo-Dev" | |
| 34 | 추가: | |
| 35 | 추가: Function .onInit | |
| 36 | 추가: ${IfNot} ${RunningX64} | |
| 37 | 추가: MessageBox MB_OK|MB_ICONSTOP "64비트 Windows가 필요합니다." | |
| 38 | 추가: Abort | |
| 39 | 추가: ${EndIf} | |
| 40 | 추가: SetShellVarContext current | |
| 41 | 추가: SetRegView 64 | |
| 42 | 추가: System::Call 'kernel32::SetLastError(i 0)' | |
| 43 | 추가: System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e' | |
| 44 | 추가: Pop $1 | |
| 45 | 추가: StrCpy $Mutex $0 | |
| 46 | 추가: ${If} $0 == 0 | |
| 47 | 추가: ${OrIf} $1 != 0 | |
| 48 | 추가: MessageBox MB_OK "다른 설치나 제거를 마친 뒤 다시 실행하세요." | |
| 49 | 추가: Abort | |
| 50 | 추가: ${EndIf} | |
| 51 | 추가: FunctionEnd | |
| 52 | 추가: | |
| 53 | 추가: Section "Zipelo" | |
| 54 | 추가: ; /D로 바뀐 경로를 파일 쓰기 전에 고정하여 제거 경로와 일치시킴. | |
| 55 | 추가: StrCpy $INSTDIR "${INSTALLROOT}" | |
| 56 | 추가: ; 기존 설치와 등록을 덮어쓰지 않음. | |
| 57 | 추가: IfFileExists "$INSTDIR" failed | |
| 58 | 추가: System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${APPKEY}", i 0, i 0x20119, *p.r1) i.r0' | |
| 59 | 추가: ${If} $0 == 0 | |
| 60 | 추가: System::Call 'advapi32::RegCloseKey(p r1)' | |
| 61 | 추가: Goto failed | |
| 62 | 추가: ${ElseIf} $0 != 2 | |
| 63 | 추가: Goto failed | |
| 64 | 추가: ${EndIf} | |
| 65 | 추가: System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${PROGKEY}", i 0, i 0x20119, *p.r1) i.r0' | |
| 66 | 추가: ${If} $0 == 0 | |
| 67 | 추가: System::Call 'advapi32::RegCloseKey(p r1)' | |
| 68 | 추가: Goto failed | |
| 69 | 추가: ${ElseIf} $0 != 2 | |
| 70 | 추가: Goto failed | |
| 71 | 추가: ${EndIf} | |
| 72 | 추가: System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "${UNKEY}", i 0, i 0x20119, *p.r1) i.r0' | |
| 73 | 추가: ${If} $0 == 0 | |
| 74 | 추가: System::Call 'advapi32::RegCloseKey(p r1)' | |
| 75 | 추가: Goto failed | |
| 76 | 추가: ${ElseIf} $0 != 2 | |
| 77 | 추가: Goto failed | |
| 78 | 추가: ${EndIf} | |
| 79 | 추가: ; 공유 등록 값이 이미 있으면 형식과 관계없이 보존함. | |
| 80 | 추가: System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "Software\RegisteredApplications", i 0, i 0x20119, *p.r1) i.r0' | |
| 81 | 추가: ${If} $0 == 0 | |
| 82 | 추가: System::Call 'advapi32::RegQueryValueExW(p r1, w "Zipelo 개발판", p 0, p 0, p 0, p 0) i.r2' | |
| 83 | 추가: System::Call 'advapi32::RegCloseKey(p r1)' | |
| 84 | 추가: ${If} $2 != 2 | |
| 85 | 추가: Goto failed | |
| 86 | 추가: ${EndIf} | |
| 87 | 추가: ${ElseIf} $0 != 2 | |
| 88 | 추가: Goto failed | |
| 89 | 추가: ${EndIf} | |
| 90 | 추가: IfFileExists "$SMPROGRAMS\Zipelo 개발판.lnk" failed | |
| 91 | 추가: ClearErrors | |
| 92 | 추가: CreateDirectory "$LOCALAPPDATA\Programs" | |
| 93 | 추가: IfErrors failed | |
| 94 | 추가: System::Call 'kernel32::CreateDirectoryW(w "$INSTDIR", p 0) i.r0' | |
| 95 | 추가: IntCmp $0 0 failed | |
| 96 | 추가: StrCpy $RootOwned 1 | |
| 97 | 추가: SetOutPath "$INSTDIR" | |
| 98 | 추가: ClearErrors | |
| 99 | 추가: File "payload\Zipelo.exe" | |
| 100 | 추가: File "payload\zipelo-archive-worker.exe" | |
| 101 | 추가: File "payload\LICENSE" | |
| 102 | 추가: File "payload\BUILD-INFO.json" | |
| 103 | 추가: IfErrors failed | |
| 104 | 추가: WriteUninstaller "$INSTDIR\Uninstall.exe" | |
| 105 | 추가: IfErrors failed | |
| 106 | 추가: WriteINIStr "$INSTDIR\install.ini" "Zipelo" "Location" "$INSTDIR" | |
| 107 | 추가: IfErrors failed | |
| 108 | 추가: StrCpy $ShortcutOwned 1 | |
| 109 | 추가: CreateShortcut "$SMPROGRAMS\Zipelo 개발판.lnk" "$INSTDIR\Zipelo.exe" | |
| 110 | 추가: IfErrors failed | |
| 111 | 추가: StrCpy $UninstallOwned 1 | |
| 112 | 추가: WriteRegStr HKCU "${UNKEY}" "DisplayName" "Zipelo 개발판" | |
| 113 | 추가: WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0-dev" | |
| 114 | 추가: WriteRegStr HKCU "${UNKEY}" "UninstallString" '$\"$INSTDIR\Uninstall.exe$\"' | |
| 115 | 추가: IfErrors failed | |
| 116 | 추가: StrCpy $InstallComplete 1 | |
| 117 | 추가: Goto done | |
| 118 | 추가: failed: | |
| 119 | 추가: Call Rollback | |
| 120 | 추가: SetErrorLevel 1 | |
| 121 | 추가: MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 이번 설치 항목을 정리했으며, 사용 중이라 지우지 못한 항목은 상세 보기에서 확인하세요." | |
| 122 | 추가: Abort | |
| 123 | 추가: done: | |
| 124 | 추가: SectionEnd | |
| 125 | 추가: | |
| 126 | 추가: Function Rollback | |
| 127 | 추가: ${If} $InstallComplete == 1 | |
| 128 | 추가: ${OrIf} $RootOwned != 1 | |
| 129 | 추가: Return | |
| 130 | 추가: ${EndIf} | |
| 131 | 추가: SetOutPath "$TEMP" | |
| 132 | 추가: ${If} $ShortcutOwned == 1 | |
| 133 | 추가: Delete "$SMPROGRAMS\Zipelo 개발판.lnk" | |
| 134 | 추가: ${EndIf} | |
| 135 | 추가: ${If} $UninstallOwned == 1 | |
| 136 | 추가: DeleteRegValue HKCU "${UNKEY}" "DisplayName" | |
| 137 | 추가: DeleteRegValue HKCU "${UNKEY}" "DisplayVersion" | |
| 138 | 추가: DeleteRegValue HKCU "${UNKEY}" "UninstallString" | |
| 139 | 추가: DeleteRegKey /ifempty HKCU "${UNKEY}" | |
| 140 | 추가: ${EndIf} | |
| 141 | 추가: Delete "$INSTDIR\Zipelo.exe" | |
| 142 | 추가: Delete "$INSTDIR\zipelo-archive-worker.exe" | |
| 143 | 추가: Delete "$INSTDIR\LICENSE" | |
| 144 | 추가: Delete "$INSTDIR\BUILD-INFO.json" | |
| 145 | 추가: Delete "$INSTDIR\install.ini" | |
| 146 | 추가: Delete "$INSTDIR\Uninstall.exe" | |
| 147 | 추가: RMDir "$INSTDIR" | |
| 148 | 추가: StrCpy $RootOwned 0 | |
| 149 | 추가: FunctionEnd | |
| 150 | 추가: | |
| 151 | 추가: Function .onInstFailed | |
| 152 | 추가: Call Rollback | |
| 153 | 추가: SetErrorLevel 1 | |
| 154 | 추가: FunctionEnd | |
| 155 | 추가: | |
| 156 | 추가: Function FinishCreate | |
| 157 | 추가: GetDlgItem $0 $HWNDPARENT 1 | |
| 158 | 추가: SendMessage $0 ${WM_SETTEXT} 0 "STR:마침" | |
| 159 | 추가: GetDlgItem $0 $HWNDPARENT 3 | |
| 160 | 추가: EnableWindow $0 0 | |
| 161 | 추가: nsDialogs::Create 1018 | |
| 162 | 추가: Pop $Dialog | |
| 163 | 추가: ${If} $Dialog == error | |
| 164 | 추가: Abort | |
| 165 | 추가: ${EndIf} | |
| 166 | 추가: ${NSD_CreateLabel} 0 0 100% 28u "Zipelo 설치가 끝났습니다." | |
| 167 | 추가: Pop $0 | |
| 168 | 추가: ${NSD_CreateLabel} 0 32u 100% 40u "[적용]을 누르면 Zipelo를 연결 프로그램으로 등록하고 Windows 기본 앱 설정을 엽니다. 기본 앱은 설정에서 직접 선택하세요." | |
| 169 | 추가: Pop $0 | |
| 170 | 추가: ${NSD_CreateButton} 0 84u 100% 26u "적용" | |
| 171 | 추가: Pop $ApplyButton | |
| 172 | 추가: ${NSD_OnClick} $ApplyButton ApplyAssociations | |
| 173 | 추가: nsDialogs::Show | |
| 174 | 추가: FunctionEnd | |
| 175 | 추가: | |
| 176 | 추가: Function ApplyAssociations | |
| 177 | 추가: Pop $0 | |
| 178 | 추가: ClearErrors | |
| 179 | 추가: WriteRegStr HKCU "${PROGKEY}" "" "Zipelo 압축파일" | |
| 180 | 추가: WriteRegStr HKCU "${PROGKEY}\shell\open\command" "" '$\"$INSTDIR\Zipelo.exe$\" $\"%1$\"' | |
| 181 | 추가: WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationName" "Zipelo 개발판" | |
| 182 | 추가: WriteRegStr HKCU "${APPKEY}\Capabilities" "ApplicationDescription" "압축파일 열기와 풀기" | |
| 183 | 추가: WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" "ZipeloDev.Archive" | |
| 184 | 추가: WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" "ZipeloDev.Archive" | |
| 185 | 추가: WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" "ZipeloDev.Archive" | |
| 186 | 추가: WriteRegStr HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz" "ZipeloDev.Archive" | |
| 187 | 추가: WriteRegStr HKCU "Software\RegisteredApplications" "Zipelo 개발판" "${APPKEY}\Capabilities" | |
| 188 | 추가: IfErrors register_failed | |
| 189 | 추가: System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)' | |
| 190 | 추가: ExecShell "open" "ms-settings:defaultapps" | |
| 191 | 추가: IfErrors settings_failed | |
| 192 | 추가: Return | |
| 193 | 추가: register_failed: | |
| 194 | 추가: MessageBox MB_OK|MB_ICONSTOP "연결 프로그램을 등록하지 못했습니다. 쓰기 권한을 확인한 뒤 다시 적용하세요." | |
| 195 | 추가: Return | |
| 196 | 추가: settings_failed: | |
| 197 | 추가: MessageBox MB_OK "Windows 설정을 열지 못했습니다. 설정에서 앱 > 기본 앱을 직접 열어주세요." | |
| 198 | 추가: FunctionEnd | |
| 199 | 추가: | |
| 200 | 추가: Function un.onInit | |
| 201 | 추가: SetShellVarContext current | |
| 202 | 추가: SetRegView 64 | |
| 203 | 추가: System::Call 'kernel32::SetLastError(i 0)' | |
| 204 | 추가: System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e' | |
| 205 | 추가: Pop $1 | |
| 206 | 추가: StrCpy $Mutex $0 | |
| 207 | 추가: ${If} $0 == 0 | |
| 208 | 추가: ${OrIf} $1 != 0 | |
| 209 | 추가: Abort | |
| 210 | 추가: ${EndIf} | |
| 211 | 추가: StrCmp $INSTDIR "${INSTALLROOT}" 0 invalid | |
| 212 | 추가: ReadINIStr $0 "$INSTDIR\install.ini" "Zipelo" "Location" | |
| 213 | 추가: StrCmp $0 $INSTDIR 0 invalid | |
| 214 | 추가: Return | |
| 215 | 추가: invalid: | |
| 216 | 추가: MessageBox MB_OK|MB_ICONSTOP "설치 위치를 확인하지 못했습니다. 파일을 삭제하지 않습니다." | |
| 217 | 추가: Abort | |
| 218 | 추가: FunctionEnd | |
| 219 | 추가: | |
| 220 | 추가: Section "Uninstall" | |
| 221 | 추가: SetOutPath "$TEMP" | |
| 222 | 추가: ClearErrors | |
| 223 | 추가: Delete "$INSTDIR\Zipelo.exe" | |
| 224 | 추가: Delete "$INSTDIR\zipelo-archive-worker.exe" | |
| 225 | 추가: IfErrors uninstall_failed | |
| 226 | 추가: Delete "$INSTDIR\LICENSE" | |
| 227 | 추가: Delete "$INSTDIR\BUILD-INFO.json" | |
| 228 | 추가: Delete "$SMPROGRAMS\Zipelo 개발판.lnk" | |
| 229 | 추가: IfErrors uninstall_failed | |
| 230 | 추가: ; 자신이 등록한 값만 제거하고 다른 파일과 키를 보존함. | |
| 231 | 추가: ReadRegStr $0 HKCU "Software\RegisteredApplications" "Zipelo 개발판" | |
| 232 | 추가: ${If} $0 == "${APPKEY}\Capabilities" | |
| 233 | 추가: DeleteRegValue HKCU "Software\RegisteredApplications" "Zipelo 개발판" | |
| 234 | 추가: ${EndIf} | |
| 235 | 추가: DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" | |
| 236 | 추가: DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" | |
| 237 | 추가: DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" | |
| 238 | 추가: DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tgz" | |
| 239 | 추가: DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationName" | |
| 240 | 추가: DeleteRegValue HKCU "${APPKEY}\Capabilities" "ApplicationDescription" | |
| 241 | 추가: DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities\FileAssociations" | |
| 242 | 추가: DeleteRegKey /ifempty HKCU "${APPKEY}\Capabilities" | |
| 243 | 추가: DeleteRegKey /ifempty HKCU "${APPKEY}" | |
| 244 | 추가: DeleteRegValue HKCU "${PROGKEY}\shell\open\command" "" | |
| 245 | 추가: DeleteRegValue HKCU "${PROGKEY}" "" | |
| 246 | 추가: DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open\command" | |
| 247 | 추가: DeleteRegKey /ifempty HKCU "${PROGKEY}\shell\open" | |
| 248 | 추가: DeleteRegKey /ifempty HKCU "${PROGKEY}\shell" | |
| 249 | 추가: DeleteRegKey /ifempty HKCU "${PROGKEY}" | |
| 250 | 추가: DeleteRegValue HKCU "${UNKEY}" "DisplayName" | |
| 251 | 추가: DeleteRegValue HKCU "${UNKEY}" "DisplayVersion" | |
| 252 | 추가: DeleteRegValue HKCU "${UNKEY}" "UninstallString" | |
| 253 | 추가: DeleteRegKey /ifempty HKCU "${UNKEY}" | |
| 254 | 추가: Delete "$INSTDIR\install.ini" | |
| 255 | 추가: Delete "$INSTDIR\Uninstall.exe" | |
| 256 | 추가: RMDir "$INSTDIR" | |
| 257 | 추가: System::Call 'shell32::SHChangeNotify(i 0x8000000, i 0, p 0, p 0)' | |
| 258 | 추가: Goto un_done | |
| 259 | 추가: uninstall_failed: | |
| 260 | 추가: SetErrorLevel 1 | |
| 261 | 추가: MessageBox MB_OK|MB_ICONSTOP "Zipelo와 작업자를 닫은 뒤 제거 프로그램을 다시 실행하세요." | |
| 262 | 추가: Abort | |
| 263 | 추가: un_done: | |
| 264 | 추가: SectionEnd |
| @@ -0,0 +1,124 @@ | ||
| 1 | 추가: import argparse | |
| 2 | 추가: import importlib.util | |
| 3 | 추가: from pathlib import Path | |
| 4 | 추가: import struct | |
| 5 | 추가: import re | |
| 6 | 추가: import shutil | |
| 7 | 추가: import subprocess | |
| 8 | 추가: import tempfile | |
| 9 | 추가: import sys | |
| 10 | 추가: from unittest.mock import patch | |
| 11 | 추가: import unittest | |
| 12 | 추가: | |
| 13 | 추가: ROOT = Path(__file__).resolve().parents[2] | |
| 14 | 추가: SPEC = importlib.util.spec_from_file_location("windows_installer", ROOT / "packaging/windows/rust/build.py") | |
| 15 | 추가: MODULE = importlib.util.module_from_spec(SPEC) | |
| 16 | 추가: SPEC.loader.exec_module(MODULE) | |
| 17 | 추가: | |
| 18 | 추가: | |
| 19 | 추가: class InstallerInputTests(unittest.TestCase): | |
| 20 | 추가: def setUp(self): | |
| 21 | 추가: runs = ROOT / "tests/windows-installer/runs" | |
| 22 | 추가: runs.mkdir(parents=True, exist_ok=True) | |
| 23 | 추가: self.directory = tempfile.TemporaryDirectory(dir=runs) | |
| 24 | 추가: self.addCleanup(self.directory.cleanup) | |
| 25 | 추가: self.root = Path(self.directory.name) | |
| 26 | 추가: | |
| 27 | 추가: def test_truncated_and_non_pe_payloads_are_rejected(self): | |
| 28 | 추가: for content in (b"", b"MZ", b"not an executable" * 8, | |
| 29 | 추가: b"MZ" + bytes(58) + struct.pack("<I", 65535)): | |
| 30 | 추가: payload = self.root / "invalid.exe" | |
| 31 | 추가: payload.write_bytes(content) | |
| 32 | 추가: with self.assertRaises(ValueError): | |
| 33 | 추가: MODULE.pe_machine(payload) | |
| 34 | 추가: | |
| 35 | 추가: def test_x64_coff_machine_is_read_from_pe_offset(self): | |
| 36 | 추가: payload = self.root / "header.exe" | |
| 37 | 추가: payload.write_bytes(b"MZ" + bytes(58) + struct.pack("<I", 128) | |
| 38 | 추가: + bytes(64) + b"PE\0\0" + struct.pack("<H", 0x8664)) | |
| 39 | 추가: self.assertEqual(MODULE.pe_machine(payload), 0x8664) | |
| 40 | 추가: payload.write_bytes(payload.read_bytes()[:128] + b"badPE!") | |
| 41 | 추가: with self.assertRaises(ValueError): | |
| 42 | 추가: MODULE.pe_machine(payload) | |
| 43 | 추가: | |
| 44 | 추가: def test_existing_output_is_preserved_before_any_build(self): | |
| 45 | 추가: output = self.root / "output" | |
| 46 | 추가: output.mkdir() | |
| 47 | 추가: sentinel = output / "user-data" | |
| 48 | 추가: sentinel.write_bytes(b"preserve") | |
| 49 | 추가: args = argparse.Namespace(output=output, target_dir=self.root / "target") | |
| 50 | 추가: with self.assertRaises(FileExistsError): | |
| 51 | 추가: MODULE.build(args) | |
| 52 | 추가: self.assertEqual(sentinel.read_bytes(), b"preserve") | |
| 53 | 추가: self.assertEqual(list(output.iterdir()), [sentinel]) | |
| 54 | 추가: self.assertFalse(args.target_dir.exists()) | |
| 55 | 추가: | |
| 56 | 추가: @unittest.skipUnless(shutil.which("makensis"), "NSIS가 설치되지 않음") | |
| 57 | 추가: def test_nsis_compiles_payloads_and_finish_callbacks(self): | |
| 58 | 추가: payload = self.root / "payload" | |
| 59 | 추가: payload.mkdir() | |
| 60 | 추가: for name in ("Zipelo.exe", "zipelo-archive-worker.exe", "LICENSE", "BUILD-INFO.json"): | |
| 61 | 추가: (payload / name).write_bytes(b"compile-only test fixture") | |
| 62 | 추가: shutil.copyfile(ROOT / "packaging/windows/rust/installer.nsi", self.root / "installer.nsi") | |
| 63 | 추가: completed = subprocess.run(["makensis", "-WX", "installer.nsi"], cwd=self.root, | |
| 64 | 추가: stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) | |
| 65 | 추가: self.assertEqual(completed.returncode, 0, completed.stdout) | |
| 66 | 추가: installer = self.root / "Zipelo-0.1.0-dev-windows-x64-setup.exe" | |
| 67 | 추가: self.assertIn(MODULE.pe_machine(installer), (0x14C, 0x8664)) | |
| 68 | 추가: self.assertGreater(installer.stat().st_size, 100000) | |
| 69 | 추가: | |
| 70 | 추가: def test_command_line_directory_is_reset_before_install_side_effects(self): | |
| 71 | 추가: source = (ROOT / "packaging/windows/rust/installer.nsi").read_text() | |
| 72 | 추가: section = source.split('Section "Zipelo"', 1)[1].split("SectionEnd", 1)[0] | |
| 73 | 추가: commands = [line.strip() for line in section.splitlines() | |
| 74 | 추가: if line.strip() and not line.strip().startswith(";")] | |
| 75 | 추가: self.assertEqual(commands[0], 'StrCpy $INSTDIR "${INSTALLROOT}"') | |
| 76 | 추가: root = re.search(r'^!define INSTALLROOT "([^"\n]+)"$', source, re.MULTILINE) | |
| 77 | 추가: self.assertIsNotNone(root) | |
| 78 | 추가: self.assertEqual(root.group(1), "$LOCALAPPDATA\\Programs\\Zipelo-Dev") | |
| 79 | 추가: self.assertIn('InstallDir "${INSTALLROOT}"', source) | |
| 80 | 추가: uninstaller = source.split("Function un.onInit", 1)[1].split("FunctionEnd", 1)[0] | |
| 81 | 추가: self.assertIn('StrCmp $INSTDIR "${INSTALLROOT}" 0 invalid', uninstaller) | |
| 82 | 추가: | |
| 83 | 추가: def test_source_commit_change_cannot_reuse_an_old_binary(self): | |
| 84 | 추가: repo = self.root / "source" | |
| 85 | 추가: repo.mkdir() | |
| 86 | 추가: manifest = repo / "Cargo.toml" | |
| 87 | 추가: manifest.write_text("fixture") | |
| 88 | 추가: real_run = subprocess.run | |
| 89 | 추가: environment = dict(MODULE.os.environ, GIT_AUTHOR_NAME="Zipelo test", | |
| 90 | 추가: GIT_AUTHOR_EMAIL="[email protected]", GIT_COMMITTER_NAME="Zipelo test", | |
| 91 | 추가: GIT_COMMITTER_EMAIL="[email protected]") | |
| 92 | 추가: | |
| 93 | 추가: def git(*args): | |
| 94 | 추가: real_run(["git", *args], cwd=repo, env=environment, check=True, | |
| 95 | 추가: stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| 96 | 추가: | |
| 97 | 추가: git("init", "-b", "features/installer-fixture") | |
| 98 | 추가: git("add", ".") | |
| 99 | 추가: git("commit", "-m", "첫 시험 소스를 기록함") | |
| 100 | 추가: | |
| 101 | 추가: def cached_compiler(command, **options): | |
| 102 | 추가: if command[0] != "cargo": | |
| 103 | 추가: return real_run(command, **options) | |
| 104 | 추가: target = Path(command[command.index("--target-dir") + 1]) | |
| 105 | 추가: output = target / MODULE.TARGET / "debug/fixture.exe" | |
| 106 | 추가: output.parent.mkdir(parents=True, exist_ok=True) | |
| 107 | 추가: if not output.exists(): | |
| 108 | 추가: header = b"MZ" + bytes(58) + struct.pack("<I", 128) + bytes(64) | |
| 109 | 추가: output.write_bytes(header + b"PE\0\0" + struct.pack("<H", 0x8664) | |
| 110 | 추가: + manifest.read_bytes()) | |
| 111 | 추가: return subprocess.CompletedProcess(command, 0) | |
| 112 | 추가: | |
| 113 | 추가: with patch.dict(MODULE.os.environ, {"CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER": sys.executable}): | |
| 114 | 추가: with patch.object(MODULE.subprocess, "run", side_effect=cached_compiler): | |
| 115 | 추가: first, first_record = MODULE.build_binary(manifest, "fixture", self.root / "target", "dev") | |
| 116 | 추가: manifest.write_text("changed fixture") | |
| 117 | 추가: git("add", ".") | |
| 118 | 추가: git("commit", "-m", "변경된 시험 소스를 기록함") | |
| 119 | 추가: with patch.object(MODULE.subprocess, "run", side_effect=cached_compiler): | |
| 120 | 추가: second, second_record = MODULE.build_binary(manifest, "fixture", self.root / "target", "dev") | |
| 121 | 추가: self.assertNotEqual(first_record["commit"], second_record["commit"]) | |
| 122 | 추가: self.assertNotEqual(first_record["sha256"], second_record["sha256"]) | |
| 123 | 추가: self.assertTrue(second.read_bytes().endswith(b"changed fixture")) | |
| 124 | 추가: self.assertTrue(first.read_bytes().endswith(b"fixture")) |
| @@ -0,0 +1 @@ | ||
| 1 | 추가: runs/ |
| @@ -0,0 +1,107 @@ | ||
| 1 | 추가: # This file is automatically @generated by Cargo. | |
| 2 | 추가: # It is not intended for manual editing. | |
| 3 | 추가: version = 4 | |
| 4 | 추가: | |
| 5 | 추가: [[package]] | |
| 6 | 추가: name = "block-buffer" | |
| 7 | 추가: version = "0.10.4" | |
| 8 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | 추가: checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | |
| 10 | 추가: dependencies = [ | |
| 11 | 추가: "generic-array", | |
| 12 | 추가: ] | |
| 13 | 추가: | |
| 14 | 추가: [[package]] | |
| 15 | 추가: name = "cfg-if" | |
| 16 | 추가: version = "1.0.5" | |
| 17 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 18 | 추가: checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" | |
| 19 | 추가: | |
| 20 | 추가: [[package]] | |
| 21 | 추가: name = "cpufeatures" | |
| 22 | 추가: version = "0.2.17" | |
| 23 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 24 | 추가: checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" | |
| 25 | 추가: dependencies = [ | |
| 26 | 추가: "libc", | |
| 27 | 추가: ] | |
| 28 | 추가: | |
| 29 | 추가: [[package]] | |
| 30 | 추가: name = "crypto-common" | |
| 31 | 추가: version = "0.1.7" | |
| 32 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 33 | 추가: checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" | |
| 34 | 추가: dependencies = [ | |
| 35 | 추가: "generic-array", | |
| 36 | 추가: "typenum", | |
| 37 | 추가: ] | |
| 38 | 추가: | |
| 39 | 추가: [[package]] | |
| 40 | 추가: name = "digest" | |
| 41 | 추가: version = "0.10.7" | |
| 42 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 43 | 추가: checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | |
| 44 | 추가: dependencies = [ | |
| 45 | 추가: "block-buffer", | |
| 46 | 추가: "crypto-common", | |
| 47 | 추가: ] | |
| 48 | 추가: | |
| 49 | 추가: [[package]] | |
| 50 | 추가: name = "generic-array" | |
| 51 | 추가: version = "0.14.7" | |
| 52 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 53 | 추가: checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | |
| 54 | 추가: dependencies = [ | |
| 55 | 추가: "typenum", | |
| 56 | 추가: "version_check", | |
| 57 | 추가: ] | |
| 58 | 추가: | |
| 59 | 추가: [[package]] | |
| 60 | 추가: name = "libc" | |
| 61 | 추가: version = "0.2.191" | |
| 62 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 63 | 추가: checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" | |
| 64 | 추가: | |
| 65 | 추가: [[package]] | |
| 66 | 추가: name = "sha2" | |
| 67 | 추가: version = "0.10.9" | |
| 68 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 69 | 추가: checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" | |
| 70 | 추가: dependencies = [ | |
| 71 | 추가: "cfg-if", | |
| 72 | 추가: "cpufeatures", | |
| 73 | 추가: "digest", | |
| 74 | 추가: ] | |
| 75 | 추가: | |
| 76 | 추가: [[package]] | |
| 77 | 추가: name = "typenum" | |
| 78 | 추가: version = "1.20.1" | |
| 79 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 80 | 추가: checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | |
| 81 | 추가: | |
| 82 | 추가: [[package]] | |
| 83 | 추가: name = "version_check" | |
| 84 | 추가: version = "0.9.5" | |
| 85 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 86 | 추가: checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | |
| 87 | 추가: | |
| 88 | 추가: [[package]] | |
| 89 | 추가: name = "zipelo-archive-worker" | |
| 90 | 추가: version = "0.1.0" | |
| 91 | 추가: dependencies = [ | |
| 92 | 추가: "sha2", | |
| 93 | 추가: "zlib-rs", | |
| 94 | 추가: ] | |
| 95 | 추가: | |
| 96 | 추가: [[package]] | |
| 97 | 추가: name = "zipelo-real-worker-probe" | |
| 98 | 추가: version = "0.1.0" | |
| 99 | 추가: dependencies = [ | |
| 100 | 추가: "zipelo-archive-worker", | |
| 101 | 추가: ] | |
| 102 | 추가: | |
| 103 | 추가: [[package]] | |
| 104 | 추가: name = "zlib-rs" | |
| 105 | 추가: version = "0.6.8" | |
| 106 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 107 | 추가: checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" |
| @@ -0,0 +1,19 @@ | ||
| 1 | 추가: [package] | |
| 2 | 추가: name = "zipelo-real-worker-probe" | |
| 3 | 추가: version = "0.1.0" | |
| 4 | 추가: edition = "2024" | |
| 5 | 추가: rust-version = "1.99" | |
| 6 | 추가: license = "MIT" | |
| 7 | 추가: publish = false | |
| 8 | 추가: autotests = false | |
| 9 | 추가: | |
| 10 | 추가: [workspace] | |
| 11 | 추가: | |
| 12 | 추가: [dependencies] | |
| 13 | 추가: worker_protocol = { package = "zipelo-archive-worker", path = "../../experiments/rust-archive-worker" } | |
| 14 | 추가: | |
| 15 | 추가: [[bin]] | |
| 16 | 추가: name = "zipelo-real-worker-probe" | |
| 17 | 추가: path = "probe.rs" | |
| 18 | 추가: test = false | |
| 19 | 추가: bench = false |
| @@ -0,0 +1,52 @@ | ||
| 1 | 추가: # 실제 작업자와 화면 연결 시험 | |
| 2 | 추가: | |
| 3 | 추가: 기본 앱은 실행 파일과 같은 폴더의 zipelo-archive-worker(Windows는 .exe)를 실행함. | |
| 4 | 추가: PATH나 현재 작업 폴더에서 임의 작업자를 검색하지 않음. ui-fixture와 --ui-fixture가 | |
| 5 | 추가: 모두 지정된 경우에만 기존 가짜 작업자를 사용함. | |
| 6 | 추가: | |
| 7 | 추가: 클라이언트는 작업자 crate의 protocol과 wire codec을 재사용하며 압축 처리와 파일 접근은 | |
| 8 | 추가: 별도 작업자 프로세스에서 수행함. UI에서 파이프 쓰기를 기다리지 않도록 8프레임 요청 큐와 | |
| 9 | 추가: 64이벤트 응답 큐를 사용함. 파이프 입출력과 child wait는 백그라운드에서 처리함. | |
| 10 | 추가: 정상 종료에는 Terminal, 양쪽 EOF와 child wait를 모두 확인함. 통신 오류는 성공으로 | |
| 11 | 추가: 표시하지 않으며, 오류 경로에서는 child 회수와 모든 파이프 스레드/핸들 정리가 끝났다는 | |
| 12 | 추가: 명시적 완료 신호까지 확인함. 연결이 예외적으로 폐기돼도 소유한 자식을 종료하고 회수함. | |
| 13 | 추가: 310초 제한 시간을 넘긴 작업자도 종료와 회수를 시도하며 완료 여부가 불명확하면 닫기를 허용하지 않음. | |
| 14 | 추가: | |
| 15 | 추가: ## 실행 | |
| 16 | 추가: | |
| 17 | 추가: 저장소 루트에서 로컬 실행기를 사용하면 실제 작업자와 probe 빌드가 화면 시험보다 먼저 수행됨. | |
| 18 | 추가: | |
| 19 | 추가: ```sh | |
| 20 | 추가: python3 tests/ci/run_rust.py local | |
| 21 | 추가: ``` | |
| 22 | 추가: | |
| 23 | 추가: 단독 시험에서는 같은 target 디렉터리에 먼저 두 실행 파일을 빌드할 것. | |
| 24 | 추가: | |
| 25 | 추가: ```sh | |
| 26 | 추가: export CARGO_TARGET_DIR="$PWD/tests/ci/target" | |
| 27 | 추가: cargo +1.99.1 build --locked --manifest-path experiments/rust-archive-worker/Cargo.toml | |
| 28 | 추가: cargo +1.99.1 build --locked --manifest-path tests/rust-app-real-worker/Cargo.toml | |
| 29 | 추가: cargo +1.99.1 test --locked --all-features --manifest-path experiments/rust-ui-memory-app/Cargo.toml --test real_worker | |
| 30 | 추가: ``` | |
| 31 | 추가: | |
| 32 | 추가: 기본 앱의 직접 실행도 같은 target 디렉터리를 사용할 것. | |
| 33 | 추가: | |
| 34 | 추가: ```sh | |
| 35 | 추가: cargo +1.99.1 run --locked --manifest-path experiments/rust-ui-memory-app/Cargo.toml --features ui -- /absolute/sample.zip | |
| 36 | 추가: ``` | |
| 37 | 추가: | |
| 38 | 추가: ## 확인 범위 | |
| 39 | 추가: | |
| 40 | 추가: - 합성 ZIP과 TAR.GZ를 실제 파일 열기 위젯으로 열고 목록을 확인한 뒤 풀기 버튼으로 해제함. | |
| 41 | 추가: - ZIP 만들기 위젯으로 합성 파일을 압축하고, 결과를 다시 열고 풀어 바이트가 같은지 확인함. | |
| 42 | 추가: - 위 세 흐름은 실제 작업자 EXE와 OS 파이프를 사용하며 Terminal, 양쪽 EOF, child wait와 연결 정리 순서를 관측함. | |
| 43 | 추가: - 누락된 작업자, 잘린 프레임, 잘못된 action 승인, Terminal 없는 조기 종료를 오류로 처리함. | |
| 44 | 추가: - 첫 Start 직렬화 실패도 실제 작업자 회수까지 대기함. Linux에서는 실행 중인 probe 연결을 폐기한 후 /proc에서 소유 자식이 사라진 것도 확인함. | |
| 45 | 추가: - flows.rs의 창은 egui Context에서 실제 위젯에 포인터와 키보드 이벤트를 전달함. 네이티브 OS 창/입력 자동화나 Windows 실행 검증은 아님. | |
| 46 | 추가: | |
| 47 | 추가: fixtures/는 generate.py의 Python 표준 라이브러리로 생성한 작은 합성 입력임. | |
| 48 | 추가: 정상 흐름은 제품 작업자를 사용하고, probe.rs는 통신 실패와 생명주기 시험 전용임. | |
| 49 | 추가: 사용자 자료를 읽거나 출력하지 않으며 모든 시험 출력은 이 폴더의 runs/ 안에만 생성함. | |
| 50 | 추가: 암호 ZIP, 대용량 성능, OS sandbox, 악성 파일 전체 검증과 Windows 실기는 이 시험의 범위 밖임. | |
| 51 | 추가: | |
| 52 | 추가: 취소와 종료 경합 회귀 시험은 실제 작업자에 List를 보낸 뒤 화면 poll 전에 취소하는 흐름을 100회 확인함. 취소 파이프 쓰기가 실패해도 검증된 Terminal과 성공 종료가 있으면 원래 결과를 보존하며, Terminal이 없는 조기 종료는 계속 실패로 처리함. 취소 쓰기 오류 판단을 미루어도 EOF와 child wait 전에는 닫기나 작업 교체를 허용하지 않음. |
바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기