디스크 공간 부족을 전용 오류로 구분함
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
39de76aa90830abfee777e7cc56fb47a490905ac- 부모
- 6ede861
변경된 파일 13개
+283-47| @@ -13,11 +13,11 @@ | ||
| 13 | 13 | |
| 14 | 14 | ## 스트리밍과 자원 정리 |
| 15 | 15 | |
| 16 | 삭제: 기존 revision 2의 필드와 tag 및 공동 합의한 입력/출력 기본 한도를 유지합니다. 앱이 공유하는 Limits::default()도 같은 값을 사용합니다. 압축비 거부 제거와 여유 공간 검사의 frontend 확인은 PR에서 별도로 받습니다. 세부 계약은 contract.json의 streaming_limits에 있습니다. | |
| 16 | 추가: revision 2의 기존 필드와 오류 tag 0~12 및 입력/출력 기본 한도를 유지하고, 히나타 님과 합의한 공간 부족 오류 DiskFull(tag 13)을 추가합니다. 구버전 앱은 새 tag를 거부하므로 앱 오류 변환과 화면 매핑을 작업자와 함께 갱신해야 합니다. 앱이 공유하는 Limits::default()도 같은 값을 사용합니다. 세부 계약은 contract.json의 streaming_limits에 있습니다. | |
| 17 | 17 | |
| 18 | 18 | - 압축비는 거부 조건으로 사용하지 않습니다. ZIP 선언 크기와 실제 해제 크기, CRC와 AES 인증을 검사하며, GZ 연결 멤버의 전체 해제량도 16 GiB 총량 한도에 포함합니다. TAR.GZ의 헤더와 padding도 계산합니다. u64 누계와 offset은 checked 연산을 사용합니다. |
| 19 | 삭제: - 입력 캡처 전에 임시 저장소 여유 공간을 확인합니다. ZIP/7z 해제 전에는 전체 임시 해제량과 선택한 출력량을 볼륨별로 합산해 검사하고, 게시 전에도 출력 공간을 재검사합니다. 미리 해제 크기를 알 수 없는 GZ/TAR.GZ는 각 해제 청크를 쓰기 전에 임시 저장소 공간을 확인합니다. Linux 64비트는 열린 핸들의 [fstatvfs](https://man7.org/linux/man-pages/man3/fstatvfs.3.html), Windows는 핸들에서 얻은 디렉터리의 [GetDiskFreeSpaceExW](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexw)를 사용합니다. 조회 실패와 부족은 기존 Io로 반환합니다. | |
| 20 | 삭제: - 공간 검사는 논리적 파일 크기에 따른 사전 확인이며 예약이나 모든 메타데이터/할당 단위 비용의 보장이 아닙니다. 다른 작업과 경쟁해 나중에 ENOSPC가 발생하면 기존 부분 출력 정리 정책을 적용합니다. 16 GiB 안에서는 압축비가 매우 큰 파일도 디스크에 풀릴 수 있습니다. 이 정책의 frontend 계약 확인은 PR에서 별도로 받습니다. | |
| 19 | 추가: - 입력 캡처 전에 임시 저장소 여유 공간을 확인합니다. ZIP/7z 해제 전에는 전체 임시 해제량과 선택한 출력량을 볼륨별로 합산해 검사하고, 게시 전에도 출력 공간을 재검사합니다. 미리 해제 크기를 알 수 없는 GZ/TAR.GZ는 각 해제 청크를 쓰기 전에 임시 저장소 공간을 확인합니다. Linux 64비트는 열린 핸들의 [fstatvfs](https://man7.org/linux/man-pages/man3/fstatvfs.3.html), Windows는 핸들에서 얻은 디렉터리의 [GetDiskFreeSpaceExW](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexw)를 사용합니다. 공간 부족은 DiskFull(13), 조회 실패와 권한 등 다른 I/O 오류는 Io(8)로 반환합니다. 실제 생성/쓰기/동기화의 공간 부족에도 같은 구분을 적용합니다. Windows의 공간 부족 코드 39와 112는 [공식 오류 목록](https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-)을 따릅니다. | |
| 20 | 추가: - 공간 검사는 논리적 파일 크기에 따른 사전 확인이며 예약이나 모든 메타데이터/할당 단위 비용의 보장이 아닙니다. 다른 작업과 경쟁해 나중에 ENOSPC가 발생하면 기존 부분 출력 정리 정책을 적용합니다. 16 GiB 안에서는 압축비가 매우 큰 파일도 디스크에 풀릴 수 있습니다. 오류 문구는 "디스크 여유 공간이 부족합니다. 공간을 확보한 뒤 다시 시도하세요"이며, detail 문자열을 오류 판정에 사용하지 않습니다. | |
| 21 | 21 | - 입력과 검증된 해제 내용은 임시 파일에 저장합니다. Linux는 [O_TMPFILE](https://man7.org/linux/man-pages/man2/open.2.html), 이를 지원하지 않는 Linux 파일시스템에서는 0600 난수 파일을 배타적으로 만든 즉시 unlink하고 링크 수 0을 확인합니다. Windows는 배타적 [DELETE_ON_CLOSE 파일](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew)을 사용합니다. 마지막 핸들이 닫히면 제거되며 임시 파일명에 아카이브 내부 이름을 사용하지 않습니다. 디스크에는 입력 사본, 해제 내용과 현재 출력 임시 파일이 동시에 필요할 수 있습니다. 임시 폴더가 tmpfs이면 해당 파일 내용은 프로세스 RSS 외의 시스템 메모리를 사용합니다. |
| 22 | 22 | - 64 MiB는 ZIP/TAR/GZ/TAR.GZ 해제 작업자 프로세스의 피크 RSS 시험 목표입니다. OS 메모리 강제 격리나 모든 아카이브의 보장을 뜻하지 않습니다. 7z와 생성은 이 RSS 목표에 포함하지 않습니다. 입력 크기와 무관한 메타데이터 예산은 유지합니다. |
| 23 | 23 | - Linux는 시작 시 부모 PID를 캡처하고 [getppid](https://man7.org/linux/man-pages/man2/getpid.2.html) 변경을 확인합니다. Windows는 부모 프로세스 핸들과 생성 시간을 확인한 뒤 [WaitForSingleObject](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject)로 생존을 검사합니다. 부모가 사라지면 checkpoint에서 Io로 중단하고 임시 출력을 정리합니다. 이미 게시한 파일/디렉터리는 유지하며 OS의 블로킹 I/O 강제 중단을 보장하지 않습니다. 기존 단발 요청을 위해 stdin EOF만으로 취소하지 않습니다. |
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | "Output": "entry_id:optional, relative_name, disposition Created|PartialRetained|Removed|CommitUncertain; only this job outputs.", |
| 40 | 40 | "Terminal": { |
| 41 | 41 | "outcome": "Completed|Failed|Cancelled", |
| 42 | 삭제: "error": "None|Integrity|UnsupportedFormat|UnsupportedFeature|WrongPassword|UnsafePath|Conflict|Limit|Io|Protocol|Internal|SourceChanged|InvalidRequest", | |
| 42 | 추가: "error": "None|Integrity|UnsupportedFormat|UnsupportedFeature|WrongPassword|UnsafePath|Conflict|Limit|Io|Protocol|Internal|SourceChanged|InvalidRequest|DiskFull", | |
| 43 | 43 | "publication": "None|Partial|Complete|Uncertain", |
| 44 | 44 | "created_count": "u64", |
| 45 | 45 | "retained_partial_count": "u64", |
| @@ -86,7 +86,8 @@ | ||
| 86 | 86 | "coordination": { |
| 87 | 87 | "frontend_message_id": "41a0e5a5-27d0-437f-805d-d39313082096", |
| 88 | 88 | "basis": "Revision 2 list identity, explicit raw GZip output naming and cancellation acknowledgement are implemented. Field order and tags remain unchanged.", |
| 89 | 삭제: "streaming_frontend_message_id": "59142fd4-22d3-4dc5-a875-5347e1b054da" | |
| 89 | 추가: "streaming_frontend_message_id": "59142fd4-22d3-4dc5-a875-5347e1b054da", | |
| 90 | 추가: "disk_full_frontend_message_id": "3b01f4c4-c9b4-4c72-a9a0-b3df39979ea1" | |
| 90 | 91 | }, |
| 91 | 92 | "list_identity": { |
| 92 | 93 | "ListId": { |
| @@ -143,7 +144,7 @@ | ||
| 143 | 144 | "regression": "Preserve existing format bytes and round-trip SevenZip in ListEnd/ListId." |
| 144 | 145 | }, |
| 145 | 146 | "streaming_limits": { |
| 146 | 삭제: "agreement": "Revision 2 fields, tags and frame encoding unchanged. Ratio-rejection removal and disk-space advisory checks are proposed under manager decision d6bc0d37-89d1-4cd2-a00b-883b5eb23ec0; frontend confirmation pending.", | |
| 147 | 추가: "agreement": "Revision 2 fields and frame encoding unchanged. Ratio-rejection removal and advisory disk-space checks follow manager decision d6bc0d37-89d1-4cd2-a00b-883b5eb23ec0. DiskFull tag 13 and preserving Io tag 8 for query/access failures were agreed with frontend in message 3b01f4c4-c9b4-4c72-a9a0-b3df39979ea1.", | |
| 147 | 148 | "default_input_bytes": 18446744073709551615, |
| 148 | 149 | "default_output_bytes": 17179869184, |
| 149 | 150 | "default_entries": 10000, |
| @@ -153,11 +154,34 @@ | ||
| 153 | 154 | "tar_ratio": "Plain TAR copies declared nonoverlapping ranges within the captured input. The sum of file sizes cannot exceed output quota.", |
| 154 | 155 | "arithmetic": "Checked u64 offsets and totals; free-space block-to-byte conversion uses u128 to avoid multiplication overflow.", |
| 155 | 156 | "memory_target": "ZIP/TAR/GZ/TAR.GZ List/Extract: worker process peak RSS <=64 MiB in Linux regression with independently generated 1 GiB payloads. This is a measured target, not an OS-enforced RSS cap. Metadata budget remains 8 MiB.", |
| 156 | 삭제: "staging": "64 KiB buffers; immutable input capture and verified decoded content use private temporary files that are removed on last-handle close. No decoded content is published until the entire catalog and integrity checks succeed. Temporary disk usage can include the archive plus expanded content plus current destination temporary file; disk exhaustion fails with Io and closes/removes unpublished data.", | |
| 157 | 추가: "staging": "64 KiB buffers; immutable input capture and verified decoded content use private temporary files that are removed on last-handle close. No decoded content is published until the entire catalog and integrity checks succeed. Temporary disk usage can include the archive plus expanded content plus current destination temporary file; disk exhaustion fails with DiskFull and closes/removes unpublished data.", | |
| 157 | 158 | "legacy": "7z and ZIP creation retain separate 64 MiB input /128 MiB output caps until their streaming implementation. The slice-based archive parser also retains these legacy memory bounds.", |
| 158 | 159 | "parent_lifetime": "Capture native parent before reading Start. At decode/read/write/password checkpoints, fail Io if parent is gone; close anonymous staging and remove current unpublished destination temp. stdin EOF alone remains valid for one-shot requests. Already published entries and directories are reported and retained. A blocked OS file operation cannot be forcibly interrupted by this cooperative guard.", |
| 159 | 삭제: "disk_space": "Advisory free-space checks use opened Linux x86_64 filesystem handles (fstatvfs) or the Windows handle-derived directory (GetDiskFreeSpaceExW). Before ZIP/7z decoding and before publication, group remaining staging and selected output logical bytes by volume. For GZip with unknown expanded size, check staging space before each decoded chunk, then preflight selected output. Input capture also checks its snapshot space. Query failure or insufficient space returns existing Io tag 8. Checks do not reserve space or account for every metadata/block-allocation overhead; later ENOSPC still closes staging and removes current unpublished output.", | |
| 160 | 추가: "disk_space": "Advisory free-space checks use opened Linux x86_64 filesystem handles (fstatvfs) or the Windows handle-derived directory (GetDiskFreeSpaceExW). Before ZIP/7z decoding and before publication, group remaining staging and selected output logical bytes by volume. For GZip with unknown expanded size, check staging space before each decoded chunk, then preflight selected output. Input capture also checks its snapshot space. Insufficient space returns DiskFull tag 13. Query failure and other I/O errors retain Io tag 8. Checks do not reserve space or account for every metadata/block-allocation overhead; later ENOSPC still closes staging and removes current unpublished output.", | |
| 160 | 161 | "remaining_risk": "High compression ratios within 16 GiB may expand fully onto disk. Resource duration, cooperative cancellation and measured memory target remain. Free-space checks can race with other disk users; already published outputs are retained on failure." |
| 161 | 162 | }, |
| 162 | 삭제: "validation": "Implementation results belong in the PR verification record. No OS sandbox or native Windows execution claim." | |
| 163 | 추가: "validation": "Implementation results belong in the PR verification record. No OS sandbox or native Windows execution claim.", | |
| 164 | 추가: "error_tags": { | |
| 165 | 추가: "None": 0, | |
| 166 | 추가: "Integrity": 1, | |
| 167 | 추가: "UnsupportedFormat": 2, | |
| 168 | 추가: "UnsupportedFeature": 3, | |
| 169 | 추가: "WrongPassword": 4, | |
| 170 | 추가: "UnsafePath": 5, | |
| 171 | 추가: "Conflict": 6, | |
| 172 | 추가: "Limit": 7, | |
| 173 | 추가: "Io": 8, | |
| 174 | 추가: "Protocol": 9, | |
| 175 | 추가: "Internal": 10, | |
| 176 | 추가: "SourceChanged": 11, | |
| 177 | 추가: "InvalidRequest": 12, | |
| 178 | 추가: "DiskFull": 13 | |
| 179 | 추가: }, | |
| 180 | 추가: "disk_full_extension": { | |
| 181 | 추가: "agreement_message_id": "3b01f4c4-c9b4-4c72-a9a0-b3df39979ea1", | |
| 182 | 추가: "compatibility": "Existing error tags 0 through 12, fields, message tags, revision 2 and frame version stay unchanged. Older clients reject error 13; app error mapping and worker must be updated together before integration.", | |
| 183 | 추가: "mapping": "Insufficient preflight space and StorageFull I/O failures return DiskFull 13. Windows ERROR_HANDLE_DISK_FULL 39 and ERROR_DISK_FULL 112 also map to DiskFull. Query failure, permission errors and other I/O failures return Io 8. No error classification by localized detail text.", | |
| 184 | 추가: "detail": "디스크 여유 공간이 부족합니다. 공간을 확보한 뒤 다시 시도하세요", | |
| 185 | 추가: "publication": "Keep existing publication, durability and cleanup semantics. DiskFull does not imply rollback or absence of previously published outputs." | |
| 186 | 추가: } | |
| 163 | 187 | } |
| @@ -232,7 +232,7 @@ mod platform { | ||
| 232 | 232 | let n = CString::new(n).map_err(|_| ErrorCode::UnsafePath)?; |
| 233 | 233 | // 고정 부모 안에 새 전용 디렉터리를 생성함. |
| 234 | 234 | if unsafe { mkdirat(self.file.as_raw_fd(), n.as_ptr(), 0o700) } != 0 { |
| 235 | 삭제: return Err(ErrorCode::Io); | |
| 235 | 추가: return Err(crate::space::io_error(std::io::Error::last_os_error())); | |
| 236 | 236 | } |
| 237 | 237 | let file = open( |
| 238 | 238 | &self.file, |
| @@ -289,11 +289,11 @@ mod platform { | ||
| 289 | 289 | unsafe { unlinkat(self.file.as_raw_fd(), n.as_ptr(), 0) == 0 } |
| 290 | 290 | } |
| 291 | 291 | pub fn sync(&self) -> Durability { |
| 292 | 삭제: if self.file.sync_all().is_ok() { | |
| 293 | 삭제: Durability::Synced | |
| 294 | 삭제: } else { | |
| 295 | 삭제: Durability::Failed | |
| 296 | 삭제: } | |
| 292 | 추가: self.sync_checked().unwrap_or(Durability::Failed) | |
| 293 | 추가: } | |
| 294 | 추가: pub(crate) fn sync_checked(&self) -> Result<Durability> { | |
| 295 | 추가: self.file.sync_all().map_err(crate::space::io_error)?; | |
| 296 | 추가: Ok(Durability::Synced) | |
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | } |
| @@ -361,7 +361,7 @@ mod platform { | ||
| 361 | 361 | if !create { |
| 362 | 362 | return Ok(None); |
| 363 | 363 | } |
| 364 | 삭제: std::fs::create_dir(&p).map_err(|_| ErrorCode::Io)?; | |
| 364 | 추가: std::fs::create_dir(&p).map_err(crate::space::io_error)?; | |
| 365 | 365 | } |
| 366 | 366 | Err(_) => return Err(ErrorCode::Io), |
| 367 | 367 | } |
| @@ -394,6 +394,9 @@ mod platform { | ||
| 394 | 394 | pub fn sync(&self) -> Durability { |
| 395 | 395 | Durability::Unconfirmed |
| 396 | 396 | } |
| 397 | 추가: pub(crate) fn sync_checked(&self) -> Result<Durability> { | |
| 398 | 추가: Ok(Durability::Unconfirmed) | |
| 399 | 추가: } | |
| 397 | 400 | } |
| 398 | 401 | } |
| 399 | 402 | #[cfg(not(any(target_os = "linux", windows)))] |
| @@ -463,13 +466,16 @@ pub(crate) fn preflight_space( | ||
| 463 | 466 | } |
| 464 | 467 | Ok(()) |
| 465 | 468 | } |
| 466 | 삭제: pub fn directory(root: &Dir, name: &str) -> Result<(bool, Durability)> { | |
| 469 | 추가: pub fn directory(root: &Dir, name: &str) -> Result<(bool, Durability, Option<ErrorCode>)> { | |
| 467 | 470 | let (d, leaf) = parent(root, name, false)?.ok_or(ErrorCode::Io)?; |
| 468 | 471 | if d.child(&leaf, false)?.is_some() { |
| 469 | 삭제: return Ok((false, Durability::NotApplicable)); | |
| 472 | 추가: return Ok((false, Durability::NotApplicable, None)); | |
| 470 | 473 | } |
| 471 | 474 | d.child(&leaf, true)?.ok_or(ErrorCode::Io)?; |
| 472 | 삭제: Ok((true, d.sync())) | |
| 475 | 추가: Ok(match d.sync_checked() { | |
| 476 | 추가: Ok(durability) => (true, durability, None), | |
| 477 | 추가: Err(error) => (true, Durability::Failed, Some(error)), | |
| 478 | 추가: }) | |
| 473 | 479 | } |
| 474 | 480 | pub struct Published { |
| 475 | 481 | pub created: bool, |
| @@ -523,7 +529,7 @@ pub fn publish_reader( | ||
| 523 | 529 | if e.kind() == std::io::ErrorKind::AlreadyExists { |
| 524 | 530 | ErrorCode::Conflict |
| 525 | 531 | } else { |
| 526 | 삭제: ErrorCode::Io | |
| 532 | 추가: crate::space::io_error(e) | |
| 527 | 533 | } |
| 528 | 534 | })?; |
| 529 | 535 | let written = (|| { |
| @@ -537,29 +543,33 @@ pub fn publish_reader( | ||
| 537 | 543 | if n == 0 { |
| 538 | 544 | return Err(ErrorCode::Io); |
| 539 | 545 | } |
| 540 | 삭제: file.write_all(&buffer[..n]).map_err(|_| ErrorCode::Io)?; | |
| 546 | 추가: file.write_all(&buffer[..n]) | |
| 547 | 추가: .map_err(crate::space::io_error)?; | |
| 541 | 548 | remaining -= n as u64; |
| 542 | 549 | } |
| 543 | 삭제: file.sync_all().map_err(|_| ErrorCode::Io) | |
| 550 | 추가: file.sync_all().map_err(crate::space::io_error) | |
| 544 | 551 | })(); |
| 545 | 삭제: let closed = close(file).map_err(|_| ErrorCode::Io); | |
| 552 | 추가: let closed = close(file).map_err(crate::space::io_error); | |
| 546 | 553 | let mut finish = written.and(closed).and_then(|_| check(true)); |
| 547 | 554 | if finish.is_ok() { |
| 548 | 555 | match dir.link(&temp, &leaf) { |
| 549 | 556 | Ok(()) => { |
| 550 | 557 | result.created = true; |
| 551 | 삭제: result.durability = dir.sync(); | |
| 552 | 삭제: if result.durability == Durability::Failed { | |
| 553 | 삭제: finish = Err(ErrorCode::Io); | |
| 558 | 추가: match dir.sync_checked() { | |
| 559 | 추가: Ok(durability) => result.durability = durability, | |
| 560 | 추가: Err(error) => { | |
| 561 | 추가: result.durability = Durability::Failed; | |
| 562 | 추가: finish = Err(error); | |
| 563 | 추가: } | |
| 554 | 564 | } |
| 555 | 565 | } |
| 556 | 566 | Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => { |
| 557 | 567 | finish = Err(ErrorCode::Conflict) |
| 558 | 568 | } |
| 559 | 삭제: Err(_) => { | |
| 569 | 추가: Err(error) => { | |
| 560 | 570 | result.uncertain = true; |
| 561 | 571 | result.durability = Durability::Unconfirmed; |
| 562 | 삭제: finish = Err(ErrorCode::Io); | |
| 572 | 추가: finish = Err(crate::space::io_error(error)); | |
| 563 | 573 | } |
| 564 | 574 | } |
| 565 | 575 | } |
| @@ -574,9 +584,11 @@ pub fn publish_reader( | ||
| 574 | 584 | finish = Err(ErrorCode::Io); |
| 575 | 585 | } |
| 576 | 586 | } |
| 577 | 삭제: if result.created && dir.sync() == Durability::Failed { | |
| 578 | 삭제: result.durability = Durability::Failed; | |
| 579 | 삭제: finish = Err(ErrorCode::Io); | |
| 587 | 추가: if result.created { | |
| 588 | 추가: if let Err(error) = dir.sync_checked() { | |
| 589 | 추가: result.durability = Durability::Failed; | |
| 590 | 추가: finish = Err(error); | |
| 591 | 추가: } | |
| 580 | 592 | } |
| 581 | 593 | finish |
| 582 | 594 | })(); |
| @@ -221,6 +221,7 @@ pub enum ErrorCode { | ||
| 221 | 221 | Internal, |
| 222 | 222 | SourceChanged, |
| 223 | 223 | InvalidRequest, |
| 224 | 추가: DiskFull, | |
| 224 | 225 | } |
| 225 | 226 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 226 | 227 | pub enum Publication { |
| @@ -379,7 +379,8 @@ impl<W: Write> Job<W> { | ||
| 379 | 379 | filesystem::preflight_space(&root, &output_sizes, None)?; |
| 380 | 380 | for name in dirs { |
| 381 | 381 | self.check()?; |
| 382 | 삭제: let (created, durability) = filesystem::directory(&root, &name)?; | |
| 382 | 추가: let (created, durability, sync_error) = | |
| 383 | 추가: filesystem::directory(&root, &name)?; | |
| 383 | 384 | if created { |
| 384 | 385 | self.terminal.created_count += 1; |
| 385 | 386 | self.terminal.publication = Publication::Partial; |
| @@ -389,8 +390,8 @@ impl<W: Write> Job<W> { | ||
| 389 | 390 | relative_name: name, |
| 390 | 391 | disposition: Disposition::Created, |
| 391 | 392 | })?; |
| 392 | 삭제: if durability == Durability::Failed { | |
| 393 | 삭제: return Err(ErrorCode::Io); | |
| 393 | 추가: if let Some(error) = sync_error { | |
| 394 | 추가: return Err(error); | |
| 394 | 395 | } |
| 395 | 396 | } |
| 396 | 397 | } |
| @@ -612,6 +613,9 @@ pub fn serve<R: Read + Send + 'static, W: Write + Send + 'static>( | ||
| 612 | 613 | ErrorCode::None => "취소됨", |
| 613 | 614 | ErrorCode::UnsupportedFeature => "암호 또는 해당 기능 미지원", |
| 614 | 615 | ErrorCode::SourceChanged => "파일이 변경됨. 다시 열어 목록을 확인해야 함", |
| 616 | 추가: ErrorCode::DiskFull => { | |
| 617 | 추가: "디스크 여유 공간이 부족합니다. 공간을 확보한 뒤 다시 시도하세요" | |
| 618 | 추가: } | |
| 615 | 619 | ErrorCode::Io => { |
| 616 | 620 | "파일을 읽거나 쓰지 못했습니다. 디스크 여유 공간과 접근 권한을 확인하세요" |
| 617 | 621 | } |
| @@ -14,7 +14,7 @@ pub(crate) fn ensure(file: &File, bytes: u64) -> Result<()> { | ||
| 14 | 14 | if bytes == 0 || bytes as u128 <= available(file)? { |
| 15 | 15 | Ok(()) |
| 16 | 16 | } else { |
| 17 | 삭제: Err(ErrorCode::Io) | |
| 17 | 추가: Err(ErrorCode::DiskFull) | |
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | |
| @@ -121,3 +121,20 @@ fn available(file: &File) -> Result<u128> { | ||
| 121 | 121 | } |
| 122 | 122 | Ok(free as u128) |
| 123 | 123 | } |
| 124 | 추가: | |
| 125 | 추가: // 공간 부족만 전용 오류로 변환함. | |
| 126 | 추가: pub(crate) fn io_error(error: std::io::Error) -> ErrorCode { | |
| 127 | 추가: #[cfg(windows)] | |
| 128 | 추가: if matches!(error.raw_os_error(), Some(39 | 112)) { | |
| 129 | 추가: return ErrorCode::DiskFull; | |
| 130 | 추가: } | |
| 131 | 추가: if error.kind() == std::io::ErrorKind::StorageFull { | |
| 132 | 추가: ErrorCode::DiskFull | |
| 133 | 추가: } else { | |
| 134 | 추가: ErrorCode::Io | |
| 135 | 추가: } | |
| 136 | 추가: } | |
| 137 | 추가: | |
| 138 | 추가: #[cfg(test)] | |
| 139 | 추가: #[path = "../../../tests/rust-archive-worker/space_errors.rs"] | |
| 140 | 추가: mod tests; |
| @@ -13,14 +13,18 @@ pub(crate) fn temporary() -> Result<File> { | ||
| 13 | 13 | { |
| 14 | 14 | use std::os::unix::fs::OpenOptionsExt; |
| 15 | 15 | // 이름 없는 임시 파일은 마지막 핸들을 닫으면 제거됨. |
| 16 | 삭제: if let Ok(file) = OpenOptions::new() | |
| 16 | 추가: match OpenOptions::new() | |
| 17 | 17 | .read(true) |
| 18 | 18 | .write(true) |
| 19 | 19 | .custom_flags(0x410000 | 0x80) |
| 20 | 20 | .mode(0o600) |
| 21 | 21 | .open(std::env::temp_dir()) |
| 22 | 22 | { |
| 23 | 삭제: return Ok(file); | |
| 23 | 추가: Ok(file) => return Ok(file), | |
| 24 | 추가: Err(ref error) if error.kind() == std::io::ErrorKind::StorageFull => { | |
| 25 | 추가: return Err(ErrorCode::DiskFull); | |
| 26 | 추가: } | |
| 27 | 추가: Err(_) => {} | |
| 24 | 28 | } |
| 25 | 29 | let mut random = [0; 16]; |
| 26 | 30 | crate::crypto::random(&mut random)?; |
| @@ -36,7 +40,7 @@ pub(crate) fn temporary() -> Result<File> { | ||
| 36 | 40 | .mode(0o600) |
| 37 | 41 | .custom_flags(0x20000) |
| 38 | 42 | .open(&path) |
| 39 | 삭제: .map_err(|_| ErrorCode::Io)?; | |
| 43 | 추가: .map_err(crate::space::io_error)?; | |
| 40 | 44 | std::fs::remove_file(path).map_err(|_| ErrorCode::Io)?; |
| 41 | 45 | use std::os::unix::fs::MetadataExt; |
| 42 | 46 | if file.metadata().map_err(|_| ErrorCode::Io)?.nlink() != 0 { |
| @@ -62,7 +66,7 @@ pub(crate) fn temporary() -> Result<File> { | ||
| 62 | 66 | .custom_flags(0x04000000 | 0x00200000) |
| 63 | 67 | .attributes(0x100) |
| 64 | 68 | .open(std::env::temp_dir().join(format!("zipelo-{name}.tmp"))) |
| 65 | 삭제: .map_err(|_| ErrorCode::Io) | |
| 69 | 추가: .map_err(crate::space::io_error) | |
| 66 | 70 | } |
| 67 | 71 | } |
| 68 | 72 | |
| @@ -121,7 +125,8 @@ impl Snapshot { | ||
| 121 | 125 | .checked_add(n as u64) |
| 122 | 126 | .filter(|n| *n <= limit) |
| 123 | 127 | .ok_or(ErrorCode::Limit)?; |
| 124 | 삭제: file.write_all(&buffer[..n]).map_err(|_| ErrorCode::Io)?; | |
| 128 | 추가: file.write_all(&buffer[..n]) | |
| 129 | 추가: .map_err(crate::space::io_error)?; | |
| 125 | 130 | hash.update(&buffer[..n]); |
| 126 | 131 | } |
| 127 | 132 | let after = source.metadata().map_err(|_| ErrorCode::Io)?; |
| @@ -36,7 +36,7 @@ fn add(a: u64, b: u64) -> Result<u64> { | ||
| 36 | 36 | a.checked_add(b).ok_or(ErrorCode::Integrity) |
| 37 | 37 | } |
| 38 | 38 | fn io<T>(v: std::io::Result<T>) -> Result<T> { |
| 39 | 삭제: v.map_err(|_| ErrorCode::Io) | |
| 39 | 추가: v.map_err(crate::space::io_error) | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | pub(crate) struct Catalog { |
| @@ -133,7 +133,7 @@ enumeration!(EntryKind{File=0,Directory=1,Link=2,Other=3}); | ||
| 133 | 133 | enumeration!(Stage{Scan=0,Read=1,Decode=2,Write=3,Verify=4,Commit=5}); |
| 134 | 134 | enumeration!(Disposition{Created=0,PartialRetained=1,Removed=2,CommitUncertain=3}); |
| 135 | 135 | enumeration!(Outcome{Completed=0,Failed=1,Cancelled=2}); |
| 136 | 삭제: enumeration!(ErrorCode{None=0,Integrity=1,UnsupportedFormat=2,UnsupportedFeature=3,WrongPassword=4,UnsafePath=5,Conflict=6,Limit=7,Io=8,Protocol=9,Internal=10,SourceChanged=11,InvalidRequest=12}); | |
| 136 | 추가: enumeration!(ErrorCode{None=0,Integrity=1,UnsupportedFormat=2,UnsupportedFeature=3,WrongPassword=4,UnsafePath=5,Conflict=6,Limit=7,Io=8,Protocol=9,Internal=10,SourceChanged=11,InvalidRequest=12,DiskFull=13}); | |
| 137 | 137 | enumeration!(Publication{None=0,Partial=1,Complete=2,Uncertain=3}); |
| 138 | 138 | enumeration!(Durability{NotApplicable=0,Synced=1,Unconfirmed=2,Failed=3}); |
| 139 | 139 | enumeration!(Cleanup{Complete=0,Failed=1,Unconfirmed=2}); |
| @@ -433,7 +433,13 @@ mod linux { | ||
| 433 | 433 | } |
| 434 | 434 | #[test] |
| 435 | 435 | fn enospc_at_create_or_after_partial_write_cleans_output() { |
| 436 | 삭제: for mode in ["create-full", "full", "stage-full"] { | |
| 436 | 추가: for mode in [ | |
| 437 | 추가: "create-full", | |
| 438 | 추가: "full", | |
| 439 | 추가: "stage-full", | |
| 440 | 추가: "temp-full", | |
| 441 | 추가: "sync-full", | |
| 442 | 추가: ] { | |
| 437 | 443 | let s = Scratch::new(); |
| 438 | 444 | generate(&s, "store", 1024 * 1024); |
| 439 | 445 | fs::write(s.0.join("preserve"), b"original").unwrap(); |
| @@ -442,7 +448,11 @@ mod linux { | ||
| 442 | 448 | assert_eq!(wait(child.id()).0, 0); |
| 443 | 449 | let events = events(&s); |
| 444 | 450 | let t = terminal(&events); |
| 445 | 삭제: assert_eq!(t.error, ErrorCode::Io, "{mode}: {events:?}"); | |
| 451 | 추가: assert_eq!(t.error, ErrorCode::DiskFull, "{mode}: {events:?}"); | |
| 452 | 추가: assert_eq!( | |
| 453 | 추가: t.detail, | |
| 454 | 추가: "디스크 여유 공간이 부족합니다. 공간을 확보한 뒤 다시 시도하세요" | |
| 455 | 추가: ); | |
| 446 | 456 | assert_eq!(t.publication, Publication::None); |
| 447 | 457 | assert_eq!(t.retained_partial_count, 0); |
| 448 | 458 | assert_eq!(t.cleanup, Cleanup::Complete); |
| @@ -465,7 +475,12 @@ mod linux { | ||
| 465 | 475 | assert_eq!(wait(child.id()).0, 0); |
| 466 | 476 | let events = events(&s); |
| 467 | 477 | let t = terminal(&events); |
| 468 | 삭제: assert_eq!(t.error, ErrorCode::Io, "{mode}: {events:?}"); | |
| 478 | 추가: let expected = if mode == "space-error" { | |
| 479 | 추가: ErrorCode::Io | |
| 480 | 추가: } else { | |
| 481 | 추가: ErrorCode::DiskFull | |
| 482 | 추가: }; | |
| 483 | 추가: assert_eq!(t.error, expected, "{mode}: {events:?}"); | |
| 469 | 484 | assert_eq!(t.publication, Publication::None); |
| 470 | 485 | assert_eq!(t.cleanup, Cleanup::Complete); |
| 471 | 486 | assert_eq!(t.created_count, 0); |
| @@ -476,6 +491,67 @@ mod linux { | ||
| 476 | 491 | } |
| 477 | 492 | } |
| 478 | 493 | #[test] |
| 494 | 추가: fn disk_full_during_directory_sync_retains_reported_outputs() { | |
| 495 | 추가: for nested in [false, true] { | |
| 496 | 추가: let s = Scratch::new(); | |
| 497 | 추가: fs::write(s.0.join("source"), vec![0; 1024]).unwrap(); | |
| 498 | 추가: let name = if nested { | |
| 499 | 추가: "folder/payload.bin" | |
| 500 | 추가: } else { | |
| 501 | 추가: "payload.bin" | |
| 502 | 추가: }; | |
| 503 | 추가: let created = execute(Start { | |
| 504 | 추가: action: Action::CreateZip { | |
| 505 | 추가: sources: vec![Source { | |
| 506 | 추가: path: s.path("source"), | |
| 507 | 추가: archive_name: name.into(), | |
| 508 | 추가: }], | |
| 509 | 추가: output_file: s.path("input"), | |
| 510 | 추가: method: Method::Store, | |
| 511 | 추가: encryption: Encryption::None, | |
| 512 | 추가: }, | |
| 513 | 추가: limits: Limits::default(), | |
| 514 | 추가: }); | |
| 515 | 추가: assert_eq!(terminal(&created).outcome, Outcome::Completed); | |
| 516 | 추가: let request = start(&s, false, Limits::default().output); | |
| 517 | 추가: let child = spawn(&s, request, Some("dir-sync-full")); | |
| 518 | 추가: assert_eq!(wait(child.id()).0, 0); | |
| 519 | 추가: let events = events(&s); | |
| 520 | 추가: let t = terminal(&events); | |
| 521 | 추가: assert_eq!(t.error, ErrorCode::DiskFull, "{events:?}"); | |
| 522 | 추가: assert_eq!(t.publication, Publication::Partial); | |
| 523 | 추가: assert_eq!(t.created_count, 1); | |
| 524 | 추가: assert_eq!(t.durability, Durability::Failed); | |
| 525 | 추가: assert_eq!(t.cleanup, Cleanup::Complete); | |
| 526 | 추가: assert_eq!(t.retained_partial_count, 0); | |
| 527 | 추가: assert_eq!(fs::read_dir(s.0.join("staging")).unwrap().count(), 0); | |
| 528 | 추가: assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 1); | |
| 529 | 추가: if nested { | |
| 530 | 추가: assert_eq!(fs::read_dir(s.0.join("output/folder")).unwrap().count(), 0); | |
| 531 | 추가: } else { | |
| 532 | 추가: assert_zero_file(&s.0.join("output/payload.bin"), 1024); | |
| 533 | 추가: } | |
| 534 | 추가: } | |
| 535 | 추가: } | |
| 536 | 추가: #[test] | |
| 537 | 추가: fn permission_and_generic_write_errors_remain_io() { | |
| 538 | 추가: for mode in ["create-denied", "write-io"] { | |
| 539 | 추가: let s = Scratch::new(); | |
| 540 | 추가: generate(&s, "store", 1024 * 1024); | |
| 541 | 추가: let request = start(&s, false, Limits::default().output); | |
| 542 | 추가: let child = spawn(&s, request, Some(mode)); | |
| 543 | 추가: assert_eq!(wait(child.id()).0, 0); | |
| 544 | 추가: let events = events(&s); | |
| 545 | 추가: let t = terminal(&events); | |
| 546 | 추가: assert_eq!(t.error, ErrorCode::Io, "{mode}: {events:?}"); | |
| 547 | 추가: assert_eq!(t.publication, Publication::None); | |
| 548 | 추가: assert_eq!(t.retained_partial_count, 0); | |
| 549 | 추가: assert_eq!(t.cleanup, Cleanup::Complete); | |
| 550 | 추가: assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); | |
| 551 | 추가: assert_eq!(fs::read_dir(s.0.join("staging")).unwrap().count(), 0); | |
| 552 | 추가: } | |
| 553 | 추가: } | |
| 554 | 추가: #[test] | |
| 479 | 555 | fn anonymous_tempfile_fallback_unlinks_before_use() { |
| 480 | 556 | let s = Scratch::new(); |
| 481 | 557 | generate(&s, "store", 1024 * 1024); |
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | static ssize_t (*real_write)(int, const void *, size_t); |
| 14 | 14 | static int (*real_openat)(int, const char *, int, ...); |
| 15 | 15 | static int (*real_open64)(const char *, int, ...); |
| 16 | 추가: static int (*real_fsync)(int); | |
| 16 | 17 | static int (*real_fstatvfs)(int, struct statvfs *); |
| 17 | 18 | static int started; |
| 18 | 19 | |
| @@ -20,6 +21,7 @@ __attribute__((constructor)) static void initialize(void) { | ||
| 20 | 21 | real_write = dlsym(RTLD_NEXT, "write"); |
| 21 | 22 | real_openat = dlsym(RTLD_NEXT, "openat"); |
| 22 | 23 | real_open64 = dlsym(RTLD_NEXT, "open64"); |
| 24 | 추가: real_fsync = dlsym(RTLD_NEXT, "fsync"); | |
| 23 | 25 | real_fstatvfs = dlsym(RTLD_NEXT, "fstatvfs"); |
| 24 | 26 | } |
| 25 | 27 | |
| @@ -43,8 +45,9 @@ int openat(int fd, const char *path, int flags, ...) { | ||
| 43 | 45 | va_end(args); |
| 44 | 46 | } |
| 45 | 47 | const char *fault = getenv("ZIPELO_TEST_FAULT"); |
| 46 | 삭제: if (fault && !strcmp(fault, "create-full") && !strncmp(path, ".zipelo-", 8)) { | |
| 47 | 삭제: errno = ENOSPC; | |
| 48 | 추가: if (fault && (!strcmp(fault, "create-full") || !strcmp(fault, "create-denied")) | |
| 49 | 추가: && !strncmp(path, ".zipelo-", 8)) { | |
| 50 | 추가: errno = !strcmp(fault, "create-full") ? ENOSPC : EACCES; | |
| 48 | 51 | return -1; |
| 49 | 52 | } |
| 50 | 53 | return real_openat(fd, path, flags, mode); |
| @@ -59,6 +62,11 @@ int open64(const char *path, int flags, ...) { | ||
| 59 | 62 | va_end(args); |
| 60 | 63 | } |
| 61 | 64 | const char *fault = getenv("ZIPELO_TEST_FAULT"); |
| 65 | 추가: if (fault && !strcmp(fault, "temp-full") | |
| 66 | 추가: && (((flags & O_TMPFILE) == O_TMPFILE) || strstr(path, "/zipelo-"))) { | |
| 67 | 추가: errno = ENOSPC; | |
| 68 | 추가: return -1; | |
| 69 | 추가: } | |
| 62 | 70 | if (fault && !strcmp(fault, "fallback") && ((flags & O_TMPFILE) == O_TMPFILE)) { |
| 63 | 71 | int marker = real_openat(AT_FDCWD, getenv("ZIPELO_TEST_MARKER"), O_CREAT | O_WRONLY, 0600); |
| 64 | 72 | if (marker >= 0) close(marker); |
| @@ -71,6 +79,7 @@ int open64(const char *path, int flags, ...) { | ||
| 71 | 79 | ssize_t write(int fd, const void *bytes, size_t count) { |
| 72 | 80 | const char *fault = getenv("ZIPELO_TEST_FAULT"); |
| 73 | 81 | if (!fault || !output_file(fd)) return real_write(fd, bytes, count); |
| 82 | 추가: if (!strcmp(fault, "write-io")) { errno = EIO; return -1; } | |
| 74 | 83 | if (!strcmp(fault, "full") || !strcmp(fault, "stage-full")) { |
| 75 | 84 | if (!started++) return real_write(fd, bytes, count < 7 ? count : 7); |
| 76 | 85 | errno = ENOSPC; |
| @@ -104,3 +113,15 @@ int fstatvfs(int fd, struct statvfs *value) { | ||
| 104 | 113 | value->f_bavail = !strcmp(fault, "space-combined") ? (1536 * 1024) / value->f_frsize : 0; |
| 105 | 114 | return 0; |
| 106 | 115 | } |
| 116 | 추가: | |
| 117 | 추가: int fsync(int fd) { | |
| 118 | 추가: const char *fault = getenv("ZIPELO_TEST_FAULT"); | |
| 119 | 추가: struct stat st; | |
| 120 | 추가: int directory_full = fault && !strcmp(fault, "dir-sync-full") | |
| 121 | 추가: && !fstat(fd, &st) && S_ISDIR(st.st_mode); | |
| 122 | 추가: if (directory_full || (fault && !strcmp(fault, "sync-full") && output_file(fd))) { | |
| 123 | 추가: errno = ENOSPC; | |
| 124 | 추가: return -1; | |
| 125 | 추가: } | |
| 126 | 추가: return real_fsync(fd); | |
| 127 | 추가: } |
| @@ -1552,3 +1552,44 @@ fn seven_zip_reference_reader_accepts_synthetic_fixtures() { | ||
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | mod hardening; |
| 1555 | 추가: | |
| 1556 | 추가: #[test] | |
| 1557 | 추가: fn disk_full_error_tag_preserves_previous_tags_and_rejects_unknown() { | |
| 1558 | 추가: for (tag, error) in [ | |
| 1559 | 추가: ErrorCode::None, | |
| 1560 | 추가: ErrorCode::Integrity, | |
| 1561 | 추가: ErrorCode::UnsupportedFormat, | |
| 1562 | 추가: ErrorCode::UnsupportedFeature, | |
| 1563 | 추가: ErrorCode::WrongPassword, | |
| 1564 | 추가: ErrorCode::UnsafePath, | |
| 1565 | 추가: ErrorCode::Conflict, | |
| 1566 | 추가: ErrorCode::Limit, | |
| 1567 | 추가: ErrorCode::Io, | |
| 1568 | 추가: ErrorCode::Protocol, | |
| 1569 | 추가: ErrorCode::Internal, | |
| 1570 | 추가: ErrorCode::SourceChanged, | |
| 1571 | 추가: ErrorCode::InvalidRequest, | |
| 1572 | 추가: ErrorCode::DiskFull, | |
| 1573 | 추가: ] | |
| 1574 | 추가: .into_iter() | |
| 1575 | 추가: .enumerate() | |
| 1576 | 추가: { | |
| 1577 | 추가: let message = Message::Terminal(Terminal { | |
| 1578 | 추가: outcome: Outcome::Failed, | |
| 1579 | 추가: error, | |
| 1580 | 추가: publication: Publication::None, | |
| 1581 | 추가: created_count: 0, | |
| 1582 | 추가: retained_partial_count: 0, | |
| 1583 | 추가: durability: Durability::NotApplicable, | |
| 1584 | 추가: cleanup: Cleanup::Complete, | |
| 1585 | 추가: detail: String::new(), | |
| 1586 | 추가: }); | |
| 1587 | 추가: let mut bytes = Vec::new(); | |
| 1588 | 추가: Writer::new(&mut bytes, 17).send(&message).unwrap(); | |
| 1589 | 추가: assert_eq!(bytes[33], tag as u8); | |
| 1590 | 추가: let decoded = Reader::new(bytes.as_slice()).read().unwrap().unwrap().2; | |
| 1591 | 추가: assert_eq!(terminal(&[decoded]).error, error); | |
| 1592 | 추가: bytes[33] = 14; | |
| 1593 | 추가: assert!(Reader::new(bytes.as_slice()).read().is_err()); | |
| 1594 | 추가: } | |
| 1595 | 추가: } |
| @@ -0,0 +1,35 @@ | ||
| 1 | 추가: use super::*; | |
| 2 | 추가: use std::io::{Error, ErrorKind}; | |
| 3 | 추가: | |
| 4 | 추가: #[test] | |
| 5 | 추가: fn storage_full_is_distinct_from_other_io_errors() { | |
| 6 | 추가: assert_eq!(io_error(ErrorKind::StorageFull.into()), ErrorCode::DiskFull); | |
| 7 | 추가: for kind in [ | |
| 8 | 추가: ErrorKind::PermissionDenied, | |
| 9 | 추가: ErrorKind::Other, | |
| 10 | 추가: ErrorKind::NotFound, | |
| 11 | 추가: ] { | |
| 12 | 추가: assert_eq!(io_error(kind.into()), ErrorCode::Io); | |
| 13 | 추가: } | |
| 14 | 추가: } | |
| 15 | 추가: | |
| 16 | 추가: #[cfg(target_os = "linux")] | |
| 17 | 추가: #[test] | |
| 18 | 추가: fn native_linux_enospc_is_disk_full() { | |
| 19 | 추가: assert_eq!(io_error(Error::from_raw_os_error(28)), ErrorCode::DiskFull); | |
| 20 | 추가: for code in [5, 13, 39, 112] { | |
| 21 | 추가: assert_eq!(io_error(Error::from_raw_os_error(code)), ErrorCode::Io); | |
| 22 | 추가: } | |
| 23 | 추가: } | |
| 24 | 추가: | |
| 25 | 추가: #[cfg(windows)] | |
| 26 | 추가: #[test] | |
| 27 | 추가: fn native_windows_disk_full_codes_are_distinct_from_access_denied() { | |
| 28 | 추가: for code in [39, 112] { | |
| 29 | 추가: assert_eq!( | |
| 30 | 추가: io_error(Error::from_raw_os_error(code)), | |
| 31 | 추가: ErrorCode::DiskFull | |
| 32 | 추가: ); | |
| 33 | 추가: } | |
| 34 | 추가: assert_eq!(io_error(Error::from_raw_os_error(5)), ErrorCode::Io); | |
| 35 | 추가: } |