mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-13 20:12:45 +08:00
Fix regression causing missing automatic history saving after adding ephemeral items
Commitf36f757fa6
(Never rewrite history file when adding ephemeral items, 2024-10-06) has a glaring bug: when adding to history ephemeral items that has potential paths, we fail to re-enable automatic saving, which effectively disables automatic saving for the entire session. Only a call to history::save_all() at exit saves us from losing data. But until exit, other fish will see our history (unless we run history save/merge or similar). Fix the imbalanced enable/disable and restructure the code a bit. Also, extend the change fromf36f757fa6
(never vacuum on ephemeral items) to private mode.
This commit is contained in:
parent
064d867873
commit
acf9ba4195
|
@ -1086,7 +1086,6 @@ impl HistoryImpl {
|
|||
fn enable_automatic_saving(&mut self) {
|
||||
assert!(self.disable_automatic_save_counter > 0); // negative overflow!
|
||||
self.disable_automatic_save_counter -= 1;
|
||||
self.save_unless_disabled();
|
||||
}
|
||||
|
||||
/// Irreversibly clears history.
|
||||
|
@ -1620,7 +1619,7 @@ impl History {
|
|||
let when = imp.timestamp_now();
|
||||
let identifier = imp.next_identifier();
|
||||
let item = HistoryItem::new(s.to_owned(), when, identifier, persist_mode);
|
||||
let do_save = persist_mode != PersistenceMode::Ephemeral;
|
||||
let to_disk = persist_mode == PersistenceMode::Disk;
|
||||
|
||||
if wants_file_detection {
|
||||
imp.disable_automatic_saving();
|
||||
|
@ -1628,7 +1627,7 @@ impl History {
|
|||
// Add the item. Then check for which paths are valid on a background thread,
|
||||
// and unblock the item.
|
||||
// Don't hold the lock while we perform this file detection.
|
||||
imp.add(item, /*pending=*/ true, /*do_save=*/ true);
|
||||
imp.add(item, /*pending=*/ true, to_disk);
|
||||
drop(imp);
|
||||
let vars_snapshot = vars.snapshot();
|
||||
iothread_perform(move || {
|
||||
|
@ -1636,16 +1635,17 @@ impl History {
|
|||
let validated_paths = expand_and_detect_paths(potential_paths, &vars_snapshot);
|
||||
let mut imp = self.imp();
|
||||
imp.set_valid_file_paths(validated_paths, identifier);
|
||||
if do_save {
|
||||
imp.enable_automatic_saving();
|
||||
imp.enable_automatic_saving();
|
||||
if to_disk {
|
||||
imp.save_unless_disabled();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Add the item.
|
||||
// If we think we're about to exit, save immediately, regardless of any disabling. This may
|
||||
// cause us to lose file hinting for some commands, but it beats losing history items.
|
||||
imp.add(item, /*pending=*/ true, do_save);
|
||||
if do_save && needs_sync_write {
|
||||
imp.add(item, /*pending=*/ true, to_disk);
|
||||
if to_disk && needs_sync_write {
|
||||
imp.save(false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user