config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 3f34cfeae115be4254c19dff21b6c2213e7d8126
parent 08600ffa4aedd23ce97653ddc5b009f469139f4c
Author: Jacob R. Edwards <n/a>
Date:   Sat, 12 Feb 2022 13:06:31 -0800

Add hardlinking to modsync script

You can disable it, with the c option, but otherwise it always
attempts to create a hardlink if the destination file doesn't already
exist. In this way the user doesn't have to think about it, but can
disable it if they want a more uniform experience.

Diffstat:
Mlib/modsync | 26+++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/lib/modsync b/lib/modsync @@ -25,9 +25,7 @@ ask() { # Could be dynamically generated for efficiency, install(1) is also # an option. -install() { - echo "$2" 1>&2 - mkdir -p "$(dirname "$2")" +update() { cp -p "$1" "$2" test "$owner" && chown "$owner" "$2" @@ -35,18 +33,34 @@ install() { chmod "$perms" "$2" } +install() { + mkdir -p "$(dirname "$2")" + # If there is an error, it's likely that we're on a different + # filesystem. If not, cp(1) will likely have the same one. + ! $fcopy && + ln "$1" "$2" 2>/dev/null && return + update "$1" "$2" +} + +# TODO: Differing source mode, owner, etc. should be updated in dest filesync() { # Fix diff(1) output, I cannot get it to produce it for the # file I want when pulling. - if ! test -f "$2" + + if test "$1" -ef "$2" + then + return + elif ! test -f "$2" then + echo "$2" 1>&2 install "$1" "$2" elif $forcediff || test "$1" -nt "$2" -o "$1" -ot "$2" then if ! diff -u "$2" "$1" 1>&2 then + echo "$2" 1>&2 $patch && ask patch y && - install "$1" "$2" + update "$1" "$2" else touch -r "$1" "$2" fi @@ -94,6 +108,7 @@ patch=true owner= perms= forcediff=false +fcopy=false while expr x"$1" : x- > /dev/null do case "$1" in @@ -101,6 +116,7 @@ do (-o) owner="$2"; shift ;; (-p) perms="$2"; shift ;; (-d) forcediff=true ;; + (-c) fcopy=true ;; (*) usererror "$name: '$1': Invalid option" ;; esac shift