logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 0aa87acbacda979c1f7ac7a41a6d4c0a8b7f4d94
parent 800eaf4f24a72f63d0152337352dc92be2fa410c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 21 Oct 2024 22:33:08 +0200

cmd/install: add support for -v option

Diffstat:

Mcmd/install.18+++++---
Mcmd/install.c21++++++++++++++++-----
2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/cmd/install.1 b/cmd/install.1 @@ -9,14 +9,14 @@ .Nd install binairies .Sh SYNOPSIS .Nm -.Op Fl CcDpT +.Op Fl CcDpTv .Op Fl g Ar group .Op Fl m Ar mode .Op Fl o Ar owner .Ar source... .Ar destination .Nm -.Op Fl CcDpT +.Op Fl CcDpTv .Op Fl g Ar group .Op Fl m Ar mode .Op Fl o Ar owner @@ -24,7 +24,7 @@ .Ar source... .Nm .Fl d -.Op Fl c +.Op Fl cv .Op Fl g Ar group .Op Fl m Ar mode .Op Fl o Ar owner @@ -88,6 +88,8 @@ as a normal file. Which asserts a single .Ar source operand. +.It Fl v +print the name of each created file or directory .El .Sh EXIT STATUS .Ex -std diff --git a/cmd/install.c b/cmd/install.c @@ -36,6 +36,8 @@ uid_t user = (uid_t)-1; gid_t group = (gid_t)-1; const char *argv0 = "install"; +bool opt_v = false; + static int do_install(char *src, char *dest, bool is_dir) { @@ -136,6 +138,8 @@ do_install(char *src, char *dest, bool is_dir) return -1; } + if(opt_v) fprintf(stderr, "%s: Made file: %s\n", argv0, dest); + if(auto_file_copy(src_fd, dest_fd, src_stat.st_size, 0) < 0) { fprintf(stderr, @@ -197,9 +201,9 @@ static void usage(void) { fprintf(stderr, "\ -Usage: install [-CcDpT] [-g group] [-m mode] [-o owner] source... destination\n\ - install [-CcDpT] [-g group] [-m mode] [-o owner] -t destination source...\n\ - install -d [-c] [-g group] [-m mode] [-o owner] directory...\n\ +Usage: install [-CcDpTv] [-g group] [-m mode] [-o owner] source... destination\n\ + install [-CcDpTv] [-g group] [-m mode] [-o owner] -t destination source...\n\ + install -d [-cv] [-g group] [-m mode] [-o owner] directory...\n\ "); } @@ -227,14 +231,15 @@ main(int argc, char *argv[]) {"preserve-timestamps", no_argument, 0, 'p'}, {"target-directory", required_argument, 0, 't'}, {"no-target-directory", no_argument, 0, 'T'}, + {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}, }; // clang-format on // Need + as first character to get POSIX-style option parsing - while((c = getopt_long(argc, argv, "+:CcDdpTt:g:m:o:", opts, NULL)) != -1) + while((c = getopt_long(argc, argv, "+:CcDdpTt:g:m:o:v", opts, NULL)) != -1) #else - while((c = getopt(argc, argv, ":CcDdpTt:g:m:o:")) != -1) + while((c = getopt(argc, argv, ":CcDdpTt:g:m:o:v")) != -1) #endif { switch(c) @@ -274,6 +279,10 @@ main(int argc, char *argv[]) return 1; } break; + case 'v': + opt_v = true; + mkdir_parents_verbose = true; + break; case ':': fprintf(stderr, "install: error: Missing operand for option: '-%c'\n", optopt); usage(); @@ -298,6 +307,8 @@ main(int argc, char *argv[]) if(mkdir_parents(dest, mode) != 0) return -1; + if(opt_v) fprintf(stderr, "%s: Made directory: %s\n", argv0, dest); + if(user != (uid_t)-1 || group != (gid_t)-1) { if(chown(dest, user, group) < 0)