Services.BackupFile (fnord v0.8.83)
View SourceGenServer that manages backup file creation for file editing operations with dual counter system.
Backup files follow the naming pattern:
original_filename.global_session_counter.change_counter.bak
- global_session_counter: Per-file, per-OS-process counter that increments when existing backup files from previous processes are detected
- change_counter: Per-file counter that increments for each successful edit within the current session
Summary
Functions
Returns a specification to start this module under a supervisor.
Delete all backup files created during this session.
Creates a backup file for the given file path and returns the backup path. Uses the dual counter system to generate unique backup filenames.
Returns a descriptive note for backup files, or nil for non-backup files. Includes session information if the backup was created this session.
Returns all backup files created during this session (current OS process).
Checks if a file path represents a backup file created by fnord. Returns true if the filename matches the pattern: filename.X.Y.bak
Checks if a backup file was created during the current session. Returns true if the file exists in the current session's backup list.
Offers to cleanup backup files created during this session.
Resets the server state. Primarily used for testing.
Starts the backup file server with a globally registered name.
Types
@type state() :: %{ global_counters: %{required(binary()) => non_neg_integer()}, change_counters: %{required(binary()) => non_neg_integer()}, backup_files: [binary()] }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec cleanup_backup_files() :: :ok
Delete all backup files created during this session.
Creates a backup file for the given file path and returns the backup path. Uses the dual counter system to generate unique backup filenames.
Returns a descriptive note for backup files, or nil for non-backup files. Includes session information if the backup was created this session.
@spec get_session_backups() :: [binary()]
Returns all backup files created during this session (current OS process).
This includes backup files for all edited files during the current session, but excludes any backup files that may exist from previous sessions.
Files are returned in reverse chronological order (most recent first).
Checks if a file path represents a backup file created by fnord. Returns true if the filename matches the pattern: filename.X.Y.bak
Checks if a backup file was created during the current session. Returns true if the file exists in the current session's backup list.
@spec offer_cleanup() :: :ok
Offers to cleanup backup files created during this session.
If backup files exist, lists them and prompts the user for confirmation before deleting them. If no backup files exist, does nothing silently.
@spec reset() :: :ok
Resets the server state. Primarily used for testing.
Starts the backup file server with a globally registered name.