[hackers] [sbase] install: Unlink destination file on failure || Michael Forney

From: <git_AT_suckless.org>
Date: Mon, 25 May 2020 06:19:48 +0200 (CEST)

commit 9e985c2bb2afea0f7fcd221b0359201cb121296d
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sun May 24 20:58:36 2020 -0700
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Sun May 24 20:58:36 2020 -0700

    install: Unlink destination file on failure

diff --git a/xinstall.c b/xinstall.c
index bb973e8..fe1a160 100644
--- a/xinstall.c
+++ b/xinstall.c
_AT_@ -54,16 +54,24 @@ install(const char *s1, const char *s2, int depth)
                         eprintf("creat %s:", s2);
         }
         if (concat(f1, s1, f2, s2) < 0)
- exit(1);
- if (fchmod(f2, mode) < 0)
- eprintf("fchmod %s:", s2);
- if (fchown(f2, owner, group) < 0)
- eprintf("lchown %s:", s2);
+ goto fail;
+ if (fchmod(f2, mode) < 0) {
+ weprintf("fchmod %s:", s2);
+ goto fail;
+ }
+ if (fchown(f2, owner, group) < 0) {
+ weprintf("fchown %s:", s2);
+ goto fail;
+ }
 
         close(f1);
         close(f2);
 
         return 0;
+
+fail:
+ unlink(s2);
+ exit(1);
 }
 
 static void
Received on Mon May 25 2020 - 06:19:48 CEST

This archive was generated by hypermail 2.3.0 : Mon May 25 2020 - 06:24:36 CEST