diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | bin/kiss-stat.c | 32 | ||||
-rwxr-xr-x | kiss | 4 | ||||
-rw-r--r-- | man/kiss-contrib.1 | 5 |
5 files changed, 54 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..950efb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +kiss-stat
\ No newline at end of file @@ -2,11 +2,22 @@ PREFIX = /usr/local BINDIR = ${PREFIX}/bin MANPREFIX = ${PREFIX}/share/man MAN1 = ${MANPREFIX}/man1 +CC = cc -install: +all: kiss-stat + +kiss-stat: + ${CC} -o kiss-stat bin/kiss-stat.c + +clean: + rm -f kiss-stat + +install: all mkdir -p ${DESTDIR}${BINDIR} cp kiss ${DESTDIR}${BINDIR}/kiss chmod 755 ${DESTDIR}${BINDIR}/kiss + cp kiss-stat ${DESTDIR}${BINDIR}/kiss-stat + chmod 755 ${DESTDIR}${BINDIR}/kiss-stat for bin in contrib/* ; do cp $${bin} ${DESTDIR}${BINDIR}/$${bin##*/}; \ chmod 755 ${DESTDIR}${BINDIR}/$${bin##*/} ; done @@ -17,9 +28,10 @@ install: uninstall: rm -f ${DESTDIR}${BINDIR}/kiss + rm -f ${DESTDIR}${BINDIR}/kiss-stat for bin in contrib/* ; do rm -f ${DESTDIR}${BINDIR}/$${bin##*/} ; done rm -f ${DESTDIR}${MAN1}/kiss.1 ${DESTDIR}${MAN1}/kiss.1 rm -f ${DESTDIR}${MAN1}/kiss-contrib.1 ${DESTDIR}${MAN1}/kiss-contrib.1 -.PHONY: install uninstall +.PHONY: all install uninstall clean diff --git a/bin/kiss-stat.c b/bin/kiss-stat.c new file mode 100644 index 0000000..d03bd13 --- /dev/null +++ b/bin/kiss-stat.c @@ -0,0 +1,32 @@ +// kiss-stat --- a utility for getting the user name of file owner +// See LICENSE for copyright information + +/* The reason this simple tool exists is because 'stat' is not + * portable and ls is not exactly stable enough for scripting. + * This program is for outputting the owner name, and that's it. + */ + +#include <pwd.h> +#include <sys/stat.h> +#include <stdio.h> + +int main (int argc, char *argv[]) { + struct stat sb; + + // Exit if no or multiple arguments are given + if (argc != 2) { + fprintf(stderr, "Usage: %s <pathname>\n", argv[0]); + return(1); + } + + // Exit if file stat cannot be obtained + if (lstat(argv[1], &sb) == -1) { + perror(argv[0]); + return(1); + } + + // Print the user name of file owner + struct passwd *pw = getpwuid(sb.st_uid); + printf("%s\n", pw->pw_name); + return(0); +} @@ -1167,7 +1167,7 @@ pkg_fetch() { # ownership of files and directories in the rare # case that the repository is owned by a 3rd user. ( - user=$(stat -c %U "$PWD") || user=root + user=$(kiss-stat "$PWD") || user=root id -u "$user" >/dev/null 2>&1 || user=root @@ -1353,7 +1353,7 @@ args() { else log "$pkg" "Need permissions to generate checksums" - user=$(stat -c %U "$repo_dir") as_root tee "$repo_dir/checksums" + user=$(kiss-stat "$repo_dir") as_root tee "$repo_dir/checksums" fi } diff --git a/man/kiss-contrib.1 b/man/kiss-contrib.1 index 64ea066..0ad4475 100644 --- a/man/kiss-contrib.1 +++ b/man/kiss-contrib.1 @@ -141,6 +141,11 @@ Prints the packages that depend on the given package. (Reverse dependencies) <pkg> Prints the given package's size, and its individual files. +.SH KISS-STAT +.B kiss-stat +<file> + +Outputs the owner name of a file/directory .SH KISS-WHICH .B kiss-which <pkg> |