[__git] Simplify exporters.

Instead of using stat, we can rely on ls.
Thanks to @ssrq for pointing that out.
This commit is contained in:
evilham 2020-06-18 11:39:04 +02:00
parent e23e5ffa3c
commit a837797ee3
2 changed files with 8 additions and 26 deletions

View file

@ -1 +0,0 @@
owner

View file

@ -0,0 +1,6 @@
#!/bin/sh
destination="/$__object_id/.git"
# See: cdist/conf/type/__file/explorer/stat
ls -ld "$destination" | awk '{ print $4 }'

View file

@ -2,28 +2,5 @@
destination="/$__object_id/.git" destination="/$__object_id/.git"
action="$(basename "${0}")" # See: cdist/conf/type/__file/explorer/stat
ls -ld "$destination" | awk '{ print $3 }'
case $action in
owner)
bsd_fmt="%Su"
linux_fmt="%U"
;;
group)
bsd_fmt="%Sg"
linux_fmt="%G"
;;
esac
os="$(uname | tr '[:upper:]' '[:lower:]')"
case $os in
*bsd)
# Checked on OpenBSD, FreeBSD and NetBSD
stat -f "${bsd_fmt}" "${destination}" 2>/dev/null || exit 0
;;
*)
stat --print "${linux_fmt}" "${destination}" 2>/dev/null || exit 0
;;
esac