[hackers] [sbase] install: Remove special handling for non-regular files || Michael Forney

From: <git_AT_suckless.org>
Date: Sun, 22 Mar 2020 01:11:43 +0100 (CET)

commit 2b8f1ee3a6a4e16d9a83b40b2ce647f1f6cce1f8
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sun Mar 1 17:26:48 2020 -0800
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Sat Mar 21 12:27:00 2020 -0700

    install: Remove special handling for non-regular files
    
    All install(1) implementations I'm aware of don't try to replicate
    the source file node like this. Additionally, this reportedly breaks
    some scripts that use install(1) in a pipeline.

diff --git a/xinstall.c b/xinstall.c
index fe55396..e102c4c 100644
--- a/xinstall.c
+++ b/xinstall.c
_AT_@ -43,72 +43,24 @@ make_dirs(char *dir, int was_missing)
 static int
 install(const char *s1, const char *s2, int depth)
 {
- DIR *dp;
         int f1, f2;
- struct dirent *d;
- struct stat st;
- ssize_t r;
- char target[PATH_MAX], ns1[PATH_MAX], ns2[PATH_MAX];
-
- if (stat(s1, &st) < 0)
- eprintf("stat %s:", s1);
-
- if (S_ISLNK(st.st_mode)) {
- if ((r = readlink(s1, target, sizeof(target) - 1)) >= 0) {
- target[r] = '\0';
- if (unlink(s2) < 0 && errno != ENOENT)
- eprintf("unlink %s:", s2);
- else if (symlink(target, s2) < 0)
- eprintf("symlink %s -> %s:", s2, target);
- }
- } else if (S_ISDIR(st.st_mode)) {
- if (!(dp = opendir(s1)))
- eprintf("opendir %s:", s1);
- if (mkdir(s2, mode | 0111) < 0 && errno != EEXIST)
- eprintf("mkdir %s:", s2);
-
- while ((d = readdir(dp))) {
- if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
- continue;
-
- estrlcpy(ns1, s1, sizeof(ns1));
- if (s1[strlen(s1) - 1] != '/')
- estrlcat(ns1, "/", sizeof(ns1));
- estrlcat(ns1, d->d_name, sizeof(ns1));
-
- estrlcpy(ns2, s2, sizeof(ns2));
- if (s2[strlen(s2) - 1] != '/')
- estrlcat(ns2, "/", sizeof(ns2));
- estrlcat(ns2, d->d_name, sizeof(ns2));
-
- fnck(ns1, ns2, install, depth + 1);
- }
 
- closedir(dp);
- } else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) ||
- S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode)) {
+ if ((f1 = open(s1, O_RDONLY)) < 0)
+ eprintf("open %s:", s1);
+ if ((f2 = creat(s2, 0600)) < 0) {
                 if (unlink(s2) < 0 && errno != ENOENT)
                         eprintf("unlink %s:", s2);
- else if (mknod(s2, (st.st_mode & ~07777) | mode, st.st_rdev) < 0)
- eprintf("mknod %s:", s2);
- } else {
- if ((f1 = open(s1, O_RDONLY)) < 0)
- eprintf("open %s:", s1);
- if ((f2 = creat(s2, 0600)) < 0) {
- if (unlink(s2) < 0 && errno != ENOENT)
- eprintf("unlink %s:", s2);
- if ((f2 = creat(s2, 0600)) < 0)
- eprintf("creat %s:", s2);
- }
- if (concat(f1, s1, f2, s2) < 0)
- exit(1);
+ if ((f2 = creat(s2, 0600)) < 0)
+ eprintf("creat %s:", s2);
+ }
+ if (concat(f1, s1, f2, s2) < 0)
+ exit(1);
 
- if (fchmod(f2, mode) < 0)
- eprintf("fchmod %s:", s2);
+ if (fchmod(f2, mode) < 0)
+ eprintf("fchmod %s:", s2);
 
- close(f1);
- close(f2);
- }
+ close(f1);
+ close(f2);
 
         if (lchown(s2, owner, group) < 0)
                 eprintf("lchown %s:", s2);
Received on Sun Mar 22 2020 - 01:11:43 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 22 2020 - 01:12:37 CET