게시 결과와 이동된 임시 파일의 상태를 재확인함
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
5e45e33c8280b3380445967a2496d0f70b2aa80b- 부모
- 3441dde
변경된 파일 3개
+122-1| @@ -842,7 +842,7 @@ pub(crate) fn publish_reader_steps( | ||
| 842 | 842 | } |
| 843 | 843 | if !temp_consumed { |
| 844 | 844 | match dir.existing(&temp) { |
| 845 | 삭제: Ok(None) => {} | |
| 845 | 추가: Ok(None) => result.cleanup = Cleanup::Unconfirmed, | |
| 846 | 846 | Ok(Some(current)) if Some(¤t.object) == identity.as_ref() => { |
| 847 | 847 | if dir.remove(&temp) { |
| 848 | 848 | publication_activity(&mut finish, check); |
| @@ -872,6 +872,23 @@ pub(crate) fn publish_reader_steps( | ||
| 872 | 872 | publication_activity(&mut finish, check); |
| 873 | 873 | } |
| 874 | 874 | } |
| 875 | 추가: if result.created { | |
| 876 | 추가: // 이름 기반 게시 뒤에도 결과가 생성한 파일인지 확인함. | |
| 877 | 추가: let verified = match dir.existing(&leaf) { | |
| 878 | 추가: Ok(Some(current)) if Some(¤t.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 | 추가: } | |
| 875 | 892 | finish |
| 876 | 893 | })(); |
| 877 | 894 | result.error = prepared.err(); |
| @@ -133,6 +133,16 @@ int fstatvfs(int fd, struct statvfs *value) { | ||
| 133 | 133 | int fsync(int fd) { |
| 134 | 134 | const char *fault = getenv("ZIPELO_TEST_FAULT"); |
| 135 | 135 | 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 | 추가: } | |
| 136 | 146 | int directory_full = fault && !strcmp(fault, "dir-sync-full") |
| 137 | 147 | && !fstat(fd, &st) && S_ISDIR(st.st_mode); |
| 138 | 148 | if (directory_full || (fault && !strcmp(fault, "sync-full") && output_file(fd))) { |
| @@ -174,6 +184,21 @@ int unlinkat(int fd, const char *path, int flags) { | ||
| 174 | 184 | return real_unlinkat(fd, path, flags); |
| 175 | 185 | } |
| 176 | 186 | |
| 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 | 추가: | |
| 177 | 202 | int renameat(int oldfd, const char *oldname, int newfd, const char *newname) { |
| 178 | 203 | const char *fault = getenv("ZIPELO_TEST_FAULT"); |
| 179 | 204 | if (fault && !strcmp(fault, "replace-fail")) { errno = EIO; return -1; } |
| @@ -316,3 +316,82 @@ fn cleanup_does_not_delete_a_replacement_at_the_temporary_name() { | ||
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | } |
| 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 | 추가: } |