diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-15 07:17:37 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-15 07:17:37 +0200 |
commit | e209cceacac0d6ee4051d8bb3dce0ad97f2f474d (patch) | |
tree | 6f2b1fe948ac0ec515a301a1f7f27f11a66a218d /crates | |
parent | feat(crates/yt/select): Print the currently processed line as progress (diff) | |
download | yt-e209cceacac0d6ee4051d8bb3dce0ad97f2f474d.zip |
fix(crates/yt/select): Correctly open the persistent file in `select split`
Otherwise, the written changes to the persistent file would either not be saved or they would be saved but not used.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/yt/src/select/mod.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/crates/yt/src/select/mod.rs b/crates/yt/src/select/mod.rs index 76d5ae8..b39bea2 100644 --- a/crates/yt/src/select/mod.rs +++ b/crates/yt/src/select/mod.rs @@ -138,8 +138,9 @@ pub(crate) async fn select_split( paths.sort(); let mut persistent_file = OpenOptions::new() - .read(true) + .read(false) .write(true) + .create(true) .truncate(true) .open(&app.config.paths.last_selection_path) .context("Failed to open persistent selection file")?; @@ -152,7 +153,14 @@ pub(crate) async fn select_split( persistent_file.write_all(&buffer)?; } - persistent_file.rewind()?; + persistent_file.flush()?; + let persistent_file = OpenOptions::new() + .read(true) + .open(format!( + "/proc/self/fd/{}", + persistent_file.as_fd().as_raw_fd() + )) + .context("Failed to re-open persistent file")?; let processed = process_file(app, &persistent_file).await?; @@ -179,7 +187,7 @@ pub(crate) async fn select_file(app: &App, done: bool, use_last_selection: bool) open_editor_at(temp_file.path()).await?; - let read_file = temp_file.reopen()?; + let read_file = OpenOptions::new().read(true).open(temp_file.path())?; fs::copy(temp_file.path(), &app.config.paths.last_selection_path) .context("Failed to persist selection file")?; |