cpt

[ARCHIVED] Carbs Packaging Tools
git clone git://git.ckyln.com/~cem/cpt.git
Log | Files | Refs | README | LICENSE

commit 723b2643d99ffd165640a8fab8636289ad5ee20c
parent 51bec2d30d75900cdb810f03e9d82fc7b5e4e377
Author: Cem Keylan <cem@ckyln.com>
Date:   Sun,  3 May 2020 19:27:46 +0300

kiss: use our own version of stat for portability purposes.

Diffstat:
A.gitignore | 2++
MMakefile | 16++++++++++++++--
Abin/kiss-stat.c | 32++++++++++++++++++++++++++++++++
Mkiss | 4++--
Mman/kiss-contrib.1 | 5+++++
5 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +kiss-stat+ \ No newline at end of file diff --git a/Makefile b/Makefile @@ -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 @@ -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); +} diff --git a/kiss b/kiss @@ -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 @@ -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>