aspiers/stow

New command line option `--orig` to rename conflicting files

Open

#4 aberto em 30 de jun. de 2015

Ver no GitHub
 (11 comments) (12 reactions) (0 assignees)Perl (51 forks)batch import
enhancementhelp wanted

Métricas do repositório

Stars
 (1.013 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

Hello!

Thank you for stow -- I'm enjoying it a lot. It has become the first tool that I install on a new machine after git. Also, I hope github is an OK channel for sending feature requests.

Here's my request: It'd be nice to have a new command line option --orig (or similar) to make backups of conflicting files in the target directory instead of failing on conflict. For example:

  • hosts => hosts.orig
  • ntp.conf => ntp.conf.orig
  • .bashrc => .bashrc.orig

I often use stow to link files from a git repo into $HOME or /etc, and Linux distributions ship with default configuration files in these locations that stow will trip over. The --adopt option does not solve my problem because I don't want to copy the OS default configs into my git repo - I want to do the opposite and overwrite the OS default configs (but keep backups of them).

Leaving each backup file in the same directory as the original and using a constant backup extension (.orig) has the nice effect that one can do e.g. find /etc -name "*.orig" to find all overwritten configs. Likewise, it's fairly easy to run diff to see changes from the OS defaults.

Here's a demonstration of what currently happens:

$ mkdir demo
$ mkdir -p demo/stow/test
$ touch demo/foo demo/stow/test/foo
$ tree demo --charset ascii
demo
|-- foo
`-- stow
    `-- test
        `-- foo

2 directories, 2 files
$ (cd demo/stow && stow test)
WARNING! stowing test would cause conflicts:
  * existing target is neither a link nor a directory: foo
All operations aborted.

This is what I would like to have:

$ (cd demo/stow && stow --orig -vv test)
...
RENAME: foo => foo.orig
LINK: foo => stow/test/foo
...
$ tree demo --charset ascii
demo
|-- foo -> stow/test/foo
|-- foo.orig
`-- stow
    `-- test
        `-- foo

2 directories, 3 files

Here's a succint description of the behavior that --orig would have, covering edge cases:

  • IF dst already exists THEN
    • IF dst.orig already exists THEN give up and stop with an error
    • ELSE rename dst to dst.orig(even if dst is a symlink, a directory, etc.)
      • IF the rename fails due to permissions etc. THEN give up and stop with an error

The option could also be named --backup or similar, but I personally like --orig because it's short and mnemonic (it reminds the user that the backup filename will have the extension .orig, which is also a de facto standard extension for such files).

Would you accept a feature like this into stow?

Kind regards, Lassi

Guia do colaborador