team-ljyzipelo

공개

GZ 저장 이름 선택과 대소문자 압축파일 필터를 수정함

작성자
호시노 히나타
작성 시각
커밋
0a0eef33e792890407cffca29251ff08f6399421
부모
6d3da49
이 시점의 파일 보기

변경된 파일 10개

+305-18
수정experiments/rust-ui-memory-app/src/archive_dialog.rs+33-5
@@ -8,6 +8,8 @@ pub enum Purpose {
88 Destination,
99 Retry,
1010 SaveZip,
11추가: SaveGzip,
12추가: RetryGzip,
1113}
1214
1315#[derive(Clone, Debug)]
@@ -21,6 +23,25 @@ pub trait Dialogs {
2123 fn choose(&mut self, request: DialogRequest) -> Result<Option<Vec<PathBuf>>, String>;
2224}
2325
26추가: pub fn archive_filters() -> Vec<(&'static str, Vec<String>)> {
27추가: let mut extensions = Vec::new();
28추가: for extension in ["zip", "7z", "tar", "gz", "tgz"] {
29추가: let mut variants = vec![String::new()];
30추가: for character in extension.chars() {
31추가: let mut next = Vec::new();
32추가: for prefix in variants {
33추가: next.push(format!("{prefix}{character}"));
34추가: if character.is_ascii_alphabetic() {
35추가: next.push(format!("{prefix}{}", character.to_ascii_uppercase()));
36추가: }
37추가: }
38추가: variants = next;
39추가: }
40추가: extensions.extend(variants);
41추가: }
42추가: vec![("압축파일", extensions), ("모든 파일", vec!["*".into()])]
43추가: }
44추가:
2445#[derive(Default)]
2546pub struct NativeDialogs;
2647
@@ -29,11 +50,13 @@ impl Dialogs for NativeDialogs {
2950 let dialog = rfd::FileDialog::new().set_directory(request.directory);
3051 let answer =
3152 std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| match request.purpose {
32삭제: Purpose::Open => dialog
33삭제: .set_title("압축파일 열기")
34삭제: .add_filter("압축파일", &["zip", "7z", "tar", "gz", "tgz"])
35삭제: .pick_file()
36삭제: .map(|path| vec![path]),
53추가: Purpose::Open => {
54추가: let mut dialog = dialog.set_title("압축파일 열기");
55추가: for (name, extensions) in archive_filters() {
56추가: dialog = dialog.add_filter(name, &extensions);
57추가: }
58추가: dialog.pick_file().map(|path| vec![path])
59추가: }
3760 Purpose::Files => dialog.set_title("파일 추가").pick_files(),
3861 Purpose::Folder => dialog
3962 .set_title("폴더 추가")
@@ -43,6 +66,11 @@ impl Dialogs for NativeDialogs {
4366 .set_title("압축을 풀 폴더 선택")
4467 .pick_folder()
4568 .map(|path| vec![path]),
69추가: Purpose::SaveGzip | Purpose::RetryGzip => dialog
70추가: .set_title("압축 해제 파일 저장")
71추가: .set_file_name(request.file_name)
72추가: .save_file()
73추가: .map(|path| vec![path]),
4674 Purpose::SaveZip => dialog
4775 .set_title("ZIP 파일 저장")
4876 .set_file_name(request.file_name)
수정experiments/rust-ui-memory-app/src/archive_present.rs+20-0
@@ -362,3 +362,23 @@ pub fn activity_text(model: &Model, creating: bool) -> &'static str {
362362 })
363363 }
364364}
365추가:
366추가: pub fn valid_output_leaf(name: &str) -> bool {
367추가: valid_leaf(name) && worker_protocol::archive::valid_name(name, false).is_ok()
368추가: }
369추가:
370추가: pub fn gzip_output_name(archive: &Path) -> String {
371추가: let file_name = archive
372추가: .file_name()
373추가: .and_then(|name| name.to_str())
374추가: .unwrap_or("");
375추가: let candidate = file_name
376추가: .rsplit_once('.')
377추가: .filter(|(_, suffix)| suffix.eq_ignore_ascii_case("gz"))
378추가: .map_or(file_name, |(stem, _)| stem);
379추가: if valid_output_leaf(candidate) {
380추가: candidate.to_owned()
381추가: } else {
382추가: "압축 해제 파일".into()
383추가: }
384추가: }
수정experiments/rust-ui-memory-app/src/archive_screen.rs+61-12
@@ -112,13 +112,7 @@ impl ArchiveApp {
112112 self.clear_password();
113113 self.destination = present::default_destination(&archive);
114114 self.automatic_destination = true;
115삭제: self.gzip_name = archive
116삭제: .file_name()
117삭제: .unwrap_or_default()
118삭제: .to_string_lossy()
119삭제: .strip_suffix(".gz")
120삭제: .unwrap_or("압축 해제 파일")
121삭제: .into();
115추가: self.gzip_name = present::gzip_output_name(&archive);
122116 self.selected_only = false;
123117 self.folder.clear();
124118 self.search.clear();
@@ -286,16 +280,26 @@ impl ArchiveApp {
286280 if self.model.busy() {
287281 return;
288282 }
283추가: let gzip = self
284추가: .model
285추가: .list_id
286추가: .as_ref()
287추가: .is_some_and(|id| id.format == Format::Gzip);
288추가: let purpose = match (purpose, gzip) {
289추가: (Purpose::Destination, true) => Purpose::SaveGzip,
290추가: (Purpose::Retry, true) => Purpose::RetryGzip,
291추가: _ => purpose,
292추가: };
289293 let directory = match purpose {
290294 Purpose::SaveZip => self.zip_folder.clone(),
291삭제: Purpose::Destination => self
295추가: Purpose::Destination | Purpose::SaveGzip => self
292296 .model
293297 .archive
294298 .as_ref()
295299 .and_then(|path| path.parent())
296300 .map(Path::to_path_buf)
297301 .unwrap_or_else(present::home_directory),
298삭제: Purpose::Retry => self.destination.clone(),
302추가: Purpose::Retry | Purpose::RetryGzip => self.destination.clone(),
299303 _ => self
300304 .sources
301305 .last()
@@ -306,7 +310,11 @@ impl ArchiveApp {
306310 let request = DialogRequest {
307311 purpose,
308312 directory,
309삭제: file_name: self.zip_name.clone(),
313추가: file_name: if matches!(purpose, Purpose::SaveGzip | Purpose::RetryGzip) {
314추가: self.gzip_name.clone()
315추가: } else {
316추가: self.zip_name.clone()
317추가: },
310318 };
311319 match self.dialogs.choose(request) {
312320 Ok(Some(paths)) if !paths.is_empty() => {
@@ -331,6 +339,33 @@ impl ArchiveApp {
331339 self.begin_extract();
332340 }
333341 }
342추가: Purpose::SaveGzip | Purpose::RetryGzip => {
343추가: let Some(name) = path.file_name().and_then(|name| name.to_str()) else {
344추가: self.ui_error = Some("저장할 파일 이름을 확인하세요".into());
345추가: return;
346추가: };
347추가: if !present::valid_output_leaf(name) {
348추가: self.ui_error = Some("저장할 파일 이름을 확인하세요".into());
349추가: return;
350추가: }
351추가: let name = name.to_owned();
352추가: self.choose_destination(
353추가: path.parent().unwrap_or(Path::new("/")).to_path_buf(),
354추가: );
355추가: self.gzip_name = name.clone();
356추가: self.selected_only = !self.model.selected.is_empty();
357추가: if purpose == Purpose::RetryGzip {
358추가: if let Some(Start::Extract {
359추가: gzip_output_name, ..
360추가: }) = &mut self.last_request
361추가: {
362추가: *gzip_output_name = Some(name);
363추가: }
364추가: self.retry();
365추가: } else {
366추가: self.begin_extract();
367추가: }
368추가: }
334369 Purpose::SaveZip => {
335370 if let Some(name) = path.file_name().and_then(|name| name.to_str()) {
336371 self.zip_name = name.to_owned();
@@ -1027,7 +1062,19 @@ impl ArchiveApp {
10271062 let action = if success {
10281063 Some(("폴더 열기", true))
10291064 } else if conflict {
1030삭제: Some(("다른 폴더에 풀기", !uncertain || self.checked_destination))
1065추가: Some((
1066추가: if self
1067추가: .model
1068추가: .list_id
1069추가: .as_ref()
1070추가: .is_some_and(|id| id.format == Format::Gzip)
1071추가: {
1072추가: "다른 이름으로 저장"
1073추가: } else {
1074추가: "다른 폴더에 풀기"
1075추가: },
1076추가: !uncertain || self.checked_destination,
1077추가: ))
10311078 } else if t
10321079 .as_ref()
10331080 .is_some_and(|t| t.error == Some(ErrorCode::SourceChanged))
@@ -1054,7 +1101,9 @@ impl ArchiveApp {
10541101 if primary {
10551102 match action.map(|(label, _)| label) {
10561103 Some("폴더 열기") => folder = true,
1057삭제: Some("다른 폴더에 풀기") => choose = true,
1104추가: Some("다른 폴더에 풀기" | "다른 이름으로 저장") => {
1105추가: choose = true
1106추가: }
10581107 Some("압축파일 다시 열기") => reopen = true,
10591108 Some("다시 시도" | "다시 만들기") => retry = true,
10601109 _ => {}
추가tests/rust-app-real-worker/fixtures/sample.gz

바이너리 파일이라 Diff를 표시하지 않아요.

파일 내려받기
수정tests/rust-app-real-worker/flows.rs+1-0
@@ -310,6 +310,7 @@ mod screen {
310310 }
311311 include!("password_flows.rs");
312312 include!("selection_flows.rs");
313추가: include!("native_dialog_flows.rs");
313314
314315 fn archive_flow(name: &str, format: Format) {
315316 let scratch = Scratch::new();
추가tests/rust-app-real-worker/native_dialog_flows.rs+86-0
@@ -0,0 +1,86 @@
1추가: fn native_fixture(scratch: &Scratch, fixture: &str, name: &str) -> PathBuf {
2추가: let target = scratch.path(name);
3추가: fs::copy(
4추가: Path::new(env!("CARGO_MANIFEST_DIR"))
5추가: .join("../../tests/rust-app-real-worker/fixtures")
6추가: .join(fixture),
7추가: &target,
8추가: ).unwrap();
9추가: target
10추가: }
11추가:
12추가: #[test]
13추가: fn raw_gzip_save_dialog_corrects_names_and_preserves_cancel_and_conflict_retry() {
14추가: use zipelo_ui_memory_app::archive_dialog::Purpose;
15추가: let mut names = vec![".gz", "report.GZ", "report.Gz", "report.gz"];
16추가: #[cfg(unix)]
17추가: names.push("report:2026.gz");
18추가: for name in names {
19추가: let scratch = Scratch::new();
20추가: let archive = native_fixture(&scratch, "sample.gz", name);
21추가: let original = fs::read(&archive).unwrap();
22추가: let output = make_directory(&scratch.path("output"));
23추가: let (factory, observed) = observed_factory();
24추가: let mut screen = Screen::new(factory);
25추가: screen.open(&archive);
26추가: assert_eq!(screen.app.model.list_id.as_ref().unwrap().format, Format::Gzip);
27추가: screen.click("압축해제");
28추가: assert!(!screen.app.model.busy());
29추가: assert_eq!(observed.borrow().jobs.len(), 1);
30추가: let request = screen.dialogs.0.borrow().requests.last().unwrap().clone();
31추가: assert_eq!(request.purpose, Purpose::SaveGzip);
32추가: assert_eq!(request.directory, scratch.0);
33추가: assert_eq!(request.file_name, if name == ".gz" || name.contains(':') { "압축 해제 파일" } else { "report" });
34추가: let existing = output.join("기존 파일.txt");
35추가: fs::write(&existing, b"preserve").unwrap();
36추가: screen.dialogs.0.borrow_mut().answers.push_back(Some(vec![existing.clone()]));
37추가: screen.click("압축해제");
38추가: let deadline = Instant::now() + Duration::from_secs(10);
39추가: while screen.app.model.busy() {
40추가: screen.render(vec![]);
41추가: assert!(Instant::now() < deadline);
42추가: std::thread::sleep(Duration::from_millis(2));
43추가: }
44추가: assert_eq!(screen.app.model.terminal.as_ref().unwrap().error, Some(ErrorCode::Conflict));
45추가: assert_eq!(fs::read(&existing).unwrap(), b"preserve");
46추가: screen.click("다른 이름으로 저장");
47추가: assert!(!screen.app.model.busy());
48추가: assert_eq!(observed.borrow().jobs.len(), 2);
49추가: assert_eq!(screen.dialogs.0.borrow().requests.last().unwrap().purpose, Purpose::RetryGzip);
50추가: let saved = output.join("사용자 이름.txt");
51추가: screen.dialogs.0.borrow_mut().answers.push_back(Some(vec![saved.clone()]));
52추가: screen.click("다른 이름으로 저장");
53추가: screen.settle();
54추가: assert_eq!(fs::read(saved).unwrap(), b"Zipelo real worker flow\n");
55추가: assert_eq!(fs::read(existing).unwrap(), b"preserve");
56추가: assert_eq!(fs::read(&archive).unwrap(), original);
57추가: assert!(matches!(
58추가: observed.borrow().starts.last(),
59추가: Some(Start::Extract { destination, gzip_output_name: Some(name), .. })
60추가: if destination == &output && name == "사용자 이름.txt"
61추가: ));
62추가: assert_reaped(&observed);
63추가: }
64추가: }
65추가:
66추가: #[test]
67추가: fn mixed_case_zip_names_open_and_extract_through_native_dialog_responses() {
68추가: use zipelo_ui_memory_app::archive_dialog::Purpose;
69추가: for name in ["sample.ZIP", "sample.Zip", "sample.zIp"] {
70추가: let scratch = Scratch::new();
71추가: let archive = native_fixture(&scratch, "sample.zip", name);
72추가: let original = fs::read(&archive).unwrap();
73추가: let output = make_directory(&scratch.path("output"));
74추가: let (factory, observed) = observed_factory();
75추가: let mut screen = Screen::new(factory);
76추가: screen.dialogs.0.borrow_mut().answers.push_back(Some(vec![archive.clone()]));
77추가: screen.click("열기");
78추가: screen.settle();
79추가: assert_eq!(screen.dialogs.0.borrow().requests[0].purpose, Purpose::Open);
80추가: assert_eq!(screen.app.model.list_id.as_ref().unwrap().format, Format::Zip);
81추가: screen.extract(&output);
82추가: assert_eq!(fs::read(output.join("content.txt")).unwrap(), b"Zipelo real worker flow\n");
83추가: assert_eq!(fs::read(archive).unwrap(), original);
84추가: assert_reaped(&observed);
85추가: }
86추가: }
추가tests/rust-app-ui/native_dialogs.rs+77-0
@@ -0,0 +1,77 @@
1추가: use std::{collections::BTreeSet, path::Path};
2추가: use zipelo_ui_memory_app::{
3추가: archive_dialog::archive_filters,
4추가: archive_present::{gzip_output_name, valid_output_leaf},
5추가: };
6추가:
7추가: #[test]
8추가: fn archive_filter_contains_every_case_variant_and_all_files_option() {
9추가: let filters = archive_filters();
10추가: assert_eq!(filters.len(), 2);
11추가: assert_eq!(filters[0].0, "압축파일");
12추가: let expected = [
13추가: "zip", "ziP", "zIp", "zIP", "Zip", "ZiP", "ZIp", "ZIP", "7z", "7Z", "tar", "taR", "tAr",
14추가: "tAR", "Tar", "TaR", "TAr", "TAR", "gz", "gZ", "Gz", "GZ", "tgz", "tgZ", "tGz", "tGZ",
15추가: "Tgz", "TgZ", "TGz", "TGZ",
16추가: ]
17추가: .into_iter()
18추가: .map(str::to_owned)
19추가: .collect::<BTreeSet<_>>();
20추가: assert_eq!(
21추가: filters[0].1.iter().cloned().collect::<BTreeSet<_>>(),
22추가: expected
23추가: );
24추가: assert_eq!(filters[0].1.len(), expected.len());
25추가: assert_eq!(filters[1], ("모든 파일", vec!["*".to_owned()]));
26추가: }
27추가:
28추가: #[test]
29추가: fn gzip_suggested_names_are_portable_and_preserve_valid_stems() {
30추가: for name in [
31추가: ".gz",
32추가: ".GZ",
33추가: "report:2026.gz",
34추가: "report?2026.gz",
35추가: "CON.gz",
36추가: "COM1.gz",
37추가: "name..gz",
38추가: "name .gz",
39추가: ] {
40추가: assert_eq!(
41추가: gzip_output_name(Path::new(name)),
42추가: "압축 해제 파일",
43추가: "{name}"
44추가: );
45추가: }
46추가: for (name, expected) in [
47추가: ("report.gz", "report"),
48추가: ("report.GZ", "report"),
49추가: ("report.Gz", "report"),
50추가: ("한글.gz", "한글"),
51추가: ("input.archive", "input.archive"),
52추가: ] {
53추가: assert_eq!(gzip_output_name(Path::new(name)), expected);
54추가: }
55추가: for name in [
56추가: "",
57추가: ".",
58추가: "..",
59추가: "../file",
60추가: "dir/file",
61추가: "dir\\file",
62추가: "a:b",
63추가: "a*",
64추가: "a?",
65추가: "a|b",
66추가: "a<b",
67추가: "a>b",
68추가: "a\"b",
69추가: "NUL.txt",
70추가: "name.",
71추가: "name ",
72추가: "control\n",
73추가: ] {
74추가: assert!(!valid_output_leaf(name), "{name:?}");
75추가: }
76추가: assert!(valid_output_leaf("사용자 이름.txt"));
77추가: }
수정tests/rust-app-ui/regressions.rs+7-1
@@ -1,6 +1,8 @@
11#[cfg(feature = "ui")]
22mod dialogs;
33mod fake;
4추가: #[cfg(feature = "ui")]
5추가: mod native_dialogs;
46use fake::*;
57use std::path::PathBuf;
68use zipelo_ui_memory_app::archive_ui::*;
@@ -663,7 +665,11 @@ fn extract_button_sends_gzip_name_only_for_raw_gzip() {
663665 .0
664666 .borrow_mut()
665667 .answers
666삭제: .push_back(Some(vec![scratch.0.clone()]));
668추가: .push_back(Some(vec![if format == Format::Gzip {
669추가: scratch.0.join("압축 해제 파일")
670추가: } else {
671추가: scratch.0.clone()
672추가: }]));
667673 app.set_dialogs(Box::new(dialogs));
668674 let texts = render(&mut app, vec![]);
669675 let button = texts
수정tests/rust-app-ui/toolbar.rs+18-0
@@ -327,3 +327,21 @@ fn excluding_a_child_after_folder_selection_does_not_restore_it_during_extractio
327327 Some(Start::Extract { selection: Selection::EntryIds(ids), .. }) if ids == &vec![2]
328328 ));
329329}
330추가:
331추가: #[test]
332추가: fn gzip_save_cancel_and_invalid_output_do_not_start_an_extraction() {
333추가: let scratch = Folder::new();
334추가: let factory = FakeFactory::default();
335추가: factory.state.borrow_mut().list_format = Some(Format::Gzip);
336추가: let mut app = loaded(&scratch, &factory);
337추가: let dialogs = TestDialogs::default();
338추가: app.set_dialogs(Box::new(dialogs.clone()));
339추가: let ctx = egui::Context::default();
340추가: policy_click(&ctx, &mut app, "압축해제");
341추가: assert_eq!(factory.state.borrow().starts.len(), 1);
342추가: assert_eq!(dialogs.0.borrow().requests[0].purpose, Purpose::SaveGzip);
343추가: dialogs.0.borrow_mut().answers.push_back(Some(vec![scratch.0.join("invalid:name")]));
344추가: policy_click(&ctx, &mut app, "압축해제");
345추가: assert_eq!(factory.state.borrow().starts.len(), 1);
346추가: assert!(!app.model.busy());
347추가: }
수정tests/ui-redesign/README.md+2-0
@@ -16,6 +16,8 @@ tests/rust-app-real-worker/selection_flows.rs는 전체, 파일, 폴더, 혼합,
1616
1717Enter는 초점이 있는 버튼만 활성화하며 암호 입력란 제출만 예외임. 완료 + Unconfirmed 안내는 자세히 보기에, Failed 내구성 경고와 실패 및 부분 추출의 Unconfirmed 안내는 본문에 표시함. 자동 풀 위치의 Unix 0700 생성, 렌더러 폴백과 계약 revision 2도 기존 회귀 시험을 유지함.
1818
19추가: 단일 파일 GZ는 운영체제 저장 창에서 출력 이름과 위치를 선택하며 TAR.GZ는 폴더 선택을 유지함. 빈 이름, 금지 문자와 예약 이름은 안전한 기본 이름으로 제안하고 반환된 이름도 검증함. native_dialog_flows.rs는 GZ의 취소, 충돌 뒤 이름 변경, 원본 보존과 대소문자 ZIP 열기를 실제 작업자로 확인함. native_dialogs.rs는 확장자 대소문자 조합 30개와 모든 파일 선택지 및 GZ 기본 이름을 검증함.
20추가:
1921## 화면 재현
2022
2123Xvfb, xdotool, ImageMagick import와 시스템 CJK 글꼴이 필요함. 촬영 실행 파일은 실제 eframe 컴포넌트에 합성 목록을 전달하며 압축파일을 읽거나 결과물을 저장하지 않음.