team-ljyzipelo

공개

임시 폴더 정체를 확인한 뒤 정리

작성자
호시노 히나타
작성 시각
커밋
f490208dd213b363582e6b482a17826dca9ad5b9
부모
26121d4
이 시점의 파일 보기

변경된 파일 3개

+112-9
수정experiments/rust-ui-memory-app/src/archive_present.rs+68-5
@@ -503,11 +503,72 @@ fn private_dir(path: &Path) -> io::Result<()> {
503503 builder.create(path)
504504}
505505
506추가: pub struct OpenRoot {
507추가: path: PathBuf,
508추가: handle: fs::File,
509추가: identity: worker_protocol::protocol::SourceObject,
510추가: }
511추가:
512추가: impl OpenRoot {
513추가: fn capture(path: PathBuf) -> io::Result<Self> {
514추가: let handle = open_root_handle(&path)?;
515추가: let identity = worker_protocol::filesystem::object(&handle)
516추가: .map_err(|_| io::Error::other("임시 폴더 식별 실패"))?;
517추가: Ok(Self {
518추가: path,
519추가: handle,
520추가: identity,
521추가: })
522추가: }
523추가:
524추가: pub fn path(&self) -> &Path {
525추가: &self.path
526추가: }
527추가:
528추가: pub fn is_current(&self) -> bool {
529추가: // 원본 핸들을 유지해 삭제된 inode가 재사용되어도 같다고 판정하지 않음.
530추가: self.handle.metadata().is_ok()
531추가: && open_root_handle(&self.path)
532추가: .ok()
533추가: .and_then(|file| worker_protocol::filesystem::object(&file).ok())
534추가: .is_some_and(|identity| identity == self.identity)
535추가: }
536추가: }
537추가:
538추가: fn open_root_handle(path: &Path) -> io::Result<fs::File> {
539추가: let mut options = fs::OpenOptions::new();
540추가: options.read(true);
541추가: #[cfg(target_os = "linux")]
542추가: {
543추가: use std::os::unix::fs::OpenOptionsExt;
544추가: options.custom_flags(0x20000); // 심볼릭 링크를 따라가지 않음.
545추가: }
546추가: #[cfg(windows)]
547추가: {
548추가: use std::os::windows::fs::OpenOptionsExt;
549추가: // 폴더 자체를 열며 재분석 지점을 따라가지 않음.
550추가: options.custom_flags(0x02000000 | 0x00200000);
551추가: }
552추가: let file = options.open(path)?;
553추가: let metadata = file.metadata()?;
554추가: if !metadata.is_dir() || fs::symlink_metadata(path)?.file_type().is_symlink() {
555추가: return Err(io::Error::other("임시 폴더가 아님"));
556추가: }
557추가: #[cfg(windows)]
558추가: {
559추가: use std::os::windows::fs::MetadataExt;
560추가: if metadata.file_attributes() & 0x400 != 0 {
561추가: return Err(io::Error::other("재분석 지점은 임시 폴더로 쓰지 않음"));
562추가: }
563추가: }
564추가: Ok(file)
565추가: }
566추가:
506567/// 압축파일 안 파일을 기본 프로그램으로 열 때 쓸 임시 폴더를 만듦.
507568/// 압축파일과 같은 폴더에 만들고, 그곳에 만들 수 없으면 시스템 임시 폴더를 씀.
508569/// 숨김 폴더로 만들지 않음. snap으로 설치한 Firefox 등은 홈 바로 아래 숨김 폴더와
509570/// 시스템 임시 폴더의 파일을 읽지 못해 열기 요청을 조용히 무시함.
510삭제: pub fn create_open_root(archive: &Path) -> io::Result<PathBuf> {
571추가: pub fn create_open_root(archive: &Path) -> io::Result<OpenRoot> {
511572 let name = archive.file_name().unwrap_or_default().to_string_lossy();
512573 let mut error = None;
513574 if let Some(parent) = archive.parent().filter(|p| !p.as_os_str().is_empty()) {
@@ -515,7 +576,7 @@ pub fn create_open_root(archive: &Path) -> io::Result<PathBuf> {
515576 for _ in 0..8 {
516577 let path = unique_folder(&base);
517578 match private_dir(&path) {
518삭제: Ok(()) => return Ok(path),
579추가: Ok(()) => return OpenRoot::capture(path),
519580 Err(e) if e.kind() == io::ErrorKind::AlreadyExists => continue,
520581 Err(e) => {
521582 error = Some(e);
@@ -527,7 +588,7 @@ pub fn create_open_root(archive: &Path) -> io::Result<PathBuf> {
527588 let base = std::env::temp_dir().join(format!("zipelo-{}-{name}", std::process::id()));
528589 let path = unique_folder(&base);
529590 private_dir(&path).map_err(|e| error.unwrap_or(e))?;
530삭제: Ok(path)
591추가: OpenRoot::capture(path)
531592}
532593
533594/// 열기용 임시 폴더 이름. 예: `자료.zip (Zipelo 임시)`.
@@ -536,8 +597,10 @@ pub fn open_root_name(archive_name: &str) -> String {
536597}
537598
538599/// 이 앱이 만든 열기용 폴더를 지움. 다른 프로그램이 파일을 쓰고 있으면 남을 수 있음.
539삭제: pub fn remove_open_root(path: &Path) {
540삭제: let _ = fs::remove_dir_all(path);
600추가: pub fn remove_open_root(root: &OpenRoot) {
601추가: if root.is_current() {
602추가: let _ = fs::remove_dir_all(root.path());
603추가: }
541604}
542605
543606/// 기본 프로그램으로 열면 실행될 수 있는 파일은 바로 열지 않음.
수정experiments/rust-ui-memory-app/src/archive_screen.rs+5-4
@@ -284,7 +284,7 @@ pub struct ArchiveApp {
284284 /// 마지막 풀기가 기본 프로그램으로 열기였으면 그 항목. 다시 시도할 때 다시 엶.
285285 last_open: Option<u32>,
286286 /// 압축파일별 열기용 임시 폴더. 앱을 닫을 때 지움.
287삭제: open_roots: Vec<(PathBuf, PathBuf)>,
287추가: open_roots: Vec<(PathBuf, present::OpenRoot)>,
288288 open_count: u64,
289289 opener: Opener,
290290 #[cfg(all(feature = "ui-fixture", debug_assertions))]
@@ -410,12 +410,13 @@ impl ArchiveApp {
410410 return false;
411411 };
412412 let root = match self.open_roots.iter().find(|(a, _)| *a == archive) {
413삭제: Some((_, root)) if root.is_dir() => root.clone(),
413추가: Some((_, root)) if root.is_current() => root.path().to_path_buf(),
414414 _ => match present::create_open_root(&archive) {
415415 Ok(root) => {
416416 self.open_roots.retain(|(a, _)| *a != archive);
417삭제: self.open_roots.push((archive, root.clone()));
418삭제: root
417추가: let path = root.path().to_path_buf();
418추가: self.open_roots.push((archive, root));
419추가: path
419420 }
420421 Err(_) => {
421422 self.dismissed = false;
수정tests/rust-app-ui/presentation.rs+39-0
@@ -1156,3 +1156,42 @@ fn client_protocol_errors_hide_internal_terms_but_preserve_exit_uncertainty() {
11561156 UNCONFIRMED_FINISH
11571157 );
11581158}
1159추가:
1160추가: #[cfg(feature = "ui")]
1161추가: #[test]
1162추가: fn app_exit_preserves_replaced_open_root() {
1163추가: use zipelo_ui_memory_app::archive_screen::ArchiveApp;
1164추가: let scratch = Folder::new();
1165추가: let mut app = ArchiveApp::new(
1166추가: Box::new(FakeFactory::default()),
1167추가: Some(scratch.0.join("sample.zip")),
1168추가: false,
1169추가: );
1170추가: pump(&mut app.model);
1171추가: assert!(app.open_entry(0));
1172추가: let root = scratch.0.join(open_root_name("sample.zip"));
1173추가: fs::rename(&root, scratch.0.join("original")).unwrap();
1174추가: fs::create_dir(&root).unwrap();
1175추가: let retained = root.join("keep.txt");
1176추가: fs::write(&retained, b"user data").unwrap();
1177추가: drop(app);
1178추가: assert_eq!(fs::read(retained).unwrap(), b"user data");
1179추가: }
1180추가:
1181추가: #[cfg(feature = "ui")]
1182추가: #[test]
1183추가: fn app_exit_removes_original_open_root() {
1184추가: use zipelo_ui_memory_app::archive_screen::ArchiveApp;
1185추가: let scratch = Folder::new();
1186추가: let mut app = ArchiveApp::new(
1187추가: Box::new(FakeFactory::default()),
1188추가: Some(scratch.0.join("sample.zip")),
1189추가: false,
1190추가: );
1191추가: pump(&mut app.model);
1192추가: assert!(app.open_entry(0));
1193추가: let root = scratch.0.join(open_root_name("sample.zip"));
1194추가: fs::write(root.join("opened.txt"), b"temporary").unwrap();
1195추가: drop(app);
1196추가: assert!(!root.exists());
1197추가: }