team-ljyzipelo

공개

게시 결과와 이동된 임시 파일의 상태를 재확인함

작성자
시로사키 하나
작성 시각
커밋
5e45e33c8280b3380445967a2496d0f70b2aa80b
부모
3441dde
이 시점의 파일 보기

변경된 파일 3개

+122-1
수정experiments/rust-archive-worker/src/filesystem.rs+18-1
@@ -842,7 +842,7 @@ pub(crate) fn publish_reader_steps(
842842 }
843843 if !temp_consumed {
844844 match dir.existing(&temp) {
845삭제: Ok(None) => {}
845추가: Ok(None) => result.cleanup = Cleanup::Unconfirmed,
846846 Ok(Some(current)) if Some(&current.object) == identity.as_ref() => {
847847 if dir.remove(&temp) {
848848 publication_activity(&mut finish, check);
@@ -872,6 +872,23 @@ pub(crate) fn publish_reader_steps(
872872 publication_activity(&mut finish, check);
873873 }
874874 }
875추가: if result.created {
876추가: // 이름 기반 게시 뒤에도 결과가 생성한 파일인지 확인함.
877추가: let verified = match dir.existing(&leaf) {
878추가: Ok(Some(current)) if Some(&current.object) == identity.as_ref() => Ok(()),
879추가: Ok(_) => Err(ErrorCode::Conflict),
880추가: Err(error) => Err(error),
881추가: };
882추가: if let Err(error) = verified {
883추가: result.created = false;
884추가: result.uncertain = true;
885추가: result.durability = Durability::Unconfirmed;
886추가: if result.cleanup == Cleanup::Complete {
887추가: result.cleanup = Cleanup::Unconfirmed;
888추가: }
889추가: finish = Err(error);
890추가: }
891추가: }
875892 finish
876893 })();
877894 result.error = prepared.err();
수정tests/rust-archive-worker/io_fault.c+25-0
@@ -133,6 +133,16 @@ int fstatvfs(int fd, struct statvfs *value) {
133133int fsync(int fd) {
134134 const char *fault = getenv("ZIPELO_TEST_FAULT");
135135 struct stat st;
136추가: if (fault && !strcmp(fault, "move-on-sync") && output_file(fd)) {
137추가: char link[64], path[4096], moved[4112];
138추가: snprintf(link, sizeof(link), "/proc/self/fd/%d", fd);
139추가: ssize_t count = readlink(link, path, sizeof(path) - 1);
140추가: if (count < 0) { errno = EIO; return -1; }
141추가: path[count] = 0;
142추가: snprintf(moved, sizeof(moved), "%s.owned", path);
143추가: if (rename(path, moved)) { errno = EIO; return -1; }
144추가: return real_fsync(fd);
145추가: }
136146 int directory_full = fault && !strcmp(fault, "dir-sync-full")
137147 && !fstat(fd, &st) && S_ISDIR(st.st_mode);
138148 if (directory_full || (fault && !strcmp(fault, "sync-full") && output_file(fd))) {
@@ -174,6 +184,21 @@ int unlinkat(int fd, const char *path, int flags) {
174184 return real_unlinkat(fd, path, flags);
175185}
176186
187추가: int linkat(int oldfd, const char *oldname, int newfd, const char *newname, int flags) {
188추가: int (*real_linkat)(int, const char *, int, const char *, int) = dlsym(RTLD_NEXT, "linkat");
189추가: const char *fault = getenv("ZIPELO_TEST_FAULT");
190추가: if (fault && !strcmp(fault, "swap-on-link") && !strncmp(oldname, ".zipelo-", 8)) {
191추가: char moved[512];
192추가: snprintf(moved, sizeof(moved), "%s.owned", oldname);
193추가: if (renameat(oldfd, oldname, oldfd, moved)) return -1;
194추가: int replacement = real_openat(oldfd, oldname, O_CREAT | O_EXCL | O_WRONLY, 0600);
195추가: if (replacement < 0) return -1;
196추가: real_write(replacement, "unrelated replacement", 21);
197추가: close(replacement);
198추가: }
199추가: return real_linkat(oldfd, oldname, newfd, newname, flags);
200추가: }
201추가:
177202int renameat(int oldfd, const char *oldname, int newfd, const char *newname) {
178203 const char *fault = getenv("ZIPELO_TEST_FAULT");
179204 if (fault && !strcmp(fault, "replace-fail")) { errno = EIO; return -1; }
수정tests/rust-archive-worker/partial_output.rs+79-0
@@ -316,3 +316,82 @@ fn cleanup_does_not_delete_a_replacement_at_the_temporary_name() {
316316 }
317317 }
318318}
319추가:
320추가: #[test]
321추가: fn late_temporary_name_swap_is_never_reported_as_created_output() {
322추가: for operation in ["extract", "extract-nested", "seven-zip", "recovery"] {
323추가: let s = Scratch::new();
324추가: let (request, output) = prepare(&s, operation);
325추가: let original = fs::read(s.0.join("archive")).ok();
326추가: let events = run(&s, request, "swap-on-link");
327추가: let end = terminal(&events);
328추가: assert_eq!(end.outcome, Outcome::Failed, "{operation}: {events:?}");
329추가: assert_eq!(end.created_count, 0, "{operation}: {events:?}");
330추가: assert_eq!(end.error, ErrorCode::Conflict);
331추가: assert_eq!(end.publication, Publication::Uncertain);
332추가: assert_eq!(end.durability, Durability::Unconfirmed);
333추가: assert_eq!(end.cleanup, Cleanup::Unconfirmed);
334추가: assert_eq!(end.retained_partial_count, 0);
335추가: assert!(!events.iter().any(|e| matches!(
336추가: e,
337추가: Message::Output {
338추가: disposition: Disposition::Created,
339추가: ..
340추가: }
341추가: )));
342추가: assert_eq!(
343추가: events
344추가: .iter()
345추가: .filter(|e| matches!(
346추가: e,
347추가: Message::Output {
348추가: disposition: Disposition::CommitUncertain,
349추가: ..
350추가: }
351추가: ))
352추가: .count(),
353추가: 1
354추가: );
355추가: assert_eq!(fs::read(&output).unwrap(), b"unrelated replacement");
356추가: assert_eq!(fs::read(s.0.join("source")).unwrap(), SOURCE);
357추가: assert_eq!(fs::read(s.0.join("archive")).ok(), original);
358추가: let replacements: Vec<_> = fs::read_dir(output.parent().unwrap())
359추가: .unwrap()
360추가: .map(|e| e.unwrap().path())
361추가: .filter(|p| p.file_name().unwrap().to_string_lossy().ends_with(".tmp"))
362추가: .collect();
363추가: assert_eq!(replacements.len(), 1);
364추가: assert_eq!(
365추가: fs::read(&replacements[0]).unwrap(),
366추가: b"unrelated replacement"
367추가: );
368추가: }
369추가: }
370추가:
371추가: #[test]
372추가: fn moved_temporary_file_is_not_reported_cleaned() {
373추가: for operation in ["extract", "extract-nested", "seven-zip", "recovery"] {
374추가: let s = Scratch::new();
375추가: let (request, output) = prepare(&s, operation);
376추가: let events = run(&s, request, "move-on-sync");
377추가: let end = terminal(&events);
378추가: assert!(!output.exists());
379추가: assert_eq!(end.outcome, Outcome::Failed, "{operation}: {events:?}");
380추가: assert_eq!(end.error, ErrorCode::Conflict);
381추가: assert_eq!(end.publication, Publication::None);
382추가: assert_eq!(end.created_count, 0);
383추가: let owned: Vec<_> = fs::read_dir(output.parent().unwrap())
384추가: .unwrap()
385추가: .map(|e| e.unwrap().path())
386추가: .filter(|p| p.file_name().unwrap().to_string_lossy().ends_with(".owned"))
387추가: .collect();
388추가: assert_eq!(owned.len(), 1);
389추가: assert!(!fs::read(&owned[0]).unwrap().is_empty());
390추가: if operation.starts_with("extract") {
391추가: assert_eq!(fs::read(&owned[0]).unwrap(), SOURCE);
392추가: }
393추가: assert_eq!(end.cleanup, Cleanup::Unconfirmed, "{events:?}");
394추가: assert_eq!(end.retained_partial_count, 0);
395추가: assert_eq!(fs::read(s.0.join("source")).unwrap(), SOURCE);
396추가: }
397추가: }