team-ljyzipelo

공개

시스템 임시 폴더 실패에도 출력 디스크의 공간 부족 원인을 보존함

작성자
시로사키 하나
작성 시각
커밋
37300090279989160fdf1ec1c70ceae855127678
부모
8608fcc
이 시점의 파일 보기

변경된 파일 3개

+103-4
수정experiments/rust-archive-worker/src/spool.rs+11-0
@@ -57,11 +57,22 @@ pub(crate) fn random_name() -> Result<String> {
5757pub(crate) fn temporary() -> Result<File> {
5858 let placed =
5959 LOCATION.with(|location| location.borrow().as_ref().map(filesystem::Dir::temporary));
60추가: let destination_full = matches!(&placed, Some(Err(ErrorCode::DiskFull)));
6061 match placed {
6162 Some(Ok(file)) => return Ok(file),
6263 Some(Err(_)) => LOCATION.with(|location| *location.borrow_mut() = None),
6364 None => {}
6465 }
66추가: system_temporary().map_err(|error| {
67추가: if destination_full {
68추가: ErrorCode::DiskFull
69추가: } else {
70추가: error
71추가: }
72추가: })
73추가: }
74추가:
75추가: fn system_temporary() -> Result<File> {
6576 #[cfg(target_os = "linux")]
6677 {
6778 use std::os::unix::fs::OpenOptionsExt;
수정tests/rust-archive-worker/io_fault.c+9-0
@@ -55,6 +55,15 @@ int openat(int fd, const char *path, int flags, ...) {
5555 va_end(args);
5656 }
5757 const char *fault = getenv("ZIPELO_TEST_FAULT");
58추가: if (fault && !strncmp(fault, "destination-", 12)
59추가: && (((flags & O_TMPFILE) == O_TMPFILE) || ((flags & O_CREAT) && spool_name(path)))) {
60추가: if (strstr(fault, "named") && (flags & O_TMPFILE) == O_TMPFILE) {
61추가: errno = EOPNOTSUPP;
62추가: } else {
63추가: errno = strstr(fault, "edquot") ? EDQUOT : strstr(fault, "denied") ? EACCES : ENOSPC;
64추가: }
65추가: return -1;
66추가: }
5867 if (fault && (!strcmp(fault, "create-full") || !strcmp(fault, "create-denied"))
5968 && !strncmp(path, ".zipelo-", 8)) {
6069 errno = !strcmp(fault, "create-full") ? ENOSPC : EACCES;
수정tests/rust-archive-worker/spool_location.rs+83-4
@@ -3,11 +3,41 @@ use super::*;
33// 해제 작업의 원본 사본과 단계 임시 파일은 시스템 임시 폴더가 아니라 출력 폴더에 둠.
44// 시스템 임시 폴더를 쓸 수 없게 만들어도(/tmp 할당량 초과와 같은 상황) 해제가 성공해야 함.
55fn extract_without_system_temp(bytes: &[u8]) -> (Scratch, Vec<Message>) {
6추가: extract_unusable_system_temp(bytes, None, false)
7추가: }
8추가: fn extract_unusable_system_temp(
9추가: bytes: &[u8],
10추가: fault: Option<&str>,
11추가: file_at_temp_path: bool,
12추가: ) -> (Scratch, Vec<Message>) {
613 let s = Scratch::new();
714 let start = encrypted_start(&s, bytes);
8삭제: let mut child = s
9삭제: .worker()
10삭제: .env("TMPDIR", s.0.join("missing-temp"))
15추가: let temp = s.0.join("missing-temp");
16추가: if file_at_temp_path {
17추가: fs::write(&temp, b"keep").unwrap();
18추가: }
19추가: let mut command = s.worker();
20추가: command.env("TMPDIR", &temp);
21추가: if let Some(fault) = fault {
22추가: let shim = s.0.join("io_fault.so");
23추가: assert!(
24추가: Command::new("cc")
25추가: .args(["-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror"])
26추가: .arg(
27추가: PathBuf::from(env!("CARGO_MANIFEST_DIR"))
28추가: .join("../../tests/rust-archive-worker/io_fault.c")
29추가: )
30추가: .args(["-ldl", "-o"])
31추가: .arg(&shim)
32추가: .status()
33추가: .unwrap()
34추가: .success()
35추가: );
36추가: command
37추가: .env("LD_PRELOAD", shim)
38추가: .env("ZIPELO_TEST_FAULT", fault);
39추가: }
40추가: let mut child = command
1141 .stdin(Stdio::piped())
1242 .stdout(Stdio::piped())
1343 .stderr(Stdio::piped())
@@ -37,7 +67,11 @@ fn extract_without_system_temp(bytes: &[u8]) -> (Scratch, Vec<Message>) {
3767 let output = child.wait_with_output().unwrap();
3868 assert!(output.status.success(), "{:?}", output.stderr);
3969 assert!(output.stderr.is_empty());
40삭제: assert!(!s.0.join("missing-temp").exists());
70추가: if file_at_temp_path {
71추가: assert_eq!(fs::read(&temp).unwrap(), b"keep");
72추가: } else {
73추가: assert!(!temp.exists());
74추가: }
4175 (s, events)
4276}
4377
@@ -101,3 +135,48 @@ fn corrupt_archive_error_wins_over_read_only_destination() {
101135 assert_eq!(terminal(&events).cleanup, Cleanup::Complete);
102136 assert_eq!(fs::read_dir(&output).unwrap().count(), 0);
103137}
138추가:
139추가: #[test]
140추가: fn destination_space_or_quota_failure_survives_unusable_system_temp() {
141추가: let input = include_bytes!("fixtures/deflate.zip");
142추가: for fault in [
143추가: "destination-enospc",
144추가: "destination-edquot",
145추가: "destination-named-enospc",
146추가: "destination-named-edquot",
147추가: ] {
148추가: for file in [false, true] {
149추가: let (s, events) = extract_unusable_system_temp(input, Some(fault), file);
150추가: let terminal = terminal(&events);
151추가: assert_eq!(
152추가: terminal.outcome,
153추가: Outcome::Failed,
154추가: "{fault}/{file}: {events:?}"
155추가: );
156추가: assert_eq!(
157추가: terminal.error,
158추가: ErrorCode::DiskFull,
159추가: "{fault}/{file}: {events:?}"
160추가: );
161추가: assert_eq!(terminal.publication, Publication::None);
162추가: assert_eq!(terminal.cleanup, Cleanup::Complete);
163추가: assert_eq!(terminal.created_count, 0);
164추가: assert_only_outputs(&s, &[]);
165추가: assert_eq!(fs::read(s.0.join("input")).unwrap(), input);
166추가: }
167추가: }
168추가: }
169추가:
170추가: #[test]
171추가: fn destination_permission_failure_with_unusable_system_temp_stays_io() {
172추가: for file in [false, true] {
173추가: let (s, events) = extract_unusable_system_temp(
174추가: include_bytes!("fixtures/deflate.zip"),
175추가: Some("destination-denied"),
176추가: file,
177추가: );
178추가: assert_eq!(terminal(&events).error, ErrorCode::Io, "{events:?}");
179추가: assert_eq!(terminal(&events).outcome, Outcome::Failed);
180추가: assert_only_outputs(&s, &[]);
181추가: }
182추가: }