화면을 실제 압축 작업자 프로세스에 연결함
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
fdb38ec1a6032351ee7b2d4b76242d2e7ccfc084
변경된 파일 22개
+2,673-1변경 내용이 커서 일부 파일의 Diff를 생략했어요. 생략한 파일은 파일 보기나 Raw로 확인할 수 있어요.
| @@ -3948,6 +3948,14 @@ dependencies = [ | ||
| 3948 | 3948 | "zipelo-rust-memory-zip-create", |
| 3949 | 3949 | ] |
| 3950 | 3950 | |
| 3951 | 추가: [[package]] | |
| 3952 | 추가: name = "zipelo-archive-worker" | |
| 3953 | 추가: version = "0.1.0" | |
| 3954 | 추가: dependencies = [ | |
| 3955 | 추가: "sha2", | |
| 3956 | 추가: "zlib-rs", | |
| 3957 | 추가: ] | |
| 3958 | 추가: | |
| 3951 | 3959 | [[package]] |
| 3952 | 3960 | name = "zipelo-memory-gzip-reader" |
| 3953 | 3961 | version = "0.1.0" |
| @@ -3976,6 +3984,7 @@ version = "0.1.0" | ||
| 3976 | 3984 | dependencies = [ |
| 3977 | 3985 | "eframe", |
| 3978 | 3986 | "zipelo-app-core-memory", |
| 3987 | 추가: "zipelo-archive-worker", | |
| 3979 | 3988 | ] |
| 3980 | 3989 | |
| 3981 | 3990 | [[package]] |
| @@ -15,16 +15,26 @@ doctest = false | ||
| 15 | 15 | [features] |
| 16 | 16 | default = [] |
| 17 | 17 | ui = ["dep:eframe"] |
| 18 | 추가: ui-fixture = ["ui"] | |
| 18 | 19 | |
| 19 | 20 | [dependencies] |
| 21 | 추가: worker_protocol = { package = "zipelo-archive-worker", path = "../rust-archive-worker" } | |
| 20 | 22 | core_memory = { package = "zipelo-app-core-memory", path = "../rust-app-core-memory" } |
| 21 | 23 | eframe = { version = "=0.37.0", optional = true, default-features = false, features = ["accesskit", "clipboard", "glow", "system_fonts", "wayland", "x11"] } |
| 22 | 24 | |
| 23 | 25 | [[bin]] |
| 24 | 26 | name = "zipelo-ui-memory-app" |
| 25 | 삭제: path = "src/app.rs" | |
| 27 | 추가: path = "src/desktop.rs" | |
| 26 | 28 | required-features = ["ui"] |
| 27 | 29 | |
| 28 | 30 | [[test]] |
| 29 | 31 | name = "ui_memory" |
| 30 | 32 | path = "../../tests/rust-ui-memory-app/regressions.rs" |
| 33 | 추가: | |
| 34 | 추가: [[test]] | |
| 35 | 추가: name = "archive_ui" | |
| 36 | 추가: path = "../../tests/rust-app-ui/regressions.rs" | |
| 37 | 추가: | |
| 38 | 추가: [[test]] | |
| 39 | 추가: name = "real_worker" | |
| 40 | 추가: path = "../../tests/rust-app-real-worker/flows.rs" |
| @@ -0,0 +1,657 @@ | ||
| 1 | 추가: use crate::archive_ui as ui; | |
| 2 | 추가: use std::{ | |
| 3 | 추가: cell::RefCell, | |
| 4 | 추가: io::{self, Read, Write}, | |
| 5 | 추가: path::PathBuf, | |
| 6 | 추가: process::{Command, Stdio}, | |
| 7 | 추가: rc::Rc, | |
| 8 | 추가: sync::{ | |
| 9 | 추가: Arc, Mutex, | |
| 10 | 추가: atomic::{AtomicBool, Ordering}, | |
| 11 | 추가: mpsc::{self, Receiver, SyncSender}, | |
| 12 | 추가: }, | |
| 13 | 추가: thread::{self, JoinHandle}, | |
| 14 | 추가: time::{Duration, Instant}, | |
| 15 | 추가: }; | |
| 16 | 추가: use worker_protocol::{protocol as wire, wire as codec}; | |
| 17 | 추가: | |
| 18 | 추가: macro_rules! convert_enum { | |
| 19 | 추가: ($name:ident, $from:ty, $to:ty, $($variant:ident),+) => { | |
| 20 | 추가: fn $name(value: $from) -> $to { | |
| 21 | 추가: match value { $(<$from>::$variant => <$to>::$variant),+ } | |
| 22 | 추가: } | |
| 23 | 추가: }; | |
| 24 | 추가: } | |
| 25 | 추가: convert_enum!( | |
| 26 | 추가: format_to_wire, | |
| 27 | 추가: ui::Format, | |
| 28 | 추가: wire::Format, | |
| 29 | 추가: Zip, | |
| 30 | 추가: Tar, | |
| 31 | 추가: Gzip, | |
| 32 | 추가: TarGzip | |
| 33 | 추가: ); | |
| 34 | 추가: convert_enum!( | |
| 35 | 추가: format_to_ui, | |
| 36 | 추가: wire::Format, | |
| 37 | 추가: ui::Format, | |
| 38 | 추가: Zip, | |
| 39 | 추가: Tar, | |
| 40 | 추가: Gzip, | |
| 41 | 추가: TarGzip | |
| 42 | 추가: ); | |
| 43 | 추가: convert_enum!( | |
| 44 | 추가: kind_to_ui, | |
| 45 | 추가: wire::EntryKind, | |
| 46 | 추가: ui::Kind, | |
| 47 | 추가: File, | |
| 48 | 추가: Directory, | |
| 49 | 추가: Link, | |
| 50 | 추가: Other | |
| 51 | 추가: ); | |
| 52 | 추가: convert_enum!( | |
| 53 | 추가: stage_to_ui, | |
| 54 | 추가: wire::Stage, | |
| 55 | 추가: ui::Stage, | |
| 56 | 추가: Scan, | |
| 57 | 추가: Read, | |
| 58 | 추가: Decode, | |
| 59 | 추가: Write, | |
| 60 | 추가: Verify, | |
| 61 | 추가: Commit | |
| 62 | 추가: ); | |
| 63 | 추가: convert_enum!( | |
| 64 | 추가: disposition_to_ui, | |
| 65 | 추가: wire::Disposition, | |
| 66 | 추가: ui::Disposition, | |
| 67 | 추가: Created, | |
| 68 | 추가: PartialRetained, | |
| 69 | 추가: Removed, | |
| 70 | 추가: CommitUncertain | |
| 71 | 추가: ); | |
| 72 | 추가: convert_enum!( | |
| 73 | 추가: outcome_to_ui, | |
| 74 | 추가: wire::Outcome, | |
| 75 | 추가: ui::Outcome, | |
| 76 | 추가: Completed, | |
| 77 | 추가: Failed, | |
| 78 | 추가: Cancelled | |
| 79 | 추가: ); | |
| 80 | 추가: convert_enum!( | |
| 81 | 추가: publication_to_ui, | |
| 82 | 추가: wire::Publication, | |
| 83 | 추가: ui::Publication, | |
| 84 | 추가: None, | |
| 85 | 추가: Partial, | |
| 86 | 추가: Complete, | |
| 87 | 추가: Uncertain | |
| 88 | 추가: ); | |
| 89 | 추가: convert_enum!( | |
| 90 | 추가: durability_to_ui, | |
| 91 | 추가: wire::Durability, | |
| 92 | 추가: ui::Durability, | |
| 93 | 추가: NotApplicable, | |
| 94 | 추가: Synced, | |
| 95 | 추가: Unconfirmed, | |
| 96 | 추가: Failed | |
| 97 | 추가: ); | |
| 98 | 추가: convert_enum!( | |
| 99 | 추가: cleanup_to_ui, | |
| 100 | 추가: wire::Cleanup, | |
| 101 | 추가: ui::Cleanup, | |
| 102 | 추가: Complete, | |
| 103 | 추가: Failed, | |
| 104 | 추가: Unconfirmed | |
| 105 | 추가: ); | |
| 106 | 추가: convert_enum!( | |
| 107 | 추가: cancel_to_ui, | |
| 108 | 추가: wire::CancelStatus, | |
| 109 | 추가: ui::CancelStatus, | |
| 110 | 추가: Requested, | |
| 111 | 추가: AlreadyRequested, | |
| 112 | 추가: TooLate, | |
| 113 | 추가: Finished | |
| 114 | 추가: ); | |
| 115 | 추가: fn list_to_wire(id: ui::ListId) -> wire::ListId { | |
| 116 | 추가: wire::ListId { | |
| 117 | 추가: catalog_version: id.catalog_version, | |
| 118 | 추가: format: format_to_wire(id.format), | |
| 119 | 추가: source_object: match id.source_object { | |
| 120 | 추가: ui::SourceObject::Unix { device, inode } => wire::SourceObject::Unix { device, inode }, | |
| 121 | 추가: ui::SourceObject::Windows { volume, file_id } => wire::SourceObject::Windows { | |
| 122 | 추가: volume_serial: volume, | |
| 123 | 추가: file_id, | |
| 124 | 추가: }, | |
| 125 | 추가: }, | |
| 126 | 추가: archive_bytes: id.archive_bytes, | |
| 127 | 추가: archive_sha256: id.archive_sha256, | |
| 128 | 추가: } | |
| 129 | 추가: } | |
| 130 | 추가: fn list_to_ui(id: wire::ListId) -> ui::ListId { | |
| 131 | 추가: ui::ListId { | |
| 132 | 추가: catalog_version: id.catalog_version, | |
| 133 | 추가: format: format_to_ui(id.format), | |
| 134 | 추가: source_object: match id.source_object { | |
| 135 | 추가: wire::SourceObject::Unix { device, inode } => ui::SourceObject::Unix { device, inode }, | |
| 136 | 추가: wire::SourceObject::Windows { | |
| 137 | 추가: volume_serial, | |
| 138 | 추가: file_id, | |
| 139 | 추가: } => ui::SourceObject::Windows { | |
| 140 | 추가: volume: volume_serial, | |
| 141 | 추가: file_id, | |
| 142 | 추가: }, | |
| 143 | 추가: }, | |
| 144 | 추가: archive_bytes: id.archive_bytes, | |
| 145 | 추가: archive_sha256: id.archive_sha256, | |
| 146 | 추가: } | |
| 147 | 추가: } | |
| 148 | 추가: fn start_to_wire(start: ui::Start) -> wire::Start { | |
| 149 | 추가: let action = match start { | |
| 150 | 추가: ui::Start::List { archive } => wire::Action::List { | |
| 151 | 추가: archive: wire::NativePath::from_path(&archive), | |
| 152 | 추가: }, | |
| 153 | 추가: ui::Start::Extract { | |
| 154 | 추가: archive, | |
| 155 | 추가: destination, | |
| 156 | 추가: selection, | |
| 157 | 추가: list_id, | |
| 158 | 추가: gzip_output_name, | |
| 159 | 추가: } => wire::Action::Extract { | |
| 160 | 추가: archive: wire::NativePath::from_path(&archive), | |
| 161 | 추가: destination: wire::NativePath::from_path(&destination), | |
| 162 | 추가: selection: match selection { | |
| 163 | 추가: ui::Selection::All => wire::Selection::All, | |
| 164 | 추가: ui::Selection::EntryIds(ids) => wire::Selection::EntryIds(ids), | |
| 165 | 추가: }, | |
| 166 | 추가: list_id: Some(list_to_wire(list_id)), | |
| 167 | 추가: gzip_output_name, | |
| 168 | 추가: }, | |
| 169 | 추가: ui::Start::CreateZip { | |
| 170 | 추가: sources, | |
| 171 | 추가: output_file, | |
| 172 | 추가: method, | |
| 173 | 추가: aes256, | |
| 174 | 추가: } => wire::Action::CreateZip { | |
| 175 | 추가: sources: sources | |
| 176 | 추가: .into_iter() | |
| 177 | 추가: .map(|(path, archive_name)| wire::Source { | |
| 178 | 추가: path: wire::NativePath::from_path(&path), | |
| 179 | 추가: archive_name, | |
| 180 | 추가: }) | |
| 181 | 추가: .collect(), | |
| 182 | 추가: output_file: wire::NativePath::from_path(&output_file), | |
| 183 | 추가: method: match method { | |
| 184 | 추가: ui::Method::Store => wire::Method::Store, | |
| 185 | 추가: ui::Method::Deflate => wire::Method::Deflate, | |
| 186 | 추가: }, | |
| 187 | 추가: encryption: if aes256 { | |
| 188 | 추가: wire::Encryption::Aes256 | |
| 189 | 추가: } else { | |
| 190 | 추가: wire::Encryption::None | |
| 191 | 추가: }, | |
| 192 | 추가: }, | |
| 193 | 추가: }; | |
| 194 | 추가: wire::Start { | |
| 195 | 추가: action, | |
| 196 | 추가: limits: wire::Limits::default(), | |
| 197 | 추가: } | |
| 198 | 추가: } | |
| 199 | 추가: fn error_to_ui(error: wire::ErrorCode) -> Option<ui::ErrorCode> { | |
| 200 | 추가: Some(match error { | |
| 201 | 추가: wire::ErrorCode::None => return None, | |
| 202 | 추가: wire::ErrorCode::Integrity => ui::ErrorCode::Integrity, | |
| 203 | 추가: wire::ErrorCode::UnsupportedFormat => ui::ErrorCode::UnsupportedFormat, | |
| 204 | 추가: wire::ErrorCode::UnsupportedFeature => ui::ErrorCode::UnsupportedFeature, | |
| 205 | 추가: wire::ErrorCode::WrongPassword => ui::ErrorCode::WrongPassword, | |
| 206 | 추가: wire::ErrorCode::UnsafePath => ui::ErrorCode::UnsafePath, | |
| 207 | 추가: wire::ErrorCode::Conflict => ui::ErrorCode::Conflict, | |
| 208 | 추가: wire::ErrorCode::Limit => ui::ErrorCode::Limit, | |
| 209 | 추가: wire::ErrorCode::Io => ui::ErrorCode::Io, | |
| 210 | 추가: wire::ErrorCode::Protocol => ui::ErrorCode::Protocol, | |
| 211 | 추가: wire::ErrorCode::Internal => ui::ErrorCode::Internal, | |
| 212 | 추가: wire::ErrorCode::SourceChanged => ui::ErrorCode::SourceChanged, | |
| 213 | 추가: wire::ErrorCode::InvalidRequest => ui::ErrorCode::InvalidRequest, | |
| 214 | 추가: }) | |
| 215 | 추가: } | |
| 216 | 추가: fn event_to_ui( | |
| 217 | 추가: message: wire::Message, | |
| 218 | 추가: expected: Option<wire::ActionKind>, | |
| 219 | 추가: ) -> Result<ui::Event, ()> { | |
| 220 | 추가: Ok(match message { | |
| 221 | 추가: wire::Message::Accepted { action, encryption } if expected == Some(action) => { | |
| 222 | 추가: ui::Event::Accepted { encryption } | |
| 223 | 추가: } | |
| 224 | 추가: wire::Message::Entry(entry) => ui::Event::Entry(ui::Entry { | |
| 225 | 추가: id: entry.entry_id, | |
| 226 | 추가: name: entry.name, | |
| 227 | 추가: kind: kind_to_ui(entry.kind), | |
| 228 | 추가: bytes: Some(entry.size), | |
| 229 | 추가: packed: Some(entry.compressed_size), | |
| 230 | 추가: encrypted: entry.encrypted, | |
| 231 | 추가: }), | |
| 232 | 추가: wire::Message::ListEnd { | |
| 233 | 추가: entry_count, | |
| 234 | 추가: list_id, | |
| 235 | 추가: } => ui::Event::ListEnd { | |
| 236 | 추가: entry_count, | |
| 237 | 추가: list_id: list_to_ui(list_id), | |
| 238 | 추가: }, | |
| 239 | 추가: wire::Message::PasswordRequired { | |
| 240 | 추가: challenge_id, | |
| 241 | 추가: attempt, | |
| 242 | 추가: purpose, | |
| 243 | 추가: } => ui::Event::PasswordRequired { | |
| 244 | 추가: challenge_id, | |
| 245 | 추가: attempt, | |
| 246 | 추가: encrypt: purpose == wire::PasswordPurpose::Encrypt, | |
| 247 | 추가: }, | |
| 248 | 추가: wire::Message::Progress { | |
| 249 | 추가: stage, | |
| 250 | 추가: processed_bytes, | |
| 251 | 추가: total_bytes, | |
| 252 | 추가: completed_entries, | |
| 253 | 추가: } => ui::Event::Progress { | |
| 254 | 추가: stage: stage_to_ui(stage), | |
| 255 | 추가: processed: processed_bytes, | |
| 256 | 추가: total: total_bytes, | |
| 257 | 추가: completed_entries: completed_entries.into(), | |
| 258 | 추가: }, | |
| 259 | 추가: wire::Message::Output { | |
| 260 | 추가: entry_id, | |
| 261 | 추가: relative_name, | |
| 262 | 추가: disposition, | |
| 263 | 추가: } => ui::Event::Output { | |
| 264 | 추가: entry_id, | |
| 265 | 추가: relative_name, | |
| 266 | 추가: disposition: disposition_to_ui(disposition), | |
| 267 | 추가: }, | |
| 268 | 추가: wire::Message::CancelAck { | |
| 269 | 추가: request_sequence, | |
| 270 | 추가: status, | |
| 271 | 추가: } => ui::Event::CancelAck { | |
| 272 | 추가: request_sequence, | |
| 273 | 추가: status: cancel_to_ui(status), | |
| 274 | 추가: }, | |
| 275 | 추가: wire::Message::Terminal(terminal) => ui::Event::Terminal(ui::Terminal { | |
| 276 | 추가: outcome: outcome_to_ui(terminal.outcome), | |
| 277 | 추가: error: error_to_ui(terminal.error), | |
| 278 | 추가: publication: publication_to_ui(terminal.publication), | |
| 279 | 추가: created_count: terminal.created_count, | |
| 280 | 추가: retained_partial_count: terminal.retained_partial_count, | |
| 281 | 추가: durability: durability_to_ui(terminal.durability), | |
| 282 | 추가: cleanup: cleanup_to_ui(terminal.cleanup), | |
| 283 | 추가: }), | |
| 284 | 추가: _ => return Err(()), | |
| 285 | 추가: }) | |
| 286 | 추가: } | |
| 287 | 추가: | |
| 288 | 추가: // 실제 파이프 쓰기는 백그라운드에서 수행하고 UI에서는 한 프레임만 직렬화함. | |
| 289 | 추가: #[derive(Clone, Default)] | |
| 290 | 추가: struct FrameBuffer(Rc<RefCell<Vec<u8>>>); | |
| 291 | 추가: impl Write for FrameBuffer { | |
| 292 | 추가: fn write(&mut self, bytes: &[u8]) -> io::Result<usize> { | |
| 293 | 추가: let mut buffer = self.0.borrow_mut(); | |
| 294 | 추가: if buffer.len().saturating_add(bytes.len()) > codec::MAX_BODY + 32 { | |
| 295 | 추가: return Err(io::Error::other("요청 프레임 한도 초과")); | |
| 296 | 추가: } | |
| 297 | 추가: buffer.extend_from_slice(bytes); | |
| 298 | 추가: Ok(bytes.len()) | |
| 299 | 추가: } | |
| 300 | 추가: fn flush(&mut self) -> io::Result<()> { | |
| 301 | 추가: Ok(()) | |
| 302 | 추가: } | |
| 303 | 추가: } | |
| 304 | 추가: struct Frame(Vec<u8>); | |
| 305 | 추가: impl Drop for Frame { | |
| 306 | 추가: fn drop(&mut self) { | |
| 307 | 추가: self.0.fill(0); | |
| 308 | 추가: } | |
| 309 | 추가: } | |
| 310 | 추가: fn notify(events: &SyncSender<ui::HostEvent>, event: ui::HostEvent) -> bool { | |
| 311 | 추가: events.send(event).is_ok() | |
| 312 | 추가: } | |
| 313 | 추가: fn fault(events: &SyncSender<ui::HostEvent>, stop: &AtomicBool, message: &str) { | |
| 314 | 추가: stop.store(true, Ordering::Release); | |
| 315 | 추가: notify(events, ui::HostEvent::Fault(message.into())); | |
| 316 | 추가: } | |
| 317 | 추가: | |
| 318 | 추가: pub struct ProcessFactory { | |
| 319 | 추가: worker: PathBuf, | |
| 320 | 추가: } | |
| 321 | 추가: impl ProcessFactory { | |
| 322 | 추가: pub fn new(worker: PathBuf) -> Self { | |
| 323 | 추가: Self { worker } | |
| 324 | 추가: } | |
| 325 | 추가: pub fn sibling() -> Result<Self, String> { | |
| 326 | 추가: let executable = | |
| 327 | 추가: std::env::current_exe().map_err(|_| "앱 실행 위치를 확인하지 못했습니다")?; | |
| 328 | 추가: let parent = executable.parent().ok_or("앱 실행 폴더가 없습니다")?; | |
| 329 | 추가: Ok(Self::new(parent.join(if cfg!(windows) { | |
| 330 | 추가: "zipelo-archive-worker.exe" | |
| 331 | 추가: } else { | |
| 332 | 추가: "zipelo-archive-worker" | |
| 333 | 추가: }))) | |
| 334 | 추가: } | |
| 335 | 추가: } | |
| 336 | 추가: impl ui::Factory for ProcessFactory { | |
| 337 | 추가: fn connect(&mut self, job_id: u64) -> Result<Box<dyn ui::Connection>, String> { | |
| 338 | 추가: if !self.worker.is_absolute() || job_id == 0 { | |
| 339 | 추가: return Err("작업자 경로 또는 작업 ID가 올바르지 않습니다".into()); | |
| 340 | 추가: } | |
| 341 | 추가: let (send, requests) = mpsc::sync_channel::<Frame>(8); | |
| 342 | 추가: let (events, receive) = mpsc::sync_channel(64); | |
| 343 | 추가: let (ready, started) = mpsc::sync_channel(1); | |
| 344 | 추가: let stop = Arc::new(AtomicBool::new(false)); | |
| 345 | 추가: let done = Arc::new(AtomicBool::new(false)); | |
| 346 | 추가: let expected = Arc::new(Mutex::new(None)); | |
| 347 | 추가: let worker = self.worker.clone(); | |
| 348 | 추가: let worker_stop = stop.clone(); | |
| 349 | 추가: let worker_done = done.clone(); | |
| 350 | 추가: let worker_expected = expected.clone(); | |
| 351 | 추가: let supervisor = thread::Builder::new() | |
| 352 | 추가: .name("zipelo-worker-owner".into()) | |
| 353 | 추가: .spawn(move || { | |
| 354 | 추가: let mut command = Command::new(worker); | |
| 355 | 추가: command | |
| 356 | 추가: .stdin(Stdio::piped()) | |
| 357 | 추가: .stdout(Stdio::piped()) | |
| 358 | 추가: .stderr(Stdio::piped()); | |
| 359 | 추가: #[cfg(windows)] | |
| 360 | 추가: { | |
| 361 | 추가: use std::os::windows::process::CommandExt; | |
| 362 | 추가: command.creation_flags(0x08000000); | |
| 363 | 추가: } | |
| 364 | 추가: let child = match command.spawn() { | |
| 365 | 추가: Ok(child) => child, | |
| 366 | 추가: Err(_) => { | |
| 367 | 추가: let _ = ready.send(Err( | |
| 368 | 추가: "작업자를 실행하지 못했습니다. 앱과 작업자를 함께 설치하세요" | |
| 369 | 추가: .to_string(), | |
| 370 | 추가: )); | |
| 371 | 추가: return; | |
| 372 | 추가: } | |
| 373 | 추가: }; | |
| 374 | 추가: if ready.send(Ok(())).is_err() { | |
| 375 | 추가: let mut child = child; | |
| 376 | 추가: let _ = child.kill(); | |
| 377 | 추가: let _ = child.wait(); | |
| 378 | 추가: return; | |
| 379 | 추가: } | |
| 380 | 추가: supervise( | |
| 381 | 추가: child, | |
| 382 | 추가: job_id, | |
| 383 | 추가: requests, | |
| 384 | 추가: events, | |
| 385 | 추가: worker_stop, | |
| 386 | 추가: worker_done, | |
| 387 | 추가: worker_expected, | |
| 388 | 추가: ); | |
| 389 | 추가: }) | |
| 390 | 추가: .map_err(|_| "작업자 관리 스레드를 시작하지 못했습니다")?; | |
| 391 | 추가: match started.recv() { | |
| 392 | 추가: Ok(Ok(())) => { | |
| 393 | 추가: let buffer = FrameBuffer::default(); | |
| 394 | 추가: Ok(Box::new(ProcessConnection { | |
| 395 | 추가: job_id, | |
| 396 | 추가: next: 0, | |
| 397 | 추가: writer: codec::Writer::new(buffer.clone(), job_id), | |
| 398 | 추가: buffer, | |
| 399 | 추가: send: Some(send), | |
| 400 | 추가: receive: Some(receive), | |
| 401 | 추가: stop, | |
| 402 | 추가: supervisor: Some(supervisor), | |
| 403 | 추가: expected, | |
| 404 | 추가: done, | |
| 405 | 추가: disconnected: false, | |
| 406 | 추가: reaped: false, | |
| 407 | 추가: })) | |
| 408 | 추가: } | |
| 409 | 추가: result => { | |
| 410 | 추가: stop.store(true, Ordering::Release); | |
| 411 | 추가: drop(send); | |
| 412 | 추가: drop(receive); | |
| 413 | 추가: let _ = supervisor.join(); | |
| 414 | 추가: Err(result | |
| 415 | 추가: .ok() | |
| 416 | 추가: .and_then(Result::err) | |
| 417 | 추가: .unwrap_or_else(|| "작업자 시작 결과가 없습니다".into())) | |
| 418 | 추가: } | |
| 419 | 추가: } | |
| 420 | 추가: } | |
| 421 | 추가: } | |
| 422 | 추가: struct ProcessConnection { | |
| 423 | 추가: job_id: u64, | |
| 424 | 추가: next: u64, | |
| 425 | 추가: writer: codec::Writer<FrameBuffer>, | |
| 426 | 추가: buffer: FrameBuffer, | |
| 427 | 추가: send: Option<SyncSender<Frame>>, | |
| 428 | 추가: receive: Option<Receiver<ui::HostEvent>>, | |
| 429 | 추가: stop: Arc<AtomicBool>, | |
| 430 | 추가: supervisor: Option<JoinHandle<()>>, | |
| 431 | 추가: expected: Arc<Mutex<Option<wire::ActionKind>>>, | |
| 432 | 추가: done: Arc<AtomicBool>, | |
| 433 | 추가: disconnected: bool, | |
| 434 | 추가: reaped: bool, | |
| 435 | 추가: } | |
| 436 | 추가: impl ui::Connection for ProcessConnection { | |
| 437 | 추가: fn send(&mut self, request: ui::Request) -> Result<(), String> { | |
| 438 | 추가: if self.stop.load(Ordering::Acquire) | |
| 439 | 추가: || request.job_id != self.job_id | |
| 440 | 추가: || request.sequence != self.next | |
| 441 | 추가: || self.next >= codec::MAX_FRAMES | |
| 442 | 추가: { | |
| 443 | 추가: self.stop.store(true, Ordering::Release); | |
| 444 | 추가: return Err("작업자 요청 채널이 닫혔거나 순서가 올바르지 않습니다".into()); | |
| 445 | 추가: } | |
| 446 | 추가: let is_cancel = matches!(request.command, ui::Command::Cancel); | |
| 447 | 추가: let message = match request.command { | |
| 448 | 추가: ui::Command::Start(start) => { | |
| 449 | 추가: let start = start_to_wire(start); | |
| 450 | 추가: *self.expected.lock().map_err(|_| { | |
| 451 | 추가: self.stop.store(true, Ordering::Release); | |
| 452 | 추가: "작업자 요청 상태 오류" | |
| 453 | 추가: })? = Some(start.action.kind()); | |
| 454 | 추가: wire::Message::Start(start) | |
| 455 | 추가: } | |
| 456 | 추가: ui::Command::Cancel => wire::Message::Cancel, | |
| 457 | 추가: ui::Command::Password { | |
| 458 | 추가: challenge_id, | |
| 459 | 추가: secret, | |
| 460 | 추가: } => wire::Message::Password { | |
| 461 | 추가: challenge_id, | |
| 462 | 추가: secret: wire::Secret(secret.as_bytes().to_vec()), | |
| 463 | 추가: }, | |
| 464 | 추가: }; | |
| 465 | 추가: if self.writer.send(&message).is_err() { | |
| 466 | 추가: self.buffer.0.borrow_mut().fill(0); | |
| 467 | 추가: self.buffer.0.borrow_mut().clear(); | |
| 468 | 추가: self.stop.store(true, Ordering::Release); | |
| 469 | 추가: return Err("작업자 요청을 직렬화하지 못했습니다".into()); | |
| 470 | 추가: } | |
| 471 | 추가: let bytes = Frame(std::mem::take(&mut *self.buffer.0.borrow_mut())); | |
| 472 | 추가: if self.send.as_ref().unwrap().try_send(bytes).is_err() { | |
| 473 | 추가: if is_cancel && self.done.load(Ordering::Acquire) { | |
| 474 | 추가: self.next += 1; | |
| 475 | 추가: return Ok(()); | |
| 476 | 추가: } | |
| 477 | 추가: self.stop.store(true, Ordering::Release); | |
| 478 | 추가: return Err("작업자 요청 대기열이 닫혔거나 가득 찼습니다".into()); | |
| 479 | 추가: } | |
| 480 | 추가: self.next += 1; | |
| 481 | 추가: Ok(()) | |
| 482 | 추가: } | |
| 483 | 추가: fn poll(&mut self) -> Option<ui::HostEvent> { | |
| 484 | 추가: match self.receive.as_ref()?.try_recv() { | |
| 485 | 추가: Ok(event) => { | |
| 486 | 추가: if matches!(event, ui::HostEvent::Exited { .. }) { | |
| 487 | 추가: self.reaped = true; | |
| 488 | 추가: } | |
| 489 | 추가: Some(event) | |
| 490 | 추가: } | |
| 491 | 추가: Err(mpsc::TryRecvError::Empty) => None, | |
| 492 | 추가: Err(mpsc::TryRecvError::Disconnected) if !self.reaped && !self.disconnected => { | |
| 493 | 추가: self.disconnected = true; | |
| 494 | 추가: Some(ui::HostEvent::Fault( | |
| 495 | 추가: "작업자 통신 스레드가 종료됐습니다".into(), | |
| 496 | 추가: )) | |
| 497 | 추가: } | |
| 498 | 추가: Err(_) => None, | |
| 499 | 추가: } | |
| 500 | 추가: } | |
| 501 | 추가: } | |
| 502 | 추가: impl Drop for ProcessConnection { | |
| 503 | 추가: fn drop(&mut self) { | |
| 504 | 추가: self.stop.store(true, Ordering::Release); | |
| 505 | 추가: self.send.take(); | |
| 506 | 추가: self.receive.take(); | |
| 507 | 추가: if let Some(supervisor) = self.supervisor.take() { | |
| 508 | 추가: let _ = supervisor.join(); | |
| 509 | 추가: } | |
| 510 | 추가: } | |
| 511 | 추가: } | |
| 512 | 추가: | |
| 513 | 추가: fn supervise( | |
| 514 | 추가: mut child: std::process::Child, | |
| 515 | 추가: job_id: u64, | |
| 516 | 추가: requests: Receiver<Frame>, | |
| 517 | 추가: events: SyncSender<ui::HostEvent>, | |
| 518 | 추가: stop: Arc<AtomicBool>, | |
| 519 | 추가: done: Arc<AtomicBool>, | |
| 520 | 추가: expected: Arc<Mutex<Option<wire::ActionKind>>>, | |
| 521 | 추가: ) { | |
| 522 | 추가: let mut input = child.stdin.take().unwrap(); | |
| 523 | 추가: let mut output = child.stdout.take().unwrap(); | |
| 524 | 추가: let mut errors = child.stderr.take().unwrap(); | |
| 525 | 추가: let mut threads = Vec::new(); | |
| 526 | 추가: let tx = events.clone(); | |
| 527 | 추가: let abort = stop.clone(); | |
| 528 | 추가: let finished = done.clone(); | |
| 529 | 추가: threads.push( | |
| 530 | 추가: thread::Builder::new() | |
| 531 | 추가: .name("zipelo-worker-input".into()) | |
| 532 | 추가: .spawn(move || { | |
| 533 | 추가: while !finished.load(Ordering::Acquire) && !abort.load(Ordering::Acquire) { | |
| 534 | 추가: match requests.recv_timeout(Duration::from_millis(10)) { | |
| 535 | 추가: Ok(frame) => { | |
| 536 | 추가: if input | |
| 537 | 추가: .write_all(&frame.0) | |
| 538 | 추가: .and_then(|_| input.flush()) | |
| 539 | 추가: .is_err() | |
| 540 | 추가: { | |
| 541 | 추가: fault(&tx, &abort, "작업자 요청 파이프 쓰기에 실패했습니다"); | |
| 542 | 추가: break; | |
| 543 | 추가: } | |
| 544 | 추가: } | |
| 545 | 추가: Err(mpsc::RecvTimeoutError::Timeout) => {} | |
| 546 | 추가: Err(_) => break, | |
| 547 | 추가: } | |
| 548 | 추가: } | |
| 549 | 추가: }), | |
| 550 | 추가: ); | |
| 551 | 추가: let tx = events.clone(); | |
| 552 | 추가: let abort = stop.clone(); | |
| 553 | 추가: threads.push( | |
| 554 | 추가: thread::Builder::new() | |
| 555 | 추가: .name("zipelo-worker-output".into()) | |
| 556 | 추가: .spawn(move || { | |
| 557 | 추가: let eof; | |
| 558 | 추가: { | |
| 559 | 추가: let mut reader = codec::Reader::new(&mut output); | |
| 560 | 추가: eof = loop { | |
| 561 | 추가: match reader.read() { | |
| 562 | 추가: Ok(Some((job, sequence, message))) => { | |
| 563 | 추가: let action = expected.lock().ok().and_then(|value| *value); | |
| 564 | 추가: let event = event_to_ui(message, action); | |
| 565 | 추가: if job != job_id || event.is_err() { | |
| 566 | 추가: fault(&tx, &abort, "작업자 응답이 요청과 일치하지 않습니다"); | |
| 567 | 추가: break false; | |
| 568 | 추가: } | |
| 569 | 추가: if !notify( | |
| 570 | 추가: &tx, | |
| 571 | 추가: ui::HostEvent::Frame { | |
| 572 | 추가: job_id: job, | |
| 573 | 추가: sequence, | |
| 574 | 추가: event: event.unwrap(), | |
| 575 | 추가: }, | |
| 576 | 추가: ) { | |
| 577 | 추가: return; | |
| 578 | 추가: } | |
| 579 | 추가: } | |
| 580 | 추가: Ok(None) => break true, | |
| 581 | 추가: Err(_) => { | |
| 582 | 추가: fault(&tx, &abort, "작업자 응답 프레임을 읽지 못했습니다"); | |
| 583 | 추가: break false; | |
| 584 | 추가: } | |
| 585 | 추가: } | |
| 586 | 추가: }; | |
| 587 | 추가: } | |
| 588 | 추가: if eof || io::copy(&mut output, &mut io::sink()).is_ok() { | |
| 589 | 추가: notify(&tx, ui::HostEvent::StdoutEof); | |
| 590 | 추가: } | |
| 591 | 추가: }), | |
| 592 | 추가: ); | |
| 593 | 추가: let tx = events.clone(); | |
| 594 | 추가: let abort = stop.clone(); | |
| 595 | 추가: threads.push( | |
| 596 | 추가: thread::Builder::new() | |
| 597 | 추가: .name("zipelo-worker-errors".into()) | |
| 598 | 추가: .spawn(move || { | |
| 599 | 추가: let mut bytes = [0u8; 4096]; | |
| 600 | 추가: loop { | |
| 601 | 추가: match errors.read(&mut bytes) { | |
| 602 | 추가: Ok(0) => { | |
| 603 | 추가: notify(&tx, ui::HostEvent::StderrEof); | |
| 604 | 추가: break; | |
| 605 | 추가: } | |
| 606 | 추가: Ok(_) => {} | |
| 607 | 추가: Err(error) if error.kind() == io::ErrorKind::Interrupted => {} | |
| 608 | 추가: Err(_) => { | |
| 609 | 추가: fault(&tx, &abort, "작업자 오류 파이프를 읽지 못했습니다"); | |
| 610 | 추가: break; | |
| 611 | 추가: } | |
| 612 | 추가: } | |
| 613 | 추가: } | |
| 614 | 추가: }), | |
| 615 | 추가: ); | |
| 616 | 추가: let mut handles = Vec::new(); | |
| 617 | 추가: for result in threads { | |
| 618 | 추가: match result { | |
| 619 | 추가: Ok(handle) => handles.push(handle), | |
| 620 | 추가: Err(_) => fault(&events, &stop, "작업자 통신 스레드를 시작하지 못했습니다"), | |
| 621 | 추가: } | |
| 622 | 추가: } | |
| 623 | 추가: let started = Instant::now(); | |
| 624 | 추가: let status = loop { | |
| 625 | 추가: if started.elapsed() >= Duration::from_secs(310) { | |
| 626 | 추가: fault(&events, &stop, "작업자 처리 제한 시간을 초과했습니다"); | |
| 627 | 추가: } | |
| 628 | 추가: if stop.load(Ordering::Acquire) { | |
| 629 | 추가: let _ = child.kill(); | |
| 630 | 추가: } | |
| 631 | 추가: match child.try_wait() { | |
| 632 | 추가: Ok(Some(status)) => break Some(status), | |
| 633 | 추가: Ok(None) => thread::sleep(Duration::from_millis(10)), | |
| 634 | 추가: Err(_) => { | |
| 635 | 추가: fault(&events, &stop, "작업자 종료 상태를 확인하지 못했습니다"); | |
| 636 | 추가: let _ = child.kill(); | |
| 637 | 추가: break child.wait().ok(); | |
| 638 | 추가: } | |
| 639 | 추가: } | |
| 640 | 추가: }; | |
| 641 | 추가: done.store(true, Ordering::Release); | |
| 642 | 추가: for handle in handles { | |
| 643 | 추가: if handle.join().is_err() { | |
| 644 | 추가: fault(&events, &stop, "작업자 통신 스레드 회수에 실패했습니다"); | |
| 645 | 추가: } | |
| 646 | 추가: } | |
| 647 | 추가: if let Some(status) = status { | |
| 648 | 추가: // 회수와 모든 파이프 핸들 정리가 끝난 뒤에만 닫기 허용 근거를 전달함. | |
| 649 | 추가: notify(&events, ui::HostEvent::CleanupComplete); | |
| 650 | 추가: notify( | |
| 651 | 추가: &events, | |
| 652 | 추가: ui::HostEvent::Exited { | |
| 653 | 추가: success: status.success(), | |
| 654 | 추가: }, | |
| 655 | 추가: ); | |
| 656 | 추가: } | |
| 657 | 추가: } |
| @@ -0,0 +1,383 @@ | ||
| 1 | 추가: use crate::archive_ui::*; | |
| 2 | 추가: use eframe::egui; | |
| 3 | 추가: use std::path::PathBuf; | |
| 4 | 추가: | |
| 5 | 추가: pub struct ArchiveApp { | |
| 6 | 추가: pub model: Model, | |
| 7 | 추가: factory: Box<dyn Factory>, | |
| 8 | 추가: open_text: String, | |
| 9 | 추가: destination: String, | |
| 10 | 추가: gzip_name: String, | |
| 11 | 추가: sources: String, | |
| 12 | 추가: zip_output: String, | |
| 13 | 추가: password: String, | |
| 14 | 추가: create: bool, | |
| 15 | 추가: open: bool, | |
| 16 | 추가: selected_only: bool, | |
| 17 | 추가: method: Method, | |
| 18 | 추가: fixture: bool, | |
| 19 | 추가: } | |
| 20 | 추가: impl ArchiveApp { | |
| 21 | 추가: pub fn new(factory: Box<dyn Factory>, startup: Option<PathBuf>, fixture: bool) -> Self { | |
| 22 | 추가: let mut app = Self { | |
| 23 | 추가: model: Model::default(), | |
| 24 | 추가: factory, | |
| 25 | 추가: open_text: String::new(), | |
| 26 | 추가: destination: String::new(), | |
| 27 | 추가: gzip_name: String::new(), | |
| 28 | 추가: sources: String::new(), | |
| 29 | 추가: zip_output: String::new(), | |
| 30 | 추가: password: String::new(), | |
| 31 | 추가: create: false, | |
| 32 | 추가: open: false, | |
| 33 | 추가: selected_only: false, | |
| 34 | 추가: method: Method::Deflate, | |
| 35 | 추가: fixture, | |
| 36 | 추가: }; | |
| 37 | 추가: if let Some(path) = startup { | |
| 38 | 추가: app.open_path(path); | |
| 39 | 추가: } | |
| 40 | 추가: app | |
| 41 | 추가: } | |
| 42 | 추가: pub fn open_path(&mut self, archive: PathBuf) { | |
| 43 | 추가: self.password.clear(); | |
| 44 | 추가: self.model | |
| 45 | 추가: .begin(Start::List { archive }, self.factory.as_mut()); | |
| 46 | 추가: } | |
| 47 | 추가: fn on_drop(&mut self, paths: Vec<PathBuf>) { | |
| 48 | 추가: if self.model.busy() || paths.is_empty() { | |
| 49 | 추가: return; | |
| 50 | 추가: } | |
| 51 | 추가: if paths.len() == 1 && !self.create { | |
| 52 | 추가: self.open_path(paths[0].clone()); | |
| 53 | 추가: } else if paths.iter().all(|p| p.to_str().is_some()) { | |
| 54 | 추가: self.sources = paths | |
| 55 | 추가: .iter() | |
| 56 | 추가: .map(|p| p.to_str().unwrap()) | |
| 57 | 추가: .collect::<Vec<_>>() | |
| 58 | 추가: .join("\n"); | |
| 59 | 추가: self.create = true; | |
| 60 | 추가: } else { | |
| 61 | 추가: self.model.error = Some("ZIP 생성 경로는 현재 UTF-8 입력만 지원합니다".into()); | |
| 62 | 추가: } | |
| 63 | 추가: } | |
| 64 | 추가: } | |
| 65 | 추가: impl ArchiveApp { | |
| 66 | 추가: pub fn show(&mut self, root: &mut egui::Ui) { | |
| 67 | 추가: self.model.poll(); | |
| 68 | 추가: if self.model.challenge.is_none() { | |
| 69 | 추가: self.password.clear(); | |
| 70 | 추가: } | |
| 71 | 추가: let ctx = root.ctx().clone(); | |
| 72 | 추가: let dropped = ctx.input(|i| { | |
| 73 | 추가: i.raw | |
| 74 | 추가: .dropped_files | |
| 75 | 추가: .iter() | |
| 76 | 추가: .map(|f| f.path().to_path_buf()) | |
| 77 | 추가: .collect::<Vec<_>>() | |
| 78 | 추가: }); | |
| 79 | 추가: self.on_drop(dropped); | |
| 80 | 추가: if ctx.input(|i| i.viewport().close_requested()) { | |
| 81 | 추가: self.model.request_close(); | |
| 82 | 추가: if self.model.close != Close::Allowed { | |
| 83 | 추가: ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose); | |
| 84 | 추가: } | |
| 85 | 추가: } | |
| 86 | 추가: if self.model.close == Close::Allowed { | |
| 87 | 추가: ctx.send_viewport_cmd(egui::ViewportCommand::Close); | |
| 88 | 추가: } | |
| 89 | 추가: egui::Panel::top("archive-actions").show(root, |ui| { | |
| 90 | 추가: ui.horizontal_wrapped(|ui| { | |
| 91 | 추가: ui.heading("Zipelo"); | |
| 92 | 추가: ui.add_enabled_ui( | |
| 93 | 추가: !self.model.busy() && self.model.close == Close::Open, | |
| 94 | 추가: |ui| { | |
| 95 | 추가: if ui.button("파일 열기").clicked() { | |
| 96 | 추가: self.open = true; | |
| 97 | 추가: } | |
| 98 | 추가: if ui.button("ZIP 만들기").clicked() { | |
| 99 | 추가: self.create = true; | |
| 100 | 추가: } | |
| 101 | 추가: }, | |
| 102 | 추가: ); | |
| 103 | 추가: if ui | |
| 104 | 추가: .add_enabled(self.model.busy(), egui::Button::new("취소 요청")) | |
| 105 | 추가: .clicked() | |
| 106 | 추가: { | |
| 107 | 추가: self.password.clear(); | |
| 108 | 추가: self.model.cancel(); | |
| 109 | 추가: } | |
| 110 | 추가: }); | |
| 111 | 추가: if self.fixture { | |
| 112 | 추가: ui.colored_label( | |
| 113 | 추가: egui::Color32::from_rgb(143, 69, 0), | |
| 114 | 추가: "화면 시험 모드 / 파일을 읽거나 저장하지 않습니다", | |
| 115 | 추가: ); | |
| 116 | 추가: } | |
| 117 | 추가: }); | |
| 118 | 추가: egui::Panel::bottom("archive-status").show(root, |ui| { | |
| 119 | 추가: ui.label(self.model.status()); | |
| 120 | 추가: if let Some((stage, done, total, entries)) = | |
| 121 | 추가: self.model.progress.filter(|_| self.model.busy()) | |
| 122 | 추가: { | |
| 123 | 추가: ui.label(format!( | |
| 124 | 추가: "{} / {done}바이트 / {entries}개 처리", | |
| 125 | 추가: stage_label(stage) | |
| 126 | 추가: )); | |
| 127 | 추가: if let Some(total) = total.filter(|n| *n > 0) { | |
| 128 | 추가: ui.add( | |
| 129 | 추가: egui::ProgressBar::new((done as f64 / total as f64).clamp(0.0, 1.0) as f32) | |
| 130 | 추가: .show_percentage(), | |
| 131 | 추가: ); | |
| 132 | 추가: } else if self.model.busy() { | |
| 133 | 추가: ui.spinner(); | |
| 134 | 추가: } | |
| 135 | 추가: } | |
| 136 | 추가: if !self.model.busy() { | |
| 137 | 추가: if let Some(t) = &self.model.terminal { | |
| 138 | 추가: for line in terminal_lines(t) { | |
| 139 | 추가: ui.label(line); | |
| 140 | 추가: } | |
| 141 | 추가: } | |
| 142 | 추가: } | |
| 143 | 추가: }); | |
| 144 | 추가: egui::CentralPanel::default_margins().show(root, |ui| { | |
| 145 | 추가: if let Some(path) = &self.model.archive { | |
| 146 | 추가: ui.heading( | |
| 147 | 추가: path.file_name() | |
| 148 | 추가: .unwrap_or(path.as_os_str()) | |
| 149 | 추가: .to_string_lossy(), | |
| 150 | 추가: ); | |
| 151 | 추가: ui.label(path.display().to_string()); | |
| 152 | 추가: } else { | |
| 153 | 추가: ui.heading("압축파일을 여기로 끌어 놓으세요"); | |
| 154 | 추가: } | |
| 155 | 추가: if self.model.list_id.is_some() { | |
| 156 | 추가: ui.add_enabled_ui(self.model.can_extract(), |ui| { | |
| 157 | 추가: ui.horizontal_wrapped(|ui| { | |
| 158 | 추가: ui.label("출력 폴더"); | |
| 159 | 추가: ui.text_edit_singleline(&mut self.destination); | |
| 160 | 추가: }); | |
| 161 | 추가: if self | |
| 162 | 추가: .model | |
| 163 | 추가: .list_id | |
| 164 | 추가: .as_ref() | |
| 165 | 추가: .is_some_and(|id| id.format == Format::Gzip) | |
| 166 | 추가: { | |
| 167 | 추가: ui.horizontal(|ui| { | |
| 168 | 추가: ui.label("출력 파일명"); | |
| 169 | 추가: ui.text_edit_singleline(&mut self.gzip_name); | |
| 170 | 추가: }); | |
| 171 | 추가: } | |
| 172 | 추가: ui.horizontal_wrapped(|ui| { | |
| 173 | 추가: ui.checkbox(&mut self.selected_only, "선택한 항목만 풀기"); | |
| 174 | 추가: if ui.button("풀기").clicked() { | |
| 175 | 추가: self.model.extract( | |
| 176 | 추가: PathBuf::from(&self.destination), | |
| 177 | 추가: self.selected_only, | |
| 178 | 추가: self.model | |
| 179 | 추가: .list_id | |
| 180 | 추가: .as_ref() | |
| 181 | 추가: .filter(|id| id.format == Format::Gzip) | |
| 182 | 추가: .map(|_| self.gzip_name.clone()), | |
| 183 | 추가: self.factory.as_mut(), | |
| 184 | 추가: ); | |
| 185 | 추가: } | |
| 186 | 추가: }); | |
| 187 | 추가: }); | |
| 188 | 추가: } | |
| 189 | 추가: ui.separator(); | |
| 190 | 추가: egui::ScrollArea::both().show(ui, |ui| { | |
| 191 | 추가: egui::Grid::new("archive-list") | |
| 192 | 추가: .striped(true) | |
| 193 | 추가: .min_col_width(90.0) | |
| 194 | 추가: .show(ui, |ui| { | |
| 195 | 추가: ui.label("선택"); | |
| 196 | 추가: ui.label("이름"); | |
| 197 | 추가: ui.label("크기"); | |
| 198 | 추가: ui.label("형식"); | |
| 199 | 추가: ui.label("암호"); | |
| 200 | 추가: ui.end_row(); | |
| 201 | 추가: for entry in &self.model.entries { | |
| 202 | 추가: let mut selected = self.model.selected.contains(&entry.id); | |
| 203 | 추가: if ui | |
| 204 | 추가: .add_enabled( | |
| 205 | 추가: !self.model.busy() | |
| 206 | 추가: && matches!(entry.kind, Kind::File | Kind::Directory), | |
| 207 | 추가: egui::Checkbox::without_text(&mut selected), | |
| 208 | 추가: ) | |
| 209 | 추가: .on_hover_text(format!("{} 선택", entry.name)) | |
| 210 | 추가: .changed() | |
| 211 | 추가: { | |
| 212 | 추가: if selected { | |
| 213 | 추가: self.model.selected.insert(entry.id); | |
| 214 | 추가: } else { | |
| 215 | 추가: self.model.selected.remove(&entry.id); | |
| 216 | 추가: } | |
| 217 | 추가: } | |
| 218 | 추가: ui.label(&entry.name); | |
| 219 | 추가: ui.label( | |
| 220 | 추가: entry | |
| 221 | 추가: .bytes | |
| 222 | 추가: .map_or("알 수 없음".into(), |n| format!("{n} B")), | |
| 223 | 추가: ); | |
| 224 | 추가: ui.label(match entry.kind { | |
| 225 | 추가: Kind::File => "파일", | |
| 226 | 추가: Kind::Directory => "폴더", | |
| 227 | 추가: Kind::Link => "링크", | |
| 228 | 추가: Kind::Other => "기타", | |
| 229 | 추가: }); | |
| 230 | 추가: ui.label(if entry.encrypted { "있음" } else { "없음" }); | |
| 231 | 추가: ui.end_row(); | |
| 232 | 추가: } | |
| 233 | 추가: }); | |
| 234 | 추가: if self.model.entries.is_empty() && self.model.list_id.is_some() { | |
| 235 | 추가: ui.label("압축파일에 항목이 없습니다"); | |
| 236 | 추가: } | |
| 237 | 추가: for (name, state) in &self.model.outputs { | |
| 238 | 추가: ui.label(format!("{name}: {}", disposition_label(*state))); | |
| 239 | 추가: } | |
| 240 | 추가: }); | |
| 241 | 추가: }); | |
| 242 | 추가: if self.open { | |
| 243 | 추가: egui::Window::new("파일 열기") | |
| 244 | 추가: .collapsible(false) | |
| 245 | 추가: .show(&ctx, |ui| { | |
| 246 | 추가: ui.label("압축파일 절대 경로"); | |
| 247 | 추가: ui.text_edit_singleline(&mut self.open_text); | |
| 248 | 추가: if ui.button("열기").clicked() { | |
| 249 | 추가: self.open_path(self.open_text.clone().into()); | |
| 250 | 추가: self.open = false; | |
| 251 | 추가: } | |
| 252 | 추가: if ui.button("닫기").clicked() { | |
| 253 | 추가: self.open = false; | |
| 254 | 추가: } | |
| 255 | 추가: }); | |
| 256 | 추가: } | |
| 257 | 추가: if self.create { | |
| 258 | 추가: egui::Window::new("ZIP 만들기") | |
| 259 | 추가: .collapsible(false) | |
| 260 | 추가: .show(&ctx, |ui| { | |
| 261 | 추가: ui.add_enabled_ui(!self.model.busy(), |ui| { | |
| 262 | 추가: ui.label("원본 파일 절대 경로 / 한 줄에 하나"); | |
| 263 | 추가: ui.add(egui::TextEdit::multiline(&mut self.sources).desired_rows(4)); | |
| 264 | 추가: ui.label("저장할 ZIP 절대 경로"); | |
| 265 | 추가: ui.text_edit_singleline(&mut self.zip_output); | |
| 266 | 추가: ui.horizontal(|ui| { | |
| 267 | 추가: ui.selectable_value(&mut self.method, Method::Deflate, "압축"); | |
| 268 | 추가: ui.selectable_value(&mut self.method, Method::Store, "묶기"); | |
| 269 | 추가: }); | |
| 270 | 추가: ui.label("암호 ZIP 생성은 작업자 지원 후 활성화됩니다"); | |
| 271 | 추가: if ui.button("ZIP 만들기").clicked() { | |
| 272 | 추가: let sources = self | |
| 273 | 추가: .sources | |
| 274 | 추가: .lines() | |
| 275 | 추가: .map(|s| { | |
| 276 | 추가: let path = PathBuf::from(s); | |
| 277 | 추가: let name = path | |
| 278 | 추가: .file_name() | |
| 279 | 추가: .and_then(|n| n.to_str()) | |
| 280 | 추가: .unwrap_or("") | |
| 281 | 추가: .to_owned(); | |
| 282 | 추가: (path, name) | |
| 283 | 추가: }) | |
| 284 | 추가: .collect(); | |
| 285 | 추가: if self.model.begin( | |
| 286 | 추가: Start::CreateZip { | |
| 287 | 추가: sources, | |
| 288 | 추가: output_file: self.zip_output.clone().into(), | |
| 289 | 추가: method: self.method, | |
| 290 | 추가: aes256: false, | |
| 291 | 추가: }, | |
| 292 | 추가: self.factory.as_mut(), | |
| 293 | 추가: ) { | |
| 294 | 추가: self.create = false; | |
| 295 | 추가: } | |
| 296 | 추가: } | |
| 297 | 추가: }); | |
| 298 | 추가: if ui.button("닫기").clicked() { | |
| 299 | 추가: self.create = false; | |
| 300 | 추가: } | |
| 301 | 추가: }); | |
| 302 | 추가: } | |
| 303 | 추가: if let Some((_, attempt, encrypt)) = self.model.challenge { | |
| 304 | 추가: egui::Window::new(if encrypt { | |
| 305 | 추가: "ZIP 암호 설정" | |
| 306 | 추가: } else { | |
| 307 | 추가: "압축파일 암호" | |
| 308 | 추가: }) | |
| 309 | 추가: .collapsible(false) | |
| 310 | 추가: .show(&ctx, |ui| { | |
| 311 | 추가: ui.label(format!("암호 입력 요청 {attempt}")); | |
| 312 | 추가: let edit = ui.add( | |
| 313 | 추가: egui::TextEdit::singleline(&mut self.password) | |
| 314 | 추가: .password(true) | |
| 315 | 추가: .char_limit(1024), | |
| 316 | 추가: ); | |
| 317 | 추가: if ui.button("암호 전달").clicked() | |
| 318 | 추가: || (edit.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) | |
| 319 | 추가: { | |
| 320 | 추가: let text = std::mem::take(&mut self.password); | |
| 321 | 추가: self.model.password(text); | |
| 322 | 추가: } | |
| 323 | 추가: if ui.button("작업 취소").clicked() { | |
| 324 | 추가: self.password.clear(); | |
| 325 | 추가: self.model.cancel(); | |
| 326 | 추가: } | |
| 327 | 추가: }); | |
| 328 | 추가: } | |
| 329 | 추가: match self.model.close { | |
| 330 | 추가: Close::Confirm => { | |
| 331 | 추가: egui::Window::new("작업 중 닫기") | |
| 332 | 추가: .collapsible(false) | |
| 333 | 추가: .show(&ctx, |ui| { | |
| 334 | 추가: ui.label("취소를 요청하고 작업자 종료를 기다릴까요?"); | |
| 335 | 추가: if ui.button("계속 열기").clicked() { | |
| 336 | 추가: self.model.keep_open(); | |
| 337 | 추가: } | |
| 338 | 추가: if ui.button("취소 후 기다리기").clicked() { | |
| 339 | 추가: self.model.confirm_close(); | |
| 340 | 추가: } | |
| 341 | 추가: }); | |
| 342 | 추가: } | |
| 343 | 추가: Close::Waiting => { | |
| 344 | 추가: egui::Window::new("종료 확인 중") | |
| 345 | 추가: .collapsible(false) | |
| 346 | 추가: .show(&ctx, |ui| { | |
| 347 | 추가: ui.label("취소 결과와 프로세스 종료를 기다립니다"); | |
| 348 | 추가: if ui.button("닫기 철회").clicked() { | |
| 349 | 추가: self.model.keep_open(); | |
| 350 | 추가: } | |
| 351 | 추가: }); | |
| 352 | 추가: } | |
| 353 | 추가: Close::Review => { | |
| 354 | 추가: egui::Window::new("결과 확인 후 닫기") | |
| 355 | 추가: .collapsible(false) | |
| 356 | 추가: .show(&ctx, |ui| { | |
| 357 | 추가: ui.label(self.model.status()); | |
| 358 | 추가: if let Some(t) = &self.model.terminal { | |
| 359 | 추가: for line in terminal_lines(t) { | |
| 360 | 추가: ui.label(line); | |
| 361 | 추가: } | |
| 362 | 추가: } | |
| 363 | 추가: if ui.button("계속 열기").clicked() { | |
| 364 | 추가: self.model.keep_open(); | |
| 365 | 추가: } | |
| 366 | 추가: if ui.button("닫기").clicked() { | |
| 367 | 추가: self.model.acknowledge_close(); | |
| 368 | 추가: } | |
| 369 | 추가: }); | |
| 370 | 추가: } | |
| 371 | 추가: _ => {} | |
| 372 | 추가: } | |
| 373 | 추가: if self.model.busy() { | |
| 374 | 추가: ctx.request_repaint_after(std::time::Duration::from_millis(30)); | |
| 375 | 추가: } | |
| 376 | 추가: } | |
| 377 | 추가: } | |
| 378 | 추가: | |
| 379 | 추가: impl eframe::App for ArchiveApp { | |
| 380 | 추가: fn ui(&mut self, root: &mut egui::Ui, _: &mut eframe::Frame) { | |
| 381 | 추가: self.show(root); | |
| 382 | 추가: } | |
| 383 | 추가: } |
| @@ -0,0 +1,812 @@ | ||
| 1 | 추가: use std::{collections::BTreeSet, path::PathBuf}; | |
| 2 | 추가: | |
| 3 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 4 | 추가: pub enum Format { | |
| 5 | 추가: Zip, | |
| 6 | 추가: Tar, | |
| 7 | 추가: Gzip, | |
| 8 | 추가: TarGzip, | |
| 9 | 추가: } | |
| 10 | 추가: #[derive(Clone, Debug, Eq, PartialEq)] | |
| 11 | 추가: pub enum SourceObject { | |
| 12 | 추가: Unix { device: u64, inode: u64 }, | |
| 13 | 추가: Windows { volume: u64, file_id: [u8; 16] }, | |
| 14 | 추가: } | |
| 15 | 추가: #[derive(Clone, Debug, Eq, PartialEq)] | |
| 16 | 추가: pub struct ListId { | |
| 17 | 추가: pub catalog_version: u16, | |
| 18 | 추가: pub format: Format, | |
| 19 | 추가: pub source_object: SourceObject, | |
| 20 | 추가: pub archive_bytes: u64, | |
| 21 | 추가: pub archive_sha256: [u8; 32], | |
| 22 | 추가: } | |
| 23 | 추가: #[derive(Clone, Debug, Eq, PartialEq)] | |
| 24 | 추가: pub enum Selection { | |
| 25 | 추가: All, | |
| 26 | 추가: EntryIds(Vec<u32>), | |
| 27 | 추가: } | |
| 28 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 29 | 추가: pub enum Method { | |
| 30 | 추가: Store, | |
| 31 | 추가: Deflate, | |
| 32 | 추가: } | |
| 33 | 추가: #[derive(Clone, Debug, Eq, PartialEq)] | |
| 34 | 추가: pub enum Start { | |
| 35 | 추가: List { | |
| 36 | 추가: archive: PathBuf, | |
| 37 | 추가: }, | |
| 38 | 추가: Extract { | |
| 39 | 추가: archive: PathBuf, | |
| 40 | 추가: destination: PathBuf, | |
| 41 | 추가: selection: Selection, | |
| 42 | 추가: list_id: ListId, | |
| 43 | 추가: gzip_output_name: Option<String>, | |
| 44 | 추가: }, | |
| 45 | 추가: CreateZip { | |
| 46 | 추가: sources: Vec<(PathBuf, String)>, | |
| 47 | 추가: output_file: PathBuf, | |
| 48 | 추가: method: Method, | |
| 49 | 추가: aes256: bool, | |
| 50 | 추가: }, | |
| 51 | 추가: } | |
| 52 | 추가: // 암호를 Debug와 로그에서 제외하고 소유 버퍼를 해제 전에 지움. | |
| 53 | 추가: pub struct Secret(Vec<u8>); | |
| 54 | 추가: impl Secret { | |
| 55 | 추가: pub fn new(text: String) -> Result<Self, &'static str> { | |
| 56 | 추가: if text.is_empty() || text.len() > 1024 { | |
| 57 | 추가: return Err("암호는 UTF-8 1~1024바이트로 입력하세요"); | |
| 58 | 추가: } | |
| 59 | 추가: Ok(Self(text.into_bytes())) | |
| 60 | 추가: } | |
| 61 | 추가: pub fn as_bytes(&self) -> &[u8] { | |
| 62 | 추가: &self.0 | |
| 63 | 추가: } | |
| 64 | 추가: } | |
| 65 | 추가: impl Drop for Secret { | |
| 66 | 추가: fn drop(&mut self) { | |
| 67 | 추가: self.0.fill(0); | |
| 68 | 추가: } | |
| 69 | 추가: } | |
| 70 | 추가: pub enum Command { | |
| 71 | 추가: Start(Start), | |
| 72 | 추가: Password { challenge_id: u64, secret: Secret }, | |
| 73 | 추가: Cancel, | |
| 74 | 추가: } | |
| 75 | 추가: pub struct Request { | |
| 76 | 추가: pub job_id: u64, | |
| 77 | 추가: pub sequence: u64, | |
| 78 | 추가: pub command: Command, | |
| 79 | 추가: } | |
| 80 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 81 | 추가: pub enum Kind { | |
| 82 | 추가: File, | |
| 83 | 추가: Directory, | |
| 84 | 추가: Link, | |
| 85 | 추가: Other, | |
| 86 | 추가: } | |
| 87 | 추가: #[derive(Clone, Debug, Eq, PartialEq)] | |
| 88 | 추가: pub struct Entry { | |
| 89 | 추가: pub id: u32, | |
| 90 | 추가: pub name: String, | |
| 91 | 추가: pub kind: Kind, | |
| 92 | 추가: pub bytes: Option<u64>, | |
| 93 | 추가: pub packed: Option<u64>, | |
| 94 | 추가: pub encrypted: bool, | |
| 95 | 추가: } | |
| 96 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 97 | 추가: pub enum CancelStatus { | |
| 98 | 추가: Requested, | |
| 99 | 추가: AlreadyRequested, | |
| 100 | 추가: TooLate, | |
| 101 | 추가: Finished, | |
| 102 | 추가: } | |
| 103 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 104 | 추가: pub enum Stage { | |
| 105 | 추가: Scan, | |
| 106 | 추가: Read, | |
| 107 | 추가: Decode, | |
| 108 | 추가: Write, | |
| 109 | 추가: Verify, | |
| 110 | 추가: Commit, | |
| 111 | 추가: } | |
| 112 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 113 | 추가: pub enum Outcome { | |
| 114 | 추가: Completed, | |
| 115 | 추가: Failed, | |
| 116 | 추가: Cancelled, | |
| 117 | 추가: } | |
| 118 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 119 | 추가: pub enum ErrorCode { | |
| 120 | 추가: Integrity, | |
| 121 | 추가: UnsupportedFormat, | |
| 122 | 추가: UnsupportedFeature, | |
| 123 | 추가: WrongPassword, | |
| 124 | 추가: UnsafePath, | |
| 125 | 추가: Conflict, | |
| 126 | 추가: Limit, | |
| 127 | 추가: Io, | |
| 128 | 추가: Protocol, | |
| 129 | 추가: Internal, | |
| 130 | 추가: SourceChanged, | |
| 131 | 추가: InvalidRequest, | |
| 132 | 추가: } | |
| 133 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 134 | 추가: pub enum Publication { | |
| 135 | 추가: None, | |
| 136 | 추가: Partial, | |
| 137 | 추가: Complete, | |
| 138 | 추가: Uncertain, | |
| 139 | 추가: } | |
| 140 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 141 | 추가: pub enum Durability { | |
| 142 | 추가: NotApplicable, | |
| 143 | 추가: Synced, | |
| 144 | 추가: Unconfirmed, | |
| 145 | 추가: Failed, | |
| 146 | 추가: } | |
| 147 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 148 | 추가: pub enum Cleanup { | |
| 149 | 추가: Complete, | |
| 150 | 추가: Failed, | |
| 151 | 추가: Unconfirmed, | |
| 152 | 추가: } | |
| 153 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 154 | 추가: pub enum Disposition { | |
| 155 | 추가: Created, | |
| 156 | 추가: PartialRetained, | |
| 157 | 추가: Removed, | |
| 158 | 추가: CommitUncertain, | |
| 159 | 추가: } | |
| 160 | 추가: #[derive(Clone, Debug)] | |
| 161 | 추가: pub struct Terminal { | |
| 162 | 추가: pub outcome: Outcome, | |
| 163 | 추가: pub error: Option<ErrorCode>, | |
| 164 | 추가: pub publication: Publication, | |
| 165 | 추가: pub created_count: u64, | |
| 166 | 추가: pub retained_partial_count: u64, | |
| 167 | 추가: pub durability: Durability, | |
| 168 | 추가: pub cleanup: Cleanup, | |
| 169 | 추가: } | |
| 170 | 추가: #[derive(Clone, Debug)] | |
| 171 | 추가: pub enum Event { | |
| 172 | 추가: Accepted { | |
| 173 | 추가: encryption: bool, | |
| 174 | 추가: }, | |
| 175 | 추가: Entry(Entry), | |
| 176 | 추가: ListEnd { | |
| 177 | 추가: entry_count: u32, | |
| 178 | 추가: list_id: ListId, | |
| 179 | 추가: }, | |
| 180 | 추가: PasswordRequired { | |
| 181 | 추가: challenge_id: u64, | |
| 182 | 추가: attempt: u32, | |
| 183 | 추가: encrypt: bool, | |
| 184 | 추가: }, | |
| 185 | 추가: Progress { | |
| 186 | 추가: stage: Stage, | |
| 187 | 추가: processed: u64, | |
| 188 | 추가: total: Option<u64>, | |
| 189 | 추가: completed_entries: u64, | |
| 190 | 추가: }, | |
| 191 | 추가: Output { | |
| 192 | 추가: entry_id: Option<u32>, | |
| 193 | 추가: relative_name: String, | |
| 194 | 추가: disposition: Disposition, | |
| 195 | 추가: }, | |
| 196 | 추가: CancelAck { | |
| 197 | 추가: request_sequence: u64, | |
| 198 | 추가: status: CancelStatus, | |
| 199 | 추가: }, | |
| 200 | 추가: Terminal(Terminal), | |
| 201 | 추가: } | |
| 202 | 추가: pub enum HostEvent { | |
| 203 | 추가: Fault(String), | |
| 204 | 추가: CleanupComplete, | |
| 205 | 추가: Frame { | |
| 206 | 추가: job_id: u64, | |
| 207 | 추가: sequence: u64, | |
| 208 | 추가: event: Event, | |
| 209 | 추가: }, | |
| 210 | 추가: StdoutEof, | |
| 211 | 추가: StderrEof, | |
| 212 | 추가: Exited { | |
| 213 | 추가: success: bool, | |
| 214 | 추가: }, | |
| 215 | 추가: } | |
| 216 | 추가: // 바이트 codec과 프로세스 소유는 작업자 어댑터에서 담당함. | |
| 217 | 추가: // 전송 실패 후에도 poll로 양쪽 EOF와 자식 회수 결과를 전달함. | |
| 218 | 추가: pub trait Connection { | |
| 219 | 추가: fn send(&mut self, request: Request) -> Result<(), String>; | |
| 220 | 추가: fn poll(&mut self) -> Option<HostEvent>; | |
| 221 | 추가: } | |
| 222 | 추가: pub trait Factory { | |
| 223 | 추가: fn connect(&mut self, job_id: u64) -> Result<Box<dyn Connection>, String>; | |
| 224 | 추가: } | |
| 225 | 추가: pub struct Unavailable; | |
| 226 | 추가: impl Factory for Unavailable { | |
| 227 | 추가: fn connect(&mut self, _: u64) -> Result<Box<dyn Connection>, String> { | |
| 228 | 추가: Err("작업자 연결이 아직 준비되지 않았습니다".into()) | |
| 229 | 추가: } | |
| 230 | 추가: } | |
| 231 | 추가: struct Running { | |
| 232 | 추가: id: u64, | |
| 233 | 추가: outgoing: u64, | |
| 234 | 추가: incoming: u64, | |
| 235 | 추가: accepted: bool, | |
| 236 | 추가: start_failed: bool, | |
| 237 | 추가: start: Start, | |
| 238 | 추가: connection: Box<dyn Connection>, | |
| 239 | 추가: entries: Vec<Entry>, | |
| 240 | 추가: list_end: Option<(u32, ListId)>, | |
| 241 | 추가: stdout_eof: bool, | |
| 242 | 추가: transport_closed: bool, | |
| 243 | 추가: stderr_eof: bool, | |
| 244 | 추가: exit: Option<bool>, | |
| 245 | 추가: cancel_sequence: Option<u64>, | |
| 246 | 추가: } | |
| 247 | 추가: #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] | |
| 248 | 추가: pub enum Close { | |
| 249 | 추가: #[default] | |
| 250 | 추가: Open, | |
| 251 | 추가: Confirm, | |
| 252 | 추가: Waiting, | |
| 253 | 추가: Review, | |
| 254 | 추가: Allowed, | |
| 255 | 추가: } | |
| 256 | 추가: #[derive(Default)] | |
| 257 | 추가: pub struct Model { | |
| 258 | 추가: running: Option<Running>, | |
| 259 | 추가: next_id: u64, | |
| 260 | 추가: pub archive: Option<PathBuf>, | |
| 261 | 추가: pub entries: Vec<Entry>, | |
| 262 | 추가: pub list_id: Option<ListId>, | |
| 263 | 추가: pub selected: BTreeSet<u32>, | |
| 264 | 추가: pub terminal: Option<Terminal>, | |
| 265 | 추가: pub challenge: Option<(u64, u32, bool)>, | |
| 266 | 추가: pub progress: Option<(Stage, u64, Option<u64>, u64)>, | |
| 267 | 추가: pub outputs: Vec<(String, Disposition)>, | |
| 268 | 추가: pub cancel: Option<CancelStatus>, | |
| 269 | 추가: pub error: Option<String>, | |
| 270 | 추가: pub encryption: bool, | |
| 271 | 추가: pub close: Close, | |
| 272 | 추가: pub confirmed: bool, | |
| 273 | 추가: } | |
| 274 | 추가: impl Model { | |
| 275 | 추가: pub fn busy(&self) -> bool { | |
| 276 | 추가: self.running.is_some() | |
| 277 | 추가: } | |
| 278 | 추가: pub fn job_id(&self) -> Option<u64> { | |
| 279 | 추가: self.running.as_ref().map(|r| r.id) | |
| 280 | 추가: } | |
| 281 | 추가: pub fn can_extract(&self) -> bool { | |
| 282 | 추가: !self.busy() | |
| 283 | 추가: && self.list_id.is_some() | |
| 284 | 추가: && self.archive.is_some() | |
| 285 | 추가: && self.close == Close::Open | |
| 286 | 추가: } | |
| 287 | 추가: pub fn begin(&mut self, start: Start, factory: &mut dyn Factory) -> bool { | |
| 288 | 추가: if self.busy() || self.close != Close::Open { | |
| 289 | 추가: return false; | |
| 290 | 추가: } | |
| 291 | 추가: let validation = match &start { | |
| 292 | 추가: Start::List { archive } => archive.is_absolute(), | |
| 293 | 추가: Start::Extract { | |
| 294 | 추가: archive, | |
| 295 | 추가: destination, | |
| 296 | 추가: selection, | |
| 297 | 추가: gzip_output_name, | |
| 298 | 추가: list_id, | |
| 299 | 추가: } => { | |
| 300 | 추가: archive.is_absolute() | |
| 301 | 추가: && destination.is_absolute() | |
| 302 | 추가: && self.archive.as_ref() == Some(archive) | |
| 303 | 추가: && self.list_id.as_ref() == Some(list_id) | |
| 304 | 추가: && match list_id.format { | |
| 305 | 추가: Format::Gzip => gzip_output_name.as_ref().is_some_and(|s| valid_leaf(s)), | |
| 306 | 추가: _ => gzip_output_name.is_none(), | |
| 307 | 추가: } | |
| 308 | 추가: && match selection { | |
| 309 | 추가: Selection::All => true, | |
| 310 | 추가: Selection::EntryIds(ids) => { | |
| 311 | 추가: !ids.is_empty() | |
| 312 | 추가: && ids.iter().collect::<BTreeSet<_>>().len() == ids.len() | |
| 313 | 추가: && ids.iter().all(|id| { | |
| 314 | 추가: self.entries.iter().any(|e| { | |
| 315 | 추가: e.id == *id | |
| 316 | 추가: && matches!(e.kind, Kind::File | Kind::Directory) | |
| 317 | 추가: }) | |
| 318 | 추가: }) | |
| 319 | 추가: } | |
| 320 | 추가: } | |
| 321 | 추가: } | |
| 322 | 추가: Start::CreateZip { | |
| 323 | 추가: sources, | |
| 324 | 추가: output_file, | |
| 325 | 추가: aes256, | |
| 326 | 추가: .. | |
| 327 | 추가: } => { | |
| 328 | 추가: !sources.is_empty() | |
| 329 | 추가: && output_file.is_absolute() | |
| 330 | 추가: && (!aes256 || self.encryption) | |
| 331 | 추가: && sources | |
| 332 | 추가: .iter() | |
| 333 | 추가: .all(|(p, n)| p.is_absolute() && valid_relative(n)) | |
| 334 | 추가: } | |
| 335 | 추가: }; | |
| 336 | 추가: if !validation { | |
| 337 | 추가: self.error = Some("입력 경로, 출력명과 선택한 목록을 확인하세요".into()); | |
| 338 | 추가: return false; | |
| 339 | 추가: } | |
| 340 | 추가: let Some(id) = self.next_id.checked_add(1) else { | |
| 341 | 추가: self.error = Some("작업 ID 한도에 도달했습니다".into()); | |
| 342 | 추가: return false; | |
| 343 | 추가: }; | |
| 344 | 추가: let mut connection = match factory.connect(id) { | |
| 345 | 추가: Ok(c) => c, | |
| 346 | 추가: Err(e) => { | |
| 347 | 추가: self.error = Some(e); | |
| 348 | 추가: return false; | |
| 349 | 추가: } | |
| 350 | 추가: }; | |
| 351 | 추가: let send_error = connection | |
| 352 | 추가: .send(Request { | |
| 353 | 추가: job_id: id, | |
| 354 | 추가: sequence: 0, | |
| 355 | 추가: command: Command::Start(start.clone()), | |
| 356 | 추가: }) | |
| 357 | 추가: .err(); | |
| 358 | 추가: let started = send_error.is_none(); | |
| 359 | 추가: if let Start::List { archive } = &start | |
| 360 | 추가: && started | |
| 361 | 추가: { | |
| 362 | 추가: self.archive = Some(archive.clone()); | |
| 363 | 추가: self.list_id = None; | |
| 364 | 추가: self.entries.clear(); | |
| 365 | 추가: self.selected.clear(); | |
| 366 | 추가: } | |
| 367 | 추가: self.next_id = id; | |
| 368 | 추가: self.terminal = None; | |
| 369 | 추가: self.challenge = None; | |
| 370 | 추가: self.progress = None; | |
| 371 | 추가: self.outputs.clear(); | |
| 372 | 추가: self.cancel = None; | |
| 373 | 추가: self.error = send_error; | |
| 374 | 추가: self.confirmed = false; | |
| 375 | 추가: self.running = Some(Running { | |
| 376 | 추가: id, | |
| 377 | 추가: outgoing: 1, | |
| 378 | 추가: incoming: 0, | |
| 379 | 추가: accepted: false, | |
| 380 | 추가: start_failed: !started, | |
| 381 | 추가: start, | |
| 382 | 추가: connection, | |
| 383 | 추가: entries: Vec::new(), | |
| 384 | 추가: list_end: None, | |
| 385 | 추가: stdout_eof: false, | |
| 386 | 추가: transport_closed: false, | |
| 387 | 추가: stderr_eof: false, | |
| 388 | 추가: exit: None, | |
| 389 | 추가: cancel_sequence: None, | |
| 390 | 추가: }); | |
| 391 | 추가: started | |
| 392 | 추가: } | |
| 393 | 추가: pub fn extract( | |
| 394 | 추가: &mut self, | |
| 395 | 추가: destination: PathBuf, | |
| 396 | 추가: selected_only: bool, | |
| 397 | 추가: gzip_output_name: Option<String>, | |
| 398 | 추가: factory: &mut dyn Factory, | |
| 399 | 추가: ) -> bool { | |
| 400 | 추가: if !self.can_extract() { | |
| 401 | 추가: return false; | |
| 402 | 추가: } | |
| 403 | 추가: self.begin( | |
| 404 | 추가: Start::Extract { | |
| 405 | 추가: archive: self.archive.clone().unwrap(), | |
| 406 | 추가: destination, | |
| 407 | 추가: selection: if selected_only { | |
| 408 | 추가: Selection::EntryIds(self.selected.iter().copied().collect()) | |
| 409 | 추가: } else { | |
| 410 | 추가: Selection::All | |
| 411 | 추가: }, | |
| 412 | 추가: list_id: self.list_id.clone().unwrap(), | |
| 413 | 추가: gzip_output_name, | |
| 414 | 추가: }, | |
| 415 | 추가: factory, | |
| 416 | 추가: ) | |
| 417 | 추가: } | |
| 418 | 추가: pub fn password(&mut self, text: String) -> bool { | |
| 419 | 추가: let Some((challenge_id, _, _)) = self.challenge else { | |
| 420 | 추가: return false; | |
| 421 | 추가: }; | |
| 422 | 추가: let secret = match Secret::new(text) { | |
| 423 | 추가: Ok(s) => s, | |
| 424 | 추가: Err(e) => { | |
| 425 | 추가: self.error = Some(e.into()); | |
| 426 | 추가: return false; | |
| 427 | 추가: } | |
| 428 | 추가: }; | |
| 429 | 추가: if self | |
| 430 | 추가: .send(Command::Password { | |
| 431 | 추가: challenge_id, | |
| 432 | 추가: secret, | |
| 433 | 추가: }) | |
| 434 | 추가: .is_some() | |
| 435 | 추가: { | |
| 436 | 추가: self.challenge = None; | |
| 437 | 추가: self.error = None; | |
| 438 | 추가: true | |
| 439 | 추가: } else { | |
| 440 | 추가: false | |
| 441 | 추가: } | |
| 442 | 추가: } | |
| 443 | 추가: fn send(&mut self, command: Command) -> Option<u64> { | |
| 444 | 추가: let run = self.running.as_mut()?; | |
| 445 | 추가: if run.start_failed || self.terminal.is_some() || run.exit.is_some() { | |
| 446 | 추가: return None; | |
| 447 | 추가: } | |
| 448 | 추가: let seq = run.outgoing; | |
| 449 | 추가: let Some(next) = seq.checked_add(1) else { | |
| 450 | 추가: self.error = Some("요청 순서 한도 초과".into()); | |
| 451 | 추가: return None; | |
| 452 | 추가: }; | |
| 453 | 추가: match run.connection.send(Request { | |
| 454 | 추가: job_id: run.id, | |
| 455 | 추가: sequence: seq, | |
| 456 | 추가: command, | |
| 457 | 추가: }) { | |
| 458 | 추가: Ok(()) => { | |
| 459 | 추가: run.outgoing = next; | |
| 460 | 추가: Some(seq) | |
| 461 | 추가: } | |
| 462 | 추가: Err(e) => { | |
| 463 | 추가: self.error = Some(e); | |
| 464 | 추가: None | |
| 465 | 추가: } | |
| 466 | 추가: } | |
| 467 | 추가: } | |
| 468 | 추가: pub fn cancel(&mut self) { | |
| 469 | 추가: if self | |
| 470 | 추가: .running | |
| 471 | 추가: .as_ref() | |
| 472 | 추가: .is_some_and(|r| r.cancel_sequence.is_none()) | |
| 473 | 추가: { | |
| 474 | 추가: if let Some(seq) = self.send(Command::Cancel) { | |
| 475 | 추가: self.running.as_mut().unwrap().cancel_sequence = Some(seq); | |
| 476 | 추가: self.challenge = None; | |
| 477 | 추가: } | |
| 478 | 추가: } | |
| 479 | 추가: } | |
| 480 | 추가: pub fn request_close(&mut self) { | |
| 481 | 추가: if self.close == Close::Open { | |
| 482 | 추가: self.close = if self.busy() { | |
| 483 | 추가: Close::Confirm | |
| 484 | 추가: } else { | |
| 485 | 추가: Close::Review | |
| 486 | 추가: }; | |
| 487 | 추가: } | |
| 488 | 추가: } | |
| 489 | 추가: pub fn confirm_close(&mut self) { | |
| 490 | 추가: if self.close == Close::Confirm { | |
| 491 | 추가: self.cancel(); | |
| 492 | 추가: self.close = if self.busy() { | |
| 493 | 추가: Close::Waiting | |
| 494 | 추가: } else { | |
| 495 | 추가: Close::Review | |
| 496 | 추가: }; | |
| 497 | 추가: } | |
| 498 | 추가: } | |
| 499 | 추가: pub fn keep_open(&mut self) { | |
| 500 | 추가: if self.close != Close::Allowed { | |
| 501 | 추가: self.close = Close::Open; | |
| 502 | 추가: } | |
| 503 | 추가: } | |
| 504 | 추가: pub fn acknowledge_close(&mut self) { | |
| 505 | 추가: if !self.busy() && self.close == Close::Review { | |
| 506 | 추가: self.close = Close::Allowed; | |
| 507 | 추가: } | |
| 508 | 추가: } | |
| 509 | 추가: pub fn poll(&mut self) { | |
| 510 | 추가: for _ in 0..128 { | |
| 511 | 추가: let Some(event) = self.running.as_mut().and_then(|r| r.connection.poll()) else { | |
| 512 | 추가: break; | |
| 513 | 추가: }; | |
| 514 | 추가: self.receive(event); | |
| 515 | 추가: } | |
| 516 | 추가: let complete = self.running.as_ref().is_some_and(|r| { | |
| 517 | 추가: r.exit.is_some() | |
| 518 | 추가: && ((r.stdout_eof && r.stderr_eof) || (r.transport_closed && self.error.is_some())) | |
| 519 | 추가: }); | |
| 520 | 추가: if complete { | |
| 521 | 추가: let run = self.running.take().unwrap(); | |
| 522 | 추가: self.confirmed = | |
| 523 | 추가: self.terminal.is_some() && run.exit == Some(true) && self.error.is_none(); | |
| 524 | 추가: if !self.confirmed { | |
| 525 | 추가: self.error.get_or_insert( | |
| 526 | 추가: "작업자 종료 결과를 확인할 수 없습니다. 출력 상태를 확인하세요".into(), | |
| 527 | 추가: ); | |
| 528 | 추가: } | |
| 529 | 추가: if self.confirmed | |
| 530 | 추가: && self | |
| 531 | 추가: .terminal | |
| 532 | 추가: .as_ref() | |
| 533 | 추가: .is_some_and(|t| t.outcome == Outcome::Completed) | |
| 534 | 추가: { | |
| 535 | 추가: if matches!(run.start, Start::List { .. }) { | |
| 536 | 추가: if let Some((count, id)) = run | |
| 537 | 추가: .list_end | |
| 538 | 추가: .filter(|(n, _)| *n as usize == run.entries.len()) | |
| 539 | 추가: { | |
| 540 | 추가: let _ = count; | |
| 541 | 추가: self.entries = run.entries; | |
| 542 | 추가: self.list_id = Some(id); | |
| 543 | 추가: } else { | |
| 544 | 추가: self.error = Some("목록 완료 정보가 일치하지 않습니다. 다시 여세요".into()); | |
| 545 | 추가: self.confirmed = false; | |
| 546 | 추가: } | |
| 547 | 추가: } | |
| 548 | 추가: } | |
| 549 | 추가: if self | |
| 550 | 추가: .terminal | |
| 551 | 추가: .as_ref() | |
| 552 | 추가: .is_some_and(|t| t.error == Some(ErrorCode::SourceChanged)) | |
| 553 | 추가: { | |
| 554 | 추가: self.list_id = None; | |
| 555 | 추가: self.selected.clear(); | |
| 556 | 추가: } | |
| 557 | 추가: self.challenge = None; | |
| 558 | 추가: if matches!(self.close, Close::Waiting | Close::Confirm) { | |
| 559 | 추가: self.close = Close::Review; | |
| 560 | 추가: } | |
| 561 | 추가: } | |
| 562 | 추가: } | |
| 563 | 추가: fn receive(&mut self, host: HostEvent) { | |
| 564 | 추가: let run = self.running.as_mut().unwrap(); | |
| 565 | 추가: match host { | |
| 566 | 추가: HostEvent::Fault(message) => self.error = Some(message), | |
| 567 | 추가: HostEvent::CleanupComplete => run.transport_closed = true, | |
| 568 | 추가: HostEvent::StdoutEof => run.stdout_eof = true, | |
| 569 | 추가: HostEvent::StderrEof => run.stderr_eof = true, | |
| 570 | 추가: HostEvent::Exited { success } => run.exit = Some(success), | |
| 571 | 추가: HostEvent::Frame { | |
| 572 | 추가: job_id, | |
| 573 | 추가: sequence, | |
| 574 | 추가: event, | |
| 575 | 추가: } => { | |
| 576 | 추가: if job_id != run.id | |
| 577 | 추가: || sequence != run.incoming | |
| 578 | 추가: || self.terminal.is_some() | |
| 579 | 추가: || run.stdout_eof | |
| 580 | 추가: || sequence >= 1_000_000 | |
| 581 | 추가: { | |
| 582 | 추가: self.error = Some("작업자 응답 순서나 작업 ID가 일치하지 않습니다".into()); | |
| 583 | 추가: return; | |
| 584 | 추가: } | |
| 585 | 추가: run.incoming += 1; | |
| 586 | 추가: if !run.accepted && !matches!(event, Event::Accepted { .. }) { | |
| 587 | 추가: self.error = Some("작업 승인 응답이 없습니다".into()); | |
| 588 | 추가: return; | |
| 589 | 추가: } | |
| 590 | 추가: match event { | |
| 591 | 추가: Event::Accepted { encryption } => { | |
| 592 | 추가: if run.accepted { | |
| 593 | 추가: self.error = Some("작업 승인 중복".into()); | |
| 594 | 추가: } | |
| 595 | 추가: run.accepted = true; | |
| 596 | 추가: self.encryption = encryption; | |
| 597 | 추가: } | |
| 598 | 추가: Event::Entry(entry) => { | |
| 599 | 추가: if !matches!(run.start, Start::List { .. }) | |
| 600 | 추가: || run.list_end.is_some() | |
| 601 | 추가: || entry.id as usize != run.entries.len() | |
| 602 | 추가: || entry.name.len() > 4096 | |
| 603 | 추가: || run.entries.len() >= 100_000 | |
| 604 | 추가: { | |
| 605 | 추가: self.error = Some("목록 응답이 유효하지 않습니다".into()); | |
| 606 | 추가: } else { | |
| 607 | 추가: run.entries.push(entry); | |
| 608 | 추가: } | |
| 609 | 추가: } | |
| 610 | 추가: Event::ListEnd { | |
| 611 | 추가: entry_count, | |
| 612 | 추가: list_id, | |
| 613 | 추가: } => { | |
| 614 | 추가: if !matches!(run.start, Start::List { .. }) | |
| 615 | 추가: || run.list_end.is_some() | |
| 616 | 추가: || list_id.catalog_version != 1 | |
| 617 | 추가: { | |
| 618 | 추가: self.error = Some("목록 완료 응답이 유효하지 않습니다".into()); | |
| 619 | 추가: } else { | |
| 620 | 추가: run.list_end = Some((entry_count, list_id)); | |
| 621 | 추가: } | |
| 622 | 추가: } | |
| 623 | 추가: Event::PasswordRequired { | |
| 624 | 추가: challenge_id, | |
| 625 | 추가: attempt, | |
| 626 | 추가: encrypt, | |
| 627 | 추가: } => { | |
| 628 | 추가: if self.challenge.is_some() || challenge_id == 0 { | |
| 629 | 추가: self.error = Some("암호 요청이 유효하지 않습니다".into()); | |
| 630 | 추가: } else { | |
| 631 | 추가: self.challenge = Some((challenge_id, attempt, encrypt)); | |
| 632 | 추가: } | |
| 633 | 추가: } | |
| 634 | 추가: Event::Progress { | |
| 635 | 추가: stage, | |
| 636 | 추가: processed, | |
| 637 | 추가: total, | |
| 638 | 추가: completed_entries, | |
| 639 | 추가: } => self.progress = Some((stage, processed, total, completed_entries)), | |
| 640 | 추가: Event::Output { | |
| 641 | 추가: relative_name, | |
| 642 | 추가: disposition, | |
| 643 | 추가: .. | |
| 644 | 추가: } => { | |
| 645 | 추가: if self.outputs.len() < 100_000 && relative_name.len() <= 4096 { | |
| 646 | 추가: self.outputs.push((relative_name, disposition)); | |
| 647 | 추가: } else { | |
| 648 | 추가: self.error = Some("출력 보고 한도 초과".into()); | |
| 649 | 추가: } | |
| 650 | 추가: } | |
| 651 | 추가: Event::CancelAck { | |
| 652 | 추가: request_sequence, | |
| 653 | 추가: status, | |
| 654 | 추가: } => { | |
| 655 | 추가: if run.cancel_sequence == Some(request_sequence) && self.cancel.is_none() { | |
| 656 | 추가: self.cancel = Some(status); | |
| 657 | 추가: } else { | |
| 658 | 추가: self.error = Some("취소 응답이 요청과 일치하지 않습니다".into()); | |
| 659 | 추가: } | |
| 660 | 추가: } | |
| 661 | 추가: Event::Terminal(t) => { | |
| 662 | 추가: self.challenge = None; | |
| 663 | 추가: self.terminal = Some(t); | |
| 664 | 추가: } | |
| 665 | 추가: } | |
| 666 | 추가: } | |
| 667 | 추가: } | |
| 668 | 추가: } | |
| 669 | 추가: pub fn status(&self) -> String { | |
| 670 | 추가: if let Some(error) = &self.error { | |
| 671 | 추가: return error.clone(); | |
| 672 | 추가: } | |
| 673 | 추가: if self.busy() { | |
| 674 | 추가: if self.terminal.is_some() { | |
| 675 | 추가: return "작업 결과 수신 / 프로세스 종료 확인 중".into(); | |
| 676 | 추가: } | |
| 677 | 추가: if self.challenge.is_some() { | |
| 678 | 추가: return "암호를 입력하세요".into(); | |
| 679 | 추가: } | |
| 680 | 추가: if let Some(c) = self.cancel { | |
| 681 | 추가: return match c { | |
| 682 | 추가: CancelStatus::Requested | CancelStatus::AlreadyRequested => { | |
| 683 | 추가: "취소 요청 접수 / 최종 결과 대기" | |
| 684 | 추가: } | |
| 685 | 추가: CancelStatus::TooLate => "취소할 수 없는 단계 / 최종 결과 대기", | |
| 686 | 추가: CancelStatus::Finished => "처리 종료 응답 / 프로세스 종료 확인 중", | |
| 687 | 추가: } | |
| 688 | 추가: .into(); | |
| 689 | 추가: } | |
| 690 | 추가: if self | |
| 691 | 추가: .running | |
| 692 | 추가: .as_ref() | |
| 693 | 추가: .is_some_and(|r| r.cancel_sequence.is_some()) | |
| 694 | 추가: { | |
| 695 | 추가: return "취소 요청 전송 / 최종 결과 대기".into(); | |
| 696 | 추가: } | |
| 697 | 추가: return "작업 중".into(); | |
| 698 | 추가: } | |
| 699 | 추가: match self | |
| 700 | 추가: .terminal | |
| 701 | 추가: .as_ref() | |
| 702 | 추가: .filter(|_| self.confirmed) | |
| 703 | 추가: .map(|t| t.outcome) | |
| 704 | 추가: { | |
| 705 | 추가: Some(Outcome::Completed) => "작업 완료", | |
| 706 | 추가: Some(Outcome::Cancelled) => "작업 취소됨", | |
| 707 | 추가: Some(Outcome::Failed) => "작업 실패", | |
| 708 | 추가: None => "압축파일을 열거나 ZIP 파일을 만드세요", | |
| 709 | 추가: } | |
| 710 | 추가: .into() | |
| 711 | 추가: } | |
| 712 | 추가: } | |
| 713 | 추가: pub fn valid_leaf(name: &str) -> bool { | |
| 714 | 추가: valid_relative(name) && !name.contains('/') && !name.contains('\\') | |
| 715 | 추가: } | |
| 716 | 추가: pub fn valid_relative(name: &str) -> bool { | |
| 717 | 추가: !name.is_empty() | |
| 718 | 추가: && !name.contains('\0') | |
| 719 | 추가: && !name.contains(':') | |
| 720 | 추가: && !name.starts_with('/') | |
| 721 | 추가: && !name.starts_with('\\') | |
| 722 | 추가: && name | |
| 723 | 추가: .split(['/', '\\']) | |
| 724 | 추가: .all(|p| !p.is_empty() && p != "." && p != "..") | |
| 725 | 추가: } | |
| 726 | 추가: | |
| 727 | 추가: // 파일 연결로 전달된 원형 경로를 손실 변환 없이 보존함. | |
| 728 | 추가: pub fn launch_args( | |
| 729 | 추가: args: Vec<std::ffi::OsString>, | |
| 730 | 추가: cwd: PathBuf, | |
| 731 | 추가: ) -> Result<(bool, Option<PathBuf>), &'static str> { | |
| 732 | 추가: let fixture = args.iter().any(|arg| arg == "--ui-fixture"); | |
| 733 | 추가: let paths = args | |
| 734 | 추가: .into_iter() | |
| 735 | 추가: .filter(|arg| arg != "--ui-fixture") | |
| 736 | 추가: .collect::<Vec<_>>(); | |
| 737 | 추가: if paths.len() > 1 { | |
| 738 | 추가: return Err("압축파일 하나를 지정하세요"); | |
| 739 | 추가: } | |
| 740 | 추가: let path = paths | |
| 741 | 추가: .into_iter() | |
| 742 | 추가: .next() | |
| 743 | 추가: .map(PathBuf::from) | |
| 744 | 추가: .map(|p| if p.is_absolute() { p } else { cwd.join(p) }); | |
| 745 | 추가: Ok((fixture, path)) | |
| 746 | 추가: } | |
| 747 | 추가: | |
| 748 | 추가: pub fn stage_label(stage: Stage) -> &'static str { | |
| 749 | 추가: match stage { | |
| 750 | 추가: Stage::Scan => "목록 읽는 중", | |
| 751 | 추가: Stage::Read => "파일 읽는 중", | |
| 752 | 추가: Stage::Decode => "압축 푸는 중", | |
| 753 | 추가: Stage::Write => "파일 쓰는 중", | |
| 754 | 추가: Stage::Verify => "검증 중", | |
| 755 | 추가: Stage::Commit => "저장 마무리 중", | |
| 756 | 추가: } | |
| 757 | 추가: } | |
| 758 | 추가: pub fn disposition_label(disposition: Disposition) -> &'static str { | |
| 759 | 추가: match disposition { | |
| 760 | 추가: Disposition::Created => "생성됨", | |
| 761 | 추가: Disposition::PartialRetained => "일부 파일 남음", | |
| 762 | 추가: Disposition::Removed => "작업 임시 파일 정리됨", | |
| 763 | 추가: Disposition::CommitUncertain => "저장 여부 불확실", | |
| 764 | 추가: } | |
| 765 | 추가: } | |
| 766 | 추가: pub fn terminal_lines(t: &Terminal) -> Vec<String> { | |
| 767 | 추가: let publication = match t.publication { | |
| 768 | 추가: Publication::None => "게시된 파일 없음", | |
| 769 | 추가: Publication::Partial => "일부 파일 게시됨", | |
| 770 | 추가: Publication::Complete => "파일 게시 완료", | |
| 771 | 추가: Publication::Uncertain => "파일 게시 여부 불확실 / 출력 폴더를 확인하세요", | |
| 772 | 추가: }; | |
| 773 | 추가: let durability = match t.durability { | |
| 774 | 추가: Durability::NotApplicable => "동기화 해당 없음", | |
| 775 | 추가: Durability::Synced => "디스크 동기화 완료", | |
| 776 | 추가: Durability::Unconfirmed => "디스크 동기화 미확인", | |
| 777 | 추가: Durability::Failed => "디스크 동기화 실패", | |
| 778 | 추가: }; | |
| 779 | 추가: let cleanup = match t.cleanup { | |
| 780 | 추가: Cleanup::Complete => "작업 임시 파일 정리 완료", | |
| 781 | 추가: Cleanup::Failed => "작업 임시 파일 정리 실패", | |
| 782 | 추가: Cleanup::Unconfirmed => "작업 임시 파일 정리 미확인", | |
| 783 | 추가: }; | |
| 784 | 추가: let mut lines = vec![ | |
| 785 | 추가: publication.into(), | |
| 786 | 추가: format!( | |
| 787 | 추가: "생성 {}개 / 남은 임시 파일 {}개", | |
| 788 | 추가: t.created_count, t.retained_partial_count | |
| 789 | 추가: ), | |
| 790 | 추가: format!("{durability} / {cleanup}"), | |
| 791 | 추가: ]; | |
| 792 | 추가: if let Some(error) = t.error { | |
| 793 | 추가: lines.push( | |
| 794 | 추가: match error { | |
| 795 | 추가: ErrorCode::Integrity => "압축파일이 손상됐습니다", | |
| 796 | 추가: ErrorCode::UnsupportedFormat => "지원하지 않는 압축 형식입니다", | |
| 797 | 추가: ErrorCode::UnsupportedFeature => "아직 지원하지 않는 기능입니다", | |
| 798 | 추가: ErrorCode::WrongPassword => "암호가 올바르지 않습니다", | |
| 799 | 추가: ErrorCode::UnsafePath => "안전하지 않은 경로가 있어 중단했습니다", | |
| 800 | 추가: ErrorCode::Conflict => "같은 이름의 파일이 있습니다. 다른 출력 폴더를 선택하세요", | |
| 801 | 추가: ErrorCode::Limit => "처리 한도를 초과했습니다", | |
| 802 | 추가: ErrorCode::Io => "파일을 읽거나 쓰지 못했습니다", | |
| 803 | 추가: ErrorCode::Protocol => "작업자 응답이 올바르지 않습니다", | |
| 804 | 추가: ErrorCode::Internal => "작업자 처리 오류입니다", | |
| 805 | 추가: ErrorCode::SourceChanged => "원본 파일이 바뀌었습니다. 압축파일을 다시 여세요", | |
| 806 | 추가: ErrorCode::InvalidRequest => "입력과 선택한 항목을 확인하세요", | |
| 807 | 추가: } | |
| 808 | 추가: .into(), | |
| 809 | 추가: ); | |
| 810 | 추가: } | |
| 811 | 추가: lines | |
| 812 | 추가: } |
| @@ -0,0 +1,71 @@ | ||
| 1 | 추가: #[cfg(feature = "ui-fixture")] | |
| 2 | 추가: #[path = "../../../tests/rust-app-ui/fake.rs"] | |
| 3 | 추가: mod fake; | |
| 4 | 추가: #[path = "system_font.rs"] | |
| 5 | 추가: mod system_font; | |
| 6 | 추가: use eframe::egui::{self, Color32, FontData, FontDefinitions, FontFamily, FontId, TextStyle}; | |
| 7 | 추가: fn main() -> eframe::Result { | |
| 8 | 추가: let font = system_font::load().map_err(|e| eframe::Error::AppCreation(Box::new(e)))?; | |
| 9 | 추가: eframe::run_native( | |
| 10 | 추가: "Zipelo", | |
| 11 | 추가: eframe::NativeOptions { | |
| 12 | 추가: renderer: eframe::Renderer::Glow, | |
| 13 | 추가: viewport: egui::ViewportBuilder::default() | |
| 14 | 추가: .with_inner_size([1060.0, 720.0]) | |
| 15 | 추가: .with_min_inner_size([760.0, 540.0]), | |
| 16 | 추가: ..Default::default() | |
| 17 | 추가: }, | |
| 18 | 추가: Box::new(move |cc| { | |
| 19 | 추가: let mut fonts = FontDefinitions::empty(); | |
| 20 | 추가: let mut data = FontData::from_owned(font.bytes); | |
| 21 | 추가: data.index = font.face_index; | |
| 22 | 추가: fonts.font_data.insert("noto-kr".into(), data.into()); | |
| 23 | 추가: fonts | |
| 24 | 추가: .families | |
| 25 | 추가: .insert(FontFamily::Proportional, vec!["noto-kr".into()]); | |
| 26 | 추가: cc.egui_ctx.set_fonts(fonts); | |
| 27 | 추가: cc.egui_ctx.set_visuals(egui::Visuals::light()); | |
| 28 | 추가: cc.egui_ctx.style_mut_of(egui::Theme::Light, |style| { | |
| 29 | 추가: style | |
| 30 | 추가: .text_styles | |
| 31 | 추가: .insert(TextStyle::Body, FontId::proportional(18.0)); | |
| 32 | 추가: style | |
| 33 | 추가: .text_styles | |
| 34 | 추가: .insert(TextStyle::Button, FontId::proportional(18.0)); | |
| 35 | 추가: style | |
| 36 | 추가: .text_styles | |
| 37 | 추가: .insert(TextStyle::Heading, FontId::proportional(26.0)); | |
| 38 | 추가: style.visuals.panel_fill = Color32::WHITE; | |
| 39 | 추가: style.visuals.override_text_color = Some(Color32::from_rgb(24, 39, 57)); | |
| 40 | 추가: style.visuals.selection.bg_fill = Color32::from_rgb(211, 230, 246); | |
| 41 | 추가: style.spacing.item_spacing = egui::vec2(12.0, 10.0); | |
| 42 | 추가: style.spacing.button_padding = egui::vec2(14.0, 10.0); | |
| 43 | 추가: }); | |
| 44 | 추가: let (fixture, startup) = zipelo_ui_memory_app::archive_ui::launch_args( | |
| 45 | 추가: std::env::args_os().skip(1).collect(), | |
| 46 | 추가: std::env::current_dir()?, | |
| 47 | 추가: ) | |
| 48 | 추가: .map_err(std::io::Error::other)?; | |
| 49 | 추가: let factory: Box<dyn zipelo_ui_memory_app::archive_ui::Factory> = if fixture { | |
| 50 | 추가: #[cfg(feature = "ui-fixture")] | |
| 51 | 추가: { | |
| 52 | 추가: Box::new(fake::FakeFactory::default()) | |
| 53 | 추가: } | |
| 54 | 추가: #[cfg(not(feature = "ui-fixture"))] | |
| 55 | 추가: { | |
| 56 | 추가: return Err(Box::new(std::io::Error::other( | |
| 57 | 추가: "ui-fixture feature가 필요합니다", | |
| 58 | 추가: ))); | |
| 59 | 추가: } | |
| 60 | 추가: } else { | |
| 61 | 추가: Box::new( | |
| 62 | 추가: zipelo_ui_memory_app::archive_process::ProcessFactory::sibling() | |
| 63 | 추가: .map_err(std::io::Error::other)?, | |
| 64 | 추가: ) | |
| 65 | 추가: }; | |
| 66 | 추가: Ok(Box::new( | |
| 67 | 추가: zipelo_ui_memory_app::archive_screen::ArchiveApp::new(factory, startup, fixture), | |
| 68 | 추가: )) | |
| 69 | 추가: }), | |
| 70 | 추가: ) | |
| 71 | 추가: } |
| @@ -4,3 +4,10 @@ pub use core_memory as core; | ||
| 4 | 4 | pub mod controller; |
| 5 | 5 | pub mod runtime; |
| 6 | 6 | pub mod transport; |
| 7 | 추가: | |
| 8 | 추가: pub mod archive_ui; | |
| 9 | 추가: | |
| 10 | 추가: #[cfg(feature = "ui")] | |
| 11 | 추가: pub mod archive_screen; | |
| 12 | 추가: | |
| 13 | 추가: pub mod archive_process; |
| @@ -0,0 +1 @@ | ||
| 1 | 추가: runs/ |
| @@ -0,0 +1,107 @@ | ||
| 1 | 추가: # This file is automatically @generated by Cargo. | |
| 2 | 추가: # It is not intended for manual editing. | |
| 3 | 추가: version = 4 | |
| 4 | 추가: | |
| 5 | 추가: [[package]] | |
| 6 | 추가: name = "block-buffer" | |
| 7 | 추가: version = "0.10.4" | |
| 8 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | 추가: checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | |
| 10 | 추가: dependencies = [ | |
| 11 | 추가: "generic-array", | |
| 12 | 추가: ] | |
| 13 | 추가: | |
| 14 | 추가: [[package]] | |
| 15 | 추가: name = "cfg-if" | |
| 16 | 추가: version = "1.0.5" | |
| 17 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 18 | 추가: checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" | |
| 19 | 추가: | |
| 20 | 추가: [[package]] | |
| 21 | 추가: name = "cpufeatures" | |
| 22 | 추가: version = "0.2.17" | |
| 23 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 24 | 추가: checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" | |
| 25 | 추가: dependencies = [ | |
| 26 | 추가: "libc", | |
| 27 | 추가: ] | |
| 28 | 추가: | |
| 29 | 추가: [[package]] | |
| 30 | 추가: name = "crypto-common" | |
| 31 | 추가: version = "0.1.7" | |
| 32 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 33 | 추가: checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" | |
| 34 | 추가: dependencies = [ | |
| 35 | 추가: "generic-array", | |
| 36 | 추가: "typenum", | |
| 37 | 추가: ] | |
| 38 | 추가: | |
| 39 | 추가: [[package]] | |
| 40 | 추가: name = "digest" | |
| 41 | 추가: version = "0.10.7" | |
| 42 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 43 | 추가: checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | |
| 44 | 추가: dependencies = [ | |
| 45 | 추가: "block-buffer", | |
| 46 | 추가: "crypto-common", | |
| 47 | 추가: ] | |
| 48 | 추가: | |
| 49 | 추가: [[package]] | |
| 50 | 추가: name = "generic-array" | |
| 51 | 추가: version = "0.14.7" | |
| 52 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 53 | 추가: checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | |
| 54 | 추가: dependencies = [ | |
| 55 | 추가: "typenum", | |
| 56 | 추가: "version_check", | |
| 57 | 추가: ] | |
| 58 | 추가: | |
| 59 | 추가: [[package]] | |
| 60 | 추가: name = "libc" | |
| 61 | 추가: version = "0.2.191" | |
| 62 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 63 | 추가: checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" | |
| 64 | 추가: | |
| 65 | 추가: [[package]] | |
| 66 | 추가: name = "sha2" | |
| 67 | 추가: version = "0.10.9" | |
| 68 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 69 | 추가: checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" | |
| 70 | 추가: dependencies = [ | |
| 71 | 추가: "cfg-if", | |
| 72 | 추가: "cpufeatures", | |
| 73 | 추가: "digest", | |
| 74 | 추가: ] | |
| 75 | 추가: | |
| 76 | 추가: [[package]] | |
| 77 | 추가: name = "typenum" | |
| 78 | 추가: version = "1.20.1" | |
| 79 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 80 | 추가: checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | |
| 81 | 추가: | |
| 82 | 추가: [[package]] | |
| 83 | 추가: name = "version_check" | |
| 84 | 추가: version = "0.9.5" | |
| 85 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 86 | 추가: checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | |
| 87 | 추가: | |
| 88 | 추가: [[package]] | |
| 89 | 추가: name = "zipelo-archive-worker" | |
| 90 | 추가: version = "0.1.0" | |
| 91 | 추가: dependencies = [ | |
| 92 | 추가: "sha2", | |
| 93 | 추가: "zlib-rs", | |
| 94 | 추가: ] | |
| 95 | 추가: | |
| 96 | 추가: [[package]] | |
| 97 | 추가: name = "zipelo-real-worker-probe" | |
| 98 | 추가: version = "0.1.0" | |
| 99 | 추가: dependencies = [ | |
| 100 | 추가: "zipelo-archive-worker", | |
| 101 | 추가: ] | |
| 102 | 추가: | |
| 103 | 추가: [[package]] | |
| 104 | 추가: name = "zlib-rs" | |
| 105 | 추가: version = "0.6.8" | |
| 106 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 107 | 추가: checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" |
| @@ -0,0 +1,19 @@ | ||
| 1 | 추가: [package] | |
| 2 | 추가: name = "zipelo-real-worker-probe" | |
| 3 | 추가: version = "0.1.0" | |
| 4 | 추가: edition = "2024" | |
| 5 | 추가: rust-version = "1.99" | |
| 6 | 추가: license = "MIT" | |
| 7 | 추가: publish = false | |
| 8 | 추가: autotests = false | |
| 9 | 추가: | |
| 10 | 추가: [workspace] | |
| 11 | 추가: | |
| 12 | 추가: [dependencies] | |
| 13 | 추가: worker_protocol = { package = "zipelo-archive-worker", path = "../../experiments/rust-archive-worker" } | |
| 14 | 추가: | |
| 15 | 추가: [[bin]] | |
| 16 | 추가: name = "zipelo-real-worker-probe" | |
| 17 | 추가: path = "probe.rs" | |
| 18 | 추가: test = false | |
| 19 | 추가: bench = false |
| @@ -0,0 +1,50 @@ | ||
| 1 | 추가: # 실제 작업자와 화면 연결 시험 | |
| 2 | 추가: | |
| 3 | 추가: 기본 앱은 실행 파일과 같은 폴더의 zipelo-archive-worker(Windows는 .exe)를 실행함. | |
| 4 | 추가: PATH나 현재 작업 폴더에서 임의 작업자를 검색하지 않음. ui-fixture와 --ui-fixture가 | |
| 5 | 추가: 모두 지정된 경우에만 기존 가짜 작업자를 사용함. | |
| 6 | 추가: | |
| 7 | 추가: 클라이언트는 작업자 crate의 protocol과 wire codec을 재사용하며 압축 처리와 파일 접근은 | |
| 8 | 추가: 별도 작업자 프로세스에서 수행함. UI에서 파이프 쓰기를 기다리지 않도록 8프레임 요청 큐와 | |
| 9 | 추가: 64이벤트 응답 큐를 사용함. 파이프 입출력과 child wait는 백그라운드에서 처리함. | |
| 10 | 추가: 정상 종료에는 Terminal, 양쪽 EOF와 child wait를 모두 확인함. 통신 오류는 성공으로 | |
| 11 | 추가: 표시하지 않으며, 오류 경로에서는 child 회수와 모든 파이프 스레드/핸들 정리가 끝났다는 | |
| 12 | 추가: 명시적 완료 신호까지 확인함. 연결이 예외적으로 폐기돼도 소유한 자식을 종료하고 회수함. | |
| 13 | 추가: 310초 제한 시간을 넘긴 작업자도 종료와 회수를 시도하며 완료 여부가 불명확하면 닫기를 허용하지 않음. | |
| 14 | 추가: | |
| 15 | 추가: ## 실행 | |
| 16 | 추가: | |
| 17 | 추가: 저장소 루트에서 로컬 실행기를 사용하면 실제 작업자와 probe 빌드가 화면 시험보다 먼저 수행됨. | |
| 18 | 추가: | |
| 19 | 추가: ```sh | |
| 20 | 추가: python3 tests/ci/run_rust.py local | |
| 21 | 추가: ``` | |
| 22 | 추가: | |
| 23 | 추가: 단독 시험에서는 같은 target 디렉터리에 먼저 두 실행 파일을 빌드할 것. | |
| 24 | 추가: | |
| 25 | 추가: ```sh | |
| 26 | 추가: export CARGO_TARGET_DIR="$PWD/tests/ci/target" | |
| 27 | 추가: cargo +1.99.1 build --locked --manifest-path experiments/rust-archive-worker/Cargo.toml | |
| 28 | 추가: cargo +1.99.1 build --locked --manifest-path tests/rust-app-real-worker/Cargo.toml | |
| 29 | 추가: cargo +1.99.1 test --locked --all-features --manifest-path experiments/rust-ui-memory-app/Cargo.toml --test real_worker | |
| 30 | 추가: ``` | |
| 31 | 추가: | |
| 32 | 추가: 기본 앱의 직접 실행도 같은 target 디렉터리를 사용할 것. | |
| 33 | 추가: | |
| 34 | 추가: ```sh | |
| 35 | 추가: cargo +1.99.1 run --locked --manifest-path experiments/rust-ui-memory-app/Cargo.toml --features ui -- /absolute/sample.zip | |
| 36 | 추가: ``` | |
| 37 | 추가: | |
| 38 | 추가: ## 확인 범위 | |
| 39 | 추가: | |
| 40 | 추가: - 합성 ZIP과 TAR.GZ를 실제 파일 열기 위젯으로 열고 목록을 확인한 뒤 풀기 버튼으로 해제함. | |
| 41 | 추가: - ZIP 만들기 위젯으로 합성 파일을 압축하고, 결과를 다시 열고 풀어 바이트가 같은지 확인함. | |
| 42 | 추가: - 위 세 흐름은 실제 작업자 EXE와 OS 파이프를 사용하며 Terminal, 양쪽 EOF, child wait와 연결 정리 순서를 관측함. | |
| 43 | 추가: - 누락된 작업자, 잘린 프레임, 잘못된 action 승인, Terminal 없는 조기 종료를 오류로 처리함. | |
| 44 | 추가: - 첫 Start 직렬화 실패도 실제 작업자 회수까지 대기함. Linux에서는 실행 중인 probe 연결을 폐기한 후 /proc에서 소유 자식이 사라진 것도 확인함. | |
| 45 | 추가: - flows.rs의 창은 egui Context에서 실제 위젯에 포인터와 키보드 이벤트를 전달함. 네이티브 OS 창/입력 자동화나 Windows 실행 검증은 아님. | |
| 46 | 추가: | |
| 47 | 추가: fixtures/는 generate.py의 Python 표준 라이브러리로 생성한 작은 합성 입력임. | |
| 48 | 추가: 정상 흐름은 제품 작업자를 사용하고, probe.rs는 통신 실패와 생명주기 시험 전용임. | |
| 49 | 추가: 사용자 자료를 읽거나 출력하지 않으며 모든 시험 출력은 이 폴더의 runs/ 안에만 생성함. | |
| 50 | 추가: 암호 ZIP, 대용량 성능, OS sandbox, 악성 파일 전체 검증과 Windows 실기는 이 시험의 범위 밖임. |
바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기| @@ -0,0 +1,471 @@ | ||
| 1 | 추가: use std::{ | |
| 2 | 추가: cell::RefCell, | |
| 3 | 추가: fs, | |
| 4 | 추가: path::{Path, PathBuf}, | |
| 5 | 추가: rc::Rc, | |
| 6 | 추가: sync::atomic::{AtomicU64, Ordering}, | |
| 7 | 추가: time::{Duration, Instant}, | |
| 8 | 추가: }; | |
| 9 | 추가: use zipelo_ui_memory_app::{archive_process::ProcessFactory, archive_ui::*}; | |
| 10 | 추가: static NEXT: AtomicU64 = AtomicU64::new(0); | |
| 11 | 추가: struct Scratch(PathBuf); | |
| 12 | 추가: impl Scratch { | |
| 13 | 추가: fn new() -> Self { | |
| 14 | 추가: let root = | |
| 15 | 추가: Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/rust-app-real-worker/runs"); | |
| 16 | 추가: fs::create_dir_all(&root).unwrap(); | |
| 17 | 추가: let path = root.join(format!( | |
| 18 | 추가: "{}-{}", | |
| 19 | 추가: std::process::id(), | |
| 20 | 추가: NEXT.fetch_add(1, Ordering::Relaxed) | |
| 21 | 추가: )); | |
| 22 | 추가: Self(make_directory(&path)) | |
| 23 | 추가: } | |
| 24 | 추가: fn path(&self, name: &str) -> PathBuf { | |
| 25 | 추가: self.0.join(name) | |
| 26 | 추가: } | |
| 27 | 추가: } | |
| 28 | 추가: impl Drop for Scratch { | |
| 29 | 추가: fn drop(&mut self) { | |
| 30 | 추가: fs::remove_dir_all(&self.0).unwrap(); | |
| 31 | 추가: } | |
| 32 | 추가: } | |
| 33 | 추가: fn make_directory(path: &Path) -> PathBuf { | |
| 34 | 추가: let mut builder = fs::DirBuilder::new(); | |
| 35 | 추가: #[cfg(unix)] | |
| 36 | 추가: { | |
| 37 | 추가: use std::os::unix::fs::DirBuilderExt; | |
| 38 | 추가: builder.mode(0o700); | |
| 39 | 추가: } | |
| 40 | 추가: builder.create(path).unwrap(); | |
| 41 | 추가: path.canonicalize().unwrap() | |
| 42 | 추가: } | |
| 43 | 추가: fn binary(name: &str) -> PathBuf { | |
| 44 | 추가: let current = std::env::current_exe().unwrap(); | |
| 45 | 추가: let path = current | |
| 46 | 추가: .parent() | |
| 47 | 추가: .unwrap() | |
| 48 | 추가: .parent() | |
| 49 | 추가: .unwrap() | |
| 50 | 추가: .join(format!("{name}{}", std::env::consts::EXE_SUFFIX)); | |
| 51 | 추가: assert!( | |
| 52 | 추가: path.is_file(), | |
| 53 | 추가: "실제 작업자와 시험 probe를 먼저 빌드해야 함: {}", | |
| 54 | 추가: path.display() | |
| 55 | 추가: ); | |
| 56 | 추가: path | |
| 57 | 추가: } | |
| 58 | 추가: #[derive(Default)] | |
| 59 | 추가: struct Observation { | |
| 60 | 추가: jobs: Vec<Vec<&'static str>>, | |
| 61 | 추가: } | |
| 62 | 추가: struct ObservedFactory { | |
| 63 | 추가: process: ProcessFactory, | |
| 64 | 추가: observed: Rc<RefCell<Observation>>, | |
| 65 | 추가: } | |
| 66 | 추가: struct ObservedConnection { | |
| 67 | 추가: connection: Box<dyn Connection>, | |
| 68 | 추가: index: usize, | |
| 69 | 추가: observed: Rc<RefCell<Observation>>, | |
| 70 | 추가: } | |
| 71 | 추가: impl Factory for ObservedFactory { | |
| 72 | 추가: fn connect(&mut self, job: u64) -> Result<Box<dyn Connection>, String> { | |
| 73 | 추가: let connection = self.process.connect(job)?; | |
| 74 | 추가: let index = self.observed.borrow().jobs.len(); | |
| 75 | 추가: self.observed.borrow_mut().jobs.push(Vec::new()); | |
| 76 | 추가: Ok(Box::new(ObservedConnection { | |
| 77 | 추가: connection, | |
| 78 | 추가: index, | |
| 79 | 추가: observed: self.observed.clone(), | |
| 80 | 추가: })) | |
| 81 | 추가: } | |
| 82 | 추가: } | |
| 83 | 추가: impl Connection for ObservedConnection { | |
| 84 | 추가: fn send(&mut self, request: Request) -> Result<(), String> { | |
| 85 | 추가: self.connection.send(request) | |
| 86 | 추가: } | |
| 87 | 추가: fn poll(&mut self) -> Option<HostEvent> { | |
| 88 | 추가: let event = self.connection.poll()?; | |
| 89 | 추가: let label = match &event { | |
| 90 | 추가: HostEvent::StdoutEof => "stdout", | |
| 91 | 추가: HostEvent::StderrEof => "stderr", | |
| 92 | 추가: HostEvent::Exited { .. } => "wait", | |
| 93 | 추가: HostEvent::CleanupComplete => "cleanup", | |
| 94 | 추가: HostEvent::Fault(_) => "fault", | |
| 95 | 추가: HostEvent::Frame { | |
| 96 | 추가: event: Event::Terminal(_), | |
| 97 | 추가: .. | |
| 98 | 추가: } => "terminal", | |
| 99 | 추가: _ => "frame", | |
| 100 | 추가: }; | |
| 101 | 추가: self.observed.borrow_mut().jobs[self.index].push(label); | |
| 102 | 추가: Some(event) | |
| 103 | 추가: } | |
| 104 | 추가: } | |
| 105 | 추가: impl Drop for ObservedConnection { | |
| 106 | 추가: fn drop(&mut self) { | |
| 107 | 추가: self.observed.borrow_mut().jobs[self.index].push("drop"); | |
| 108 | 추가: } | |
| 109 | 추가: } | |
| 110 | 추가: fn observed_factory() -> (ObservedFactory, Rc<RefCell<Observation>>) { | |
| 111 | 추가: let observed = Rc::new(RefCell::new(Observation::default())); | |
| 112 | 추가: ( | |
| 113 | 추가: ObservedFactory { | |
| 114 | 추가: process: ProcessFactory::new(binary("zipelo-archive-worker")), | |
| 115 | 추가: observed: observed.clone(), | |
| 116 | 추가: }, | |
| 117 | 추가: observed, | |
| 118 | 추가: ) | |
| 119 | 추가: } | |
| 120 | 추가: fn assert_reaped(observed: &Rc<RefCell<Observation>>) { | |
| 121 | 추가: for events in &observed.borrow().jobs { | |
| 122 | 추가: for label in ["terminal", "stdout", "stderr", "cleanup", "wait", "drop"] { | |
| 123 | 추가: assert_eq!( | |
| 124 | 추가: events.iter().filter(|value| **value == label).count(), | |
| 125 | 추가: 1, | |
| 126 | 추가: "{events:?}" | |
| 127 | 추가: ); | |
| 128 | 추가: } | |
| 129 | 추가: assert!(!events.contains(&"fault")); | |
| 130 | 추가: assert_eq!(&events[events.len() - 2..], &["wait", "drop"]); | |
| 131 | 추가: } | |
| 132 | 추가: } | |
| 133 | 추가: fn wait(model: &mut Model) { | |
| 134 | 추가: let deadline = Instant::now() + Duration::from_secs(10); | |
| 135 | 추가: while model.busy() { | |
| 136 | 추가: model.poll(); | |
| 137 | 추가: assert!( | |
| 138 | 추가: Instant::now() < deadline, | |
| 139 | 추가: "작업자 종료 시간 초과: {}", | |
| 140 | 추가: model.status() | |
| 141 | 추가: ); | |
| 142 | 추가: std::thread::sleep(Duration::from_millis(2)); | |
| 143 | 추가: } | |
| 144 | 추가: } | |
| 145 | 추가: fn completed(model: &Model) { | |
| 146 | 추가: assert!(model.confirmed, "{}", model.status()); | |
| 147 | 추가: assert_eq!(model.terminal.as_ref().unwrap().outcome, Outcome::Completed); | |
| 148 | 추가: } | |
| 149 | 추가: #[cfg(feature = "ui")] | |
| 150 | 추가: mod screen { | |
| 151 | 추가: use super::*; | |
| 152 | 추가: use eframe::egui::{self, epaint::Shape}; | |
| 153 | 추가: use zipelo_ui_memory_app::archive_screen::ArchiveApp; | |
| 154 | 추가: struct Screen { | |
| 155 | 추가: context: egui::Context, | |
| 156 | 추가: app: ArchiveApp, | |
| 157 | 추가: } | |
| 158 | 추가: impl Screen { | |
| 159 | 추가: fn new(factory: ObservedFactory) -> Self { | |
| 160 | 추가: Self { | |
| 161 | 추가: context: egui::Context::default(), | |
| 162 | 추가: app: ArchiveApp::new(Box::new(factory), None, false), | |
| 163 | 추가: } | |
| 164 | 추가: } | |
| 165 | 추가: fn render(&mut self, events: Vec<egui::Event>) -> Vec<(String, egui::Pos2)> { | |
| 166 | 추가: fn text(shape: &Shape, output: &mut Vec<(String, egui::Pos2)>) { | |
| 167 | 추가: match shape { | |
| 168 | 추가: Shape::Text(value) => output.push(( | |
| 169 | 추가: value.galley.job.text.clone(), | |
| 170 | 추가: value.pos + value.galley.rect.size() / 2.0, | |
| 171 | 추가: )), | |
| 172 | 추가: Shape::Vec(values) => { | |
| 173 | 추가: for value in values { | |
| 174 | 추가: text(value, output); | |
| 175 | 추가: } | |
| 176 | 추가: } | |
| 177 | 추가: _ => {} | |
| 178 | 추가: } | |
| 179 | 추가: } | |
| 180 | 추가: let mut frame = self.context.run_ui( | |
| 181 | 추가: egui::RawInput { | |
| 182 | 추가: screen_rect: Some(egui::Rect::from_min_size( | |
| 183 | 추가: egui::Pos2::ZERO, | |
| 184 | 추가: egui::vec2(1060.0, 720.0), | |
| 185 | 추가: )), | |
| 186 | 추가: events, | |
| 187 | 추가: ..Default::default() | |
| 188 | 추가: }, | |
| 189 | 추가: |ui| self.app.show(ui), | |
| 190 | 추가: ); | |
| 191 | 추가: frame.textures_delta.clear(); | |
| 192 | 추가: let mut output = Vec::new(); | |
| 193 | 추가: for shape in frame.shapes { | |
| 194 | 추가: text(&shape.shape, &mut output); | |
| 195 | 추가: } | |
| 196 | 추가: output | |
| 197 | 추가: } | |
| 198 | 추가: fn locate(&mut self, label: &str) -> egui::Pos2 { | |
| 199 | 추가: self.render(vec![]); | |
| 200 | 추가: self.render(vec![]) | |
| 201 | 추가: .into_iter() | |
| 202 | 추가: .filter(|(text, _)| text == label) | |
| 203 | 추가: .max_by(|a, b| a.1.y.total_cmp(&b.1.y)) | |
| 204 | 추가: .unwrap_or_else(|| panic!("화면 항목 누락: {label}")) | |
| 205 | 추가: .1 | |
| 206 | 추가: } | |
| 207 | 추가: fn click_at(&mut self, point: egui::Pos2) { | |
| 208 | 추가: self.render(vec![ | |
| 209 | 추가: egui::Event::PointerMoved(point), | |
| 210 | 추가: egui::Event::PointerButton { | |
| 211 | 추가: pos: point, | |
| 212 | 추가: button: egui::PointerButton::Primary, | |
| 213 | 추가: pressed: true, | |
| 214 | 추가: modifiers: Default::default(), | |
| 215 | 추가: }, | |
| 216 | 추가: ]); | |
| 217 | 추가: self.render(vec![egui::Event::PointerButton { | |
| 218 | 추가: pos: point, | |
| 219 | 추가: button: egui::PointerButton::Primary, | |
| 220 | 추가: pressed: false, | |
| 221 | 추가: modifiers: Default::default(), | |
| 222 | 추가: }]); | |
| 223 | 추가: } | |
| 224 | 추가: fn click(&mut self, label: &str) { | |
| 225 | 추가: let point = self.locate(label); | |
| 226 | 추가: self.click_at(point); | |
| 227 | 추가: } | |
| 228 | 추가: fn fill(&mut self, label: &str, offset: egui::Vec2, value: &Path) { | |
| 229 | 추가: let point = self.locate(label) + offset; | |
| 230 | 추가: self.click_at(point); | |
| 231 | 추가: self.render(vec![ | |
| 232 | 추가: egui::Event::Key { | |
| 233 | 추가: key: egui::Key::A, | |
| 234 | 추가: physical_key: None, | |
| 235 | 추가: pressed: true, | |
| 236 | 추가: repeat: false, | |
| 237 | 추가: modifiers: egui::Modifiers::COMMAND, | |
| 238 | 추가: }, | |
| 239 | 추가: egui::Event::Text(value.to_str().unwrap().to_string()), | |
| 240 | 추가: ]); | |
| 241 | 추가: } | |
| 242 | 추가: fn settle(&mut self) { | |
| 243 | 추가: let deadline = Instant::now() + Duration::from_secs(10); | |
| 244 | 추가: while self.app.model.busy() { | |
| 245 | 추가: self.render(vec![]); | |
| 246 | 추가: assert!(Instant::now() < deadline, "{}", self.app.model.status()); | |
| 247 | 추가: std::thread::sleep(Duration::from_millis(2)); | |
| 248 | 추가: } | |
| 249 | 추가: completed(&self.app.model); | |
| 250 | 추가: } | |
| 251 | 추가: fn open(&mut self, archive: &Path) { | |
| 252 | 추가: self.click("파일 열기"); | |
| 253 | 추가: self.fill("압축파일 절대 경로", egui::vec2(0.0, 22.0), archive); | |
| 254 | 추가: self.click("열기"); | |
| 255 | 추가: assert!(self.app.model.busy()); | |
| 256 | 추가: self.settle(); | |
| 257 | 추가: } | |
| 258 | 추가: fn extract(&mut self, destination: &Path) { | |
| 259 | 추가: self.fill("출력 폴더", egui::vec2(100.0, 0.0), destination); | |
| 260 | 추가: self.click("풀기"); | |
| 261 | 추가: assert!(self.app.model.busy()); | |
| 262 | 추가: self.settle(); | |
| 263 | 추가: assert_eq!( | |
| 264 | 추가: self.app.model.terminal.as_ref().unwrap().publication, | |
| 265 | 추가: Publication::Complete | |
| 266 | 추가: ); | |
| 267 | 추가: } | |
| 268 | 추가: } | |
| 269 | 추가: fn archive_flow(name: &str, format: Format) { | |
| 270 | 추가: let scratch = Scratch::new(); | |
| 271 | 추가: let fixture = Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 272 | 추가: .join("../../tests/rust-app-real-worker/fixtures") | |
| 273 | 추가: .join(name); | |
| 274 | 추가: let archive = scratch.path(name); | |
| 275 | 추가: fs::copy(fixture, &archive).unwrap(); | |
| 276 | 추가: let original = fs::read(&archive).unwrap(); | |
| 277 | 추가: let output = make_directory(&scratch.path("output")); | |
| 278 | 추가: let (factory, observed) = observed_factory(); | |
| 279 | 추가: let mut screen = Screen::new(factory); | |
| 280 | 추가: screen.open(&archive); | |
| 281 | 추가: assert_eq!(screen.app.model.list_id.as_ref().unwrap().format, format); | |
| 282 | 추가: assert_eq!(screen.app.model.entries[0].name, "content.txt"); | |
| 283 | 추가: screen.extract(&output); | |
| 284 | 추가: assert_eq!( | |
| 285 | 추가: fs::read(output.join("content.txt")).unwrap(), | |
| 286 | 추가: b"Zipelo real worker flow\n" | |
| 287 | 추가: ); | |
| 288 | 추가: assert_eq!(fs::read(archive).unwrap(), original); | |
| 289 | 추가: assert_eq!(observed.borrow().jobs.len(), 2); | |
| 290 | 추가: assert_reaped(&observed); | |
| 291 | 추가: } | |
| 292 | 추가: #[test] | |
| 293 | 추가: fn zip_open_and_extract_via_actual_widgets_and_worker() { | |
| 294 | 추가: archive_flow("sample.zip", Format::Zip); | |
| 295 | 추가: } | |
| 296 | 추가: #[test] | |
| 297 | 추가: fn targz_open_and_extract_via_actual_widgets_and_worker() { | |
| 298 | 추가: archive_flow("sample.tar.gz", Format::TarGzip); | |
| 299 | 추가: } | |
| 300 | 추가: #[test] | |
| 301 | 추가: fn create_zip_reopen_and_extract_via_actual_widgets_and_worker() { | |
| 302 | 추가: let scratch = Scratch::new(); | |
| 303 | 추가: let source = scratch.path("one.txt"); | |
| 304 | 추가: fs::write(&source, b"ZIP creation through real worker\n").unwrap(); | |
| 305 | 추가: let archive = scratch.path("new.zip"); | |
| 306 | 추가: let output = make_directory(&scratch.path("output")); | |
| 307 | 추가: let (factory, observed) = observed_factory(); | |
| 308 | 추가: let mut screen = Screen::new(factory); | |
| 309 | 추가: screen.click("ZIP 만들기"); | |
| 310 | 추가: screen.fill( | |
| 311 | 추가: "원본 파일 절대 경로 / 한 줄에 하나", | |
| 312 | 추가: egui::vec2(0.0, 25.0), | |
| 313 | 추가: &source, | |
| 314 | 추가: ); | |
| 315 | 추가: screen.fill("저장할 ZIP 절대 경로", egui::vec2(0.0, 22.0), &archive); | |
| 316 | 추가: screen.click("ZIP 만들기"); | |
| 317 | 추가: assert!(screen.app.model.busy()); | |
| 318 | 추가: screen.settle(); | |
| 319 | 추가: assert!(archive.is_file()); | |
| 320 | 추가: screen.open(&archive); | |
| 321 | 추가: assert_eq!(screen.app.model.entries[0].name, "one.txt"); | |
| 322 | 추가: screen.extract(&output); | |
| 323 | 추가: assert_eq!( | |
| 324 | 추가: fs::read(output.join("one.txt")).unwrap(), | |
| 325 | 추가: fs::read(source).unwrap() | |
| 326 | 추가: ); | |
| 327 | 추가: assert_eq!(observed.borrow().jobs.len(), 3); | |
| 328 | 추가: assert_reaped(&observed); | |
| 329 | 추가: } | |
| 330 | 추가: } | |
| 331 | 추가: #[test] | |
| 332 | 추가: fn missing_worker_is_an_error_without_a_fake_result() { | |
| 333 | 추가: let scratch = Scratch::new(); | |
| 334 | 추가: let mut factory = ProcessFactory::new(scratch.path("not-installed")); | |
| 335 | 추가: let mut model = Model::default(); | |
| 336 | 추가: assert!(!model.begin( | |
| 337 | 추가: Start::List { | |
| 338 | 추가: archive: scratch.path("sample.zip") | |
| 339 | 추가: }, | |
| 340 | 추가: &mut factory | |
| 341 | 추가: )); | |
| 342 | 추가: assert!(!model.busy()); | |
| 343 | 추가: assert!(model.error.is_some()); | |
| 344 | 추가: assert!(!model.confirmed); | |
| 345 | 추가: } | |
| 346 | 추가: #[test] | |
| 347 | 추가: fn broken_or_incomplete_worker_output_is_not_success() { | |
| 348 | 추가: for name in ["truncated", "wrong-action", "early-exit"] { | |
| 349 | 추가: let scratch = Scratch::new(); | |
| 350 | 추가: let probe = scratch.path(&format!("{name}{}", std::env::consts::EXE_SUFFIX)); | |
| 351 | 추가: fs::copy(binary("zipelo-real-worker-probe"), &probe).unwrap(); | |
| 352 | 추가: let mut factory = ProcessFactory::new(probe); | |
| 353 | 추가: let mut model = Model::default(); | |
| 354 | 추가: assert!(model.begin( | |
| 355 | 추가: Start::List { | |
| 356 | 추가: archive: scratch.path("sample.zip") | |
| 357 | 추가: }, | |
| 358 | 추가: &mut factory | |
| 359 | 추가: )); | |
| 360 | 추가: model.request_close(); | |
| 361 | 추가: model.confirm_close(); | |
| 362 | 추가: assert_eq!(model.close, Close::Waiting); | |
| 363 | 추가: wait(&mut model); | |
| 364 | 추가: assert!(!model.confirmed); | |
| 365 | 추가: assert!(model.error.is_some()); | |
| 366 | 추가: assert_eq!(model.close, Close::Review); | |
| 367 | 추가: model.acknowledge_close(); | |
| 368 | 추가: assert_eq!(model.close, Close::Allowed); | |
| 369 | 추가: } | |
| 370 | 추가: } | |
| 371 | 추가: #[cfg(target_os = "linux")] | |
| 372 | 추가: #[test] | |
| 373 | 추가: fn dropping_live_connection_kills_and_reaps_owned_child() { | |
| 374 | 추가: let scratch = Scratch::new(); | |
| 375 | 추가: let probe = scratch.path("hang"); | |
| 376 | 추가: fs::copy(binary("zipelo-real-worker-probe"), &probe).unwrap(); | |
| 377 | 추가: let mut factory = ProcessFactory::new(probe); | |
| 378 | 추가: let mut model = Model::default(); | |
| 379 | 추가: assert!(model.begin( | |
| 380 | 추가: Start::List { | |
| 381 | 추가: archive: scratch.path("sample.zip") | |
| 382 | 추가: }, | |
| 383 | 추가: &mut factory | |
| 384 | 추가: )); | |
| 385 | 추가: let deadline = Instant::now() + Duration::from_secs(5); | |
| 386 | 추가: while !scratch.path("probe.pid").exists() { | |
| 387 | 추가: assert!(Instant::now() < deadline); | |
| 388 | 추가: std::thread::sleep(Duration::from_millis(2)); | |
| 389 | 추가: } | |
| 390 | 추가: let pid = fs::read_to_string(scratch.path("probe.pid")).unwrap(); | |
| 391 | 추가: drop(model); | |
| 392 | 추가: assert!(!Path::new("/proc").join(pid).exists()); | |
| 393 | 추가: } | |
| 394 | 추가: | |
| 395 | 추가: #[test] | |
| 396 | 추가: fn failed_start_serialization_reaps_the_real_worker_without_terminal() { | |
| 397 | 추가: let scratch = Scratch::new(); | |
| 398 | 추가: let mut factory = ProcessFactory::new(binary("zipelo-archive-worker")); | |
| 399 | 추가: let mut model = Model::default(); | |
| 400 | 추가: let archive = scratch.path(&"a".repeat(40000)); | |
| 401 | 추가: assert!(!model.begin(Start::List { archive }, &mut factory)); | |
| 402 | 추가: assert!(model.busy()); | |
| 403 | 추가: model.request_close(); | |
| 404 | 추가: model.confirm_close(); | |
| 405 | 추가: assert_eq!(model.close, Close::Waiting); | |
| 406 | 추가: wait(&mut model); | |
| 407 | 추가: assert!(!model.confirmed); | |
| 408 | 추가: assert!(model.terminal.is_none()); | |
| 409 | 추가: assert!(model.error.is_some()); | |
| 410 | 추가: assert_eq!(model.close, Close::Review); | |
| 411 | 추가: } | |
| 412 | 추가: | |
| 413 | 추가: #[test] | |
| 414 | 추가: fn late_cancel_after_child_reap_keeps_the_original_terminal_result() { | |
| 415 | 추가: let scratch = Scratch::new(); | |
| 416 | 추가: let archive = scratch.path("sample.zip"); | |
| 417 | 추가: fs::copy( | |
| 418 | 추가: Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 419 | 추가: .join("../../tests/rust-app-real-worker/fixtures/sample.zip"), | |
| 420 | 추가: &archive, | |
| 421 | 추가: ) | |
| 422 | 추가: .unwrap(); | |
| 423 | 추가: let mut factory = ProcessFactory::new(binary("zipelo-archive-worker")); | |
| 424 | 추가: let mut connection = factory.connect(1).unwrap(); | |
| 425 | 추가: connection | |
| 426 | 추가: .send(Request { | |
| 427 | 추가: job_id: 1, | |
| 428 | 추가: sequence: 0, | |
| 429 | 추가: command: Command::Start(Start::List { archive }), | |
| 430 | 추가: }) | |
| 431 | 추가: .unwrap(); | |
| 432 | 추가: let deadline = Instant::now() + Duration::from_secs(10); | |
| 433 | 추가: let mut terminal = false; | |
| 434 | 추가: loop { | |
| 435 | 추가: assert!(Instant::now() < deadline); | |
| 436 | 추가: match connection.poll() { | |
| 437 | 추가: Some(HostEvent::CleanupComplete) => break, | |
| 438 | 추가: Some(HostEvent::Frame { | |
| 439 | 추가: event: Event::Terminal(value), | |
| 440 | 추가: .. | |
| 441 | 추가: }) => { | |
| 442 | 추가: assert_eq!(value.outcome, Outcome::Completed); | |
| 443 | 추가: terminal = true; | |
| 444 | 추가: } | |
| 445 | 추가: Some(HostEvent::Fault(message)) => panic!("{message}"), | |
| 446 | 추가: _ => std::thread::sleep(Duration::from_millis(1)), | |
| 447 | 추가: } | |
| 448 | 추가: } | |
| 449 | 추가: assert!(terminal); | |
| 450 | 추가: assert!( | |
| 451 | 추가: connection | |
| 452 | 추가: .send(Request { | |
| 453 | 추가: job_id: 1, | |
| 454 | 추가: sequence: 1, | |
| 455 | 추가: command: Command::Cancel | |
| 456 | 추가: }) | |
| 457 | 추가: .is_ok() | |
| 458 | 추가: ); | |
| 459 | 추가: loop { | |
| 460 | 추가: assert!(Instant::now() < deadline); | |
| 461 | 추가: match connection.poll() { | |
| 462 | 추가: Some(HostEvent::Exited { success }) => { | |
| 463 | 추가: assert!(success); | |
| 464 | 추가: break; | |
| 465 | 추가: } | |
| 466 | 추가: Some(HostEvent::Fault(message)) => panic!("{message}"), | |
| 467 | 추가: _ => std::thread::sleep(Duration::from_millis(1)), | |
| 468 | 추가: } | |
| 469 | 추가: } | |
| 470 | 추가: assert!(connection.poll().is_none()); | |
| 471 | 추가: } |
| @@ -0,0 +1,24 @@ | ||
| 1 | 추가: import gzip | |
| 2 | 추가: from io import BytesIO | |
| 3 | 추가: from pathlib import Path | |
| 4 | 추가: import tarfile | |
| 5 | 추가: import zipfile | |
| 6 | 추가: | |
| 7 | 추가: ROOT = Path(__file__).resolve().parent / "fixtures" | |
| 8 | 추가: PAYLOAD = b"Zipelo real worker flow\n" | |
| 9 | 추가: ROOT.mkdir(exist_ok=True) | |
| 10 | 추가: stream = BytesIO() | |
| 11 | 추가: with zipfile.ZipFile(stream, "w") as archive: | |
| 12 | 추가: info = zipfile.ZipInfo("content.txt", (1980, 1, 1, 0, 0, 0)) | |
| 13 | 추가: info.compress_type = zipfile.ZIP_DEFLATED | |
| 14 | 추가: archive.writestr(info, PAYLOAD) | |
| 15 | 추가: (ROOT / "sample.zip").write_bytes(stream.getvalue()) | |
| 16 | 추가: stream = BytesIO() | |
| 17 | 추가: with tarfile.open(fileobj=stream, mode="w", format=tarfile.USTAR_FORMAT) as archive: | |
| 18 | 추가: info = tarfile.TarInfo("content.txt") | |
| 19 | 추가: info.size = len(PAYLOAD) | |
| 20 | 추가: info.mode = 0o600 | |
| 21 | 추가: archive.addfile(info, BytesIO(PAYLOAD)) | |
| 22 | 추가: compressed = bytearray(gzip.compress(stream.getvalue(), mtime=0)) | |
| 23 | 추가: compressed[9] = 255 | |
| 24 | 추가: (ROOT / "sample.tar.gz").write_bytes(compressed) |
| @@ -0,0 +1,29 @@ | ||
| 1 | 추가: use std::{io::Write, path::PathBuf, time::Duration}; | |
| 2 | 추가: use worker_protocol::{ | |
| 3 | 추가: protocol::*, | |
| 4 | 추가: wire::{Reader, Writer}, | |
| 5 | 추가: }; | |
| 6 | 추가: | |
| 7 | 추가: fn main() { | |
| 8 | 추가: let executable = PathBuf::from(std::env::args_os().next().unwrap()); | |
| 9 | 추가: let mode = executable.file_stem().unwrap().to_string_lossy(); | |
| 10 | 추가: if mode.starts_with("hang") { | |
| 11 | 추가: let parent = executable.parent().unwrap(); | |
| 12 | 추가: std::fs::write(parent.join("probe.pid.tmp"), std::process::id().to_string()).unwrap(); | |
| 13 | 추가: std::fs::rename(parent.join("probe.pid.tmp"), parent.join("probe.pid")).unwrap(); | |
| 14 | 추가: std::thread::sleep(Duration::from_secs(30)); | |
| 15 | 추가: return; | |
| 16 | 추가: } | |
| 17 | 추가: let mut reader = Reader::new(std::io::stdin()); | |
| 18 | 추가: let (job, _, _) = reader.read().unwrap().unwrap(); | |
| 19 | 추가: if mode.starts_with("wrong-action") { | |
| 20 | 추가: Writer::new(std::io::stdout(), job) | |
| 21 | 추가: .send(&Message::Accepted { | |
| 22 | 추가: action: ActionKind::Extract, | |
| 23 | 추가: encryption: false, | |
| 24 | 추가: }) | |
| 25 | 추가: .unwrap(); | |
| 26 | 추가: } else if !mode.starts_with("early-exit") { | |
| 27 | 추가: std::io::stdout().write_all(b"ZAW1").unwrap(); | |
| 28 | 추가: } | |
| 29 | 추가: } |
| @@ -0,0 +1,3 @@ | ||
| 1 | 추가: screens/ | |
| 2 | 추가: screens-*/ | |
| 3 | 추가: __pycache__/ |
| @@ -0,0 +1,19 @@ | ||
| 1 | 추가: # 앱 화면 흐름 시험 | |
| 2 | 추가: | |
| 3 | 추가: 가짜 작업자는 계약 revision 2의 의미를 따르는 프론트엔드 어댑터임. 바이너리 codec, 실제 프로세스 실행, 파일 읽기와 쓰기, 암호 해독은 수행하지 않음. 실제 codec은 backend 소유이며 이 PR에서 중복 구현하지 않음. | |
| 4 | 추가: | |
| 5 | 추가: `python3 tests/ci/run_rust.py local`은 기존 시험과 새 `archive_ui` 시험을 all-features로 실행함. Windows 결과는 교차 빌드이며 Windows 실제 실행은 별도 확인해야 함. | |
| 6 | 추가: | |
| 7 | 추가: 화면 직접 확인: | |
| 8 | 추가: | |
| 9 | 추가: ```sh | |
| 10 | 추가: cargo +1.99.1 run --locked --manifest-path experiments/rust-ui-memory-app/Cargo.toml --features ui-fixture -- --ui-fixture /absolute/example.zip | |
| 11 | 추가: ``` | |
| 12 | 추가: | |
| 13 | 추가: `locked.zip` 이름은 가짜 암호 요청을 만듦. 아무 비어 있지 않은 합성 암호를 받으며 암호를 기록하거나 저장하지 않음. 실제 암호나 사용자 자료를 입력할 필요가 없음. 시험 모드는 화면에 명시되고 실제 파일을 만들지 않음. `ui-fixture` 없이 실행하면 앱과 같은 폴더의 실제 zipelo-archive-worker를 실행함. Windows에서는 .exe 확장자를 사용함. 작업자가 누락되면 오류를 표시하며 가짜 성공으로 대체하지 않음. 실제 작업자 연결 시험은 ../rust-app-real-worker/README.md를 참고할 것. | |
| 14 | 추가: | |
| 15 | 추가: 범위는 목록 확인, 선택 해제, GZ 출력명, ZIP 생성, 암호 요청, 진행률, 취소와 닫기 철회, Terminal/EOF/child wait 분리, 오래된 ID/sequence 거부, SourceChanged 재열람, 부분 출력과 불확실 게시 보존임. 구성한 이벤트 시험은 실제 OS 종료나 파일 보안 검증의 증거가 아님. | |
| 16 | 추가: | |
| 17 | 추가: 디자인은 흰 바탕 #FFFFFF, 글자 #182739, 선택 #D3E6F6, 강조 #174C7C를 사용함. 기존 한글 시스템 폰트와 본문/버튼 18px, 제목 26px를 유지함. 상단 작업 버튼, 가운데 파일 목록, 하단 진행/결과의 왼쪽 정렬 구조이며 작은 부가 설명, 장식 카드와 새 아이콘을 추가하지 않음. | |
| 18 | 추가: | |
| 19 | 추가: 풀기 버튼은 raw GZ에만 출력명을 보내며 ZIP/TAR/TAR.GZ에는 None을 보냄. 모델과 가짜 작업자도 이 계약을 검증함. Start 전송 실패 시에는 연결을 보존하고 추가 요청을 막으며, 양쪽 EOF와 child wait가 모두 올 때까지 교체와 닫기를 허용하지 않음. 이때 Terminal이 없어도 종료 후 오류 확인 화면으로 이동하며 성공으로 표시하지 않음. |
Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기