Skip to main content

gc_backup

Function gc_backup 

Source
pub fn gc_backup(
    source: Option<Utf8PathBuf>,
    older_than: Option<String>,
    dry_run: bool,
    icons_override: Option<IconsMode>,
    no_color: bool,
) -> Result<()>
Expand description

yui gc-backup [--older-than DUR] [--dry-run] — prune snapshots under $DOTFILES/.yui/backup/.

With no --older-than we run a non-destructive survey: walk the backup tree, list every entry whose name carries yui’s _<YYYYMMDD_HHMMSSfff>[.<ext>] suffix, and print AGE / SIZE / PATH sorted oldest-first plus a hint to pass --older-than DUR to actually delete. With --older-than DUR (e.g. 30d, 2w, 12h, 6m, 1y) we delete every entry strictly older than the cutoff. --dry-run previews the same set without writing.

Two design points worth flagging:

  1. Suffix, not mtime. std::fs::copy preserves source mtime on most platforms, so a backup of an old dotfile would look “old” by mtime even when freshly created. The suffix is the source of truth for “when did yui take this snapshot?”.
  2. Defensive parse. Anything in .yui/backup/ whose name doesn’t match the suffix shape is left alone — if you dropped a file there by hand, gc-backup isn’t going to delete it.