2023-08-31 10:32:11 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cpto="$1"
|
|
|
|
cpfrom="$2"
|
|
|
|
|
2024-02-23 08:57:41 +00:00
|
|
|
cpOverwrite() {
|
|
|
|
# -f flag in case the destination perms were set to 000
|
|
|
|
# --no-dereference in case the destination already exists as a symlink
|
|
|
|
# however, "no-dereference" has the edge case of copying `cpfrom` to `cpto`
|
|
|
|
# when `cpto` already exists as a symlink to `cpfom`:
|
|
|
|
# "cp: <cpto> and <cpfrom> are the same file"
|
|
|
|
# use `--remove-destination` for that
|
|
|
|
cp --no-dereference -f "$cpfrom" "$cpto" \
|
|
|
|
|| cp --no-dereference --remove-destination "$cpfrom" "$cpto"
|
|
|
|
}
|
|
|
|
|
|
|
|
cpNoOverwrite() {
|
|
|
|
# --no-dereference in case the destination already exists as a symlink.
|
|
|
|
# it will still follow directory-level intermediate symlinks: just not a leaf symlink
|
2024-02-23 11:24:52 +00:00
|
|
|
cp --no-clobber --no-dereference "$cpfrom" "$cpto" || test -f "$cpto"
|
2024-02-23 08:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cpNoOverwrite
|