]> CyberLeo.Net >> Repos - CDN/shlib.git/blob - lib/sh/file.sh
Add file convenience functions: onelink
[CDN/shlib.git] / lib / sh / file.sh
1 # File library script
2
3 if [ -z "${__file_sh_loaded}" ]
4 then
5   __file_sh_loaded=yes
6   
7   # Make sure the listed files have only one hardlink
8   onelink() {
9     while [ -n "${1}" ]
10     do
11       if [ -f "${1}" -a "$(stat -f '%l' "${1}")" -gt 1 ]
12       then
13         tmp="$(mktemp "${1}")"
14         cp -p "${1}" "${tmp}" && mv "${tmp}" "${1}" || return 1
15       fi
16       shift
17     done
18   }
19 fi