[][src]Module coreutils_core::backup

The Backup module handles creating backups using the methods specified in the GNU coreutils manual.

About

The GNU coreutils backup options support 4 backup modes:

  • None
  • Numbered
  • Existing
  • Simple

NOTE: This module does not figure out default values based on environment variables as defined in the GNU backup options manual page. Whether to adhere to the GNU standard or not is up to the user of this module.

None

Can be specified by either supplying the strings none or off. Fairly self-explanatory: Never make backups.

Numbered

Can be specified by either supplying the strings numbered or t. This mode always makes numbered backups. This means that a backup of a file a.txt will be backed up to a.txt~X~ where X is the next number backup.

For example, if we create a file named main.rs and then back it up in this mode, we will get main.rs~1~. If we back the file up a second time, we will get main.rs~2~.

Simple

Can be specified by either supplying the strings simple or never (not to be confused with none) This mode simple appends a static suffix to the backup (This is how Emacs makes backup files by default).

For exmaple, if we create a file named main.rs and then back it up in this mode, we will get main.rs~. If we back the file up a second time, we will overwrite the old backup and the new backup will be called main.rs~.

Existing

Can be specified by either supplying the strings existing or nil. This mode checks for the existance of previous backups in any mode. If it finds numbered backups, it will continue to make numbered backups. If it finds simple backups, it will continue to make simple backups.

Enums

BackupMode

Convenience Enum to represent the different backup modes. See module documentation for an in-depth overview of what each backup mode means/does.

Functions

create_existing_backup

Creates a backup in-keeping with previous backups. Pokes the directory to see whether there are any numbered or simple backups of the input file. If numbered backups are found, a numbered backup will be created. Else, a simple backup is created using the input suffix

create_numbered_backup

Creates a numbered backup. Does so by taking the input file and poking the parent directory to find a file of the form <file>~<X>~ where X is a number. If none can be found, a backup file is created where X is 1. Else, it creates a backup file where X is X + 1.

create_simple_backup

Creates a simple backup. Creates a backup of the form <file><suffix>. Overwrites any previous backup files with that same suffix.