Break out if stat fails on the source file in cp(1)

Save one level of indentation.
This commit is contained in:
sin 2014-11-19 15:08:57 +00:00
parent 2c42905f63
commit 9b38355ae8

View File

@ -39,12 +39,13 @@ cp(const char *s1, const char *s2)
if (cp_vflag) if (cp_vflag)
printf("'%s' -> '%s'\n", s1, s2); printf("'%s' -> '%s'\n", s1, s2);
if (cp_dflag) r = cp_dflag ? lstat(s1, &st) : stat(s1, &st);
r = lstat(s1, &st); if (r < 0) {
else weprintf("%s %s:", cp_dflag ? "lstat" : "stat", s1);
r = stat(s1, &st); cp_status = 1;
return 0;
}
if (r == 0) {
if (cp_dflag && S_ISLNK(st.st_mode)) { if (cp_dflag && S_ISLNK(st.st_mode)) {
if (readlink(s1, buf, sizeof(buf) - 1) >= 0) { if (readlink(s1, buf, sizeof(buf) - 1) >= 0) {
if (cp_fflag) if (cp_fflag)
@ -57,6 +58,7 @@ cp(const char *s1, const char *s2)
} }
goto preserve; goto preserve;
} }
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
if (!cp_rflag) if (!cp_rflag)
eprintf("%s: is a directory\n", s1); eprintf("%s: is a directory\n", s1);
@ -89,7 +91,6 @@ cp(const char *s1, const char *s2)
free(ns2); free(ns2);
goto preserve; goto preserve;
} }
}
if (cp_aflag) { if (cp_aflag) {
if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) || if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) ||
@ -125,6 +126,7 @@ cp(const char *s1, const char *s2)
} }
} }
concat(f1, s1, f2, s2); concat(f1, s1, f2, s2);
/* preserve permissions by default */
fchmod(fileno(f2), st.st_mode); fchmod(fileno(f2), st.st_mode);
fclose(f2); fclose(f2);
fclose(f1); fclose(f1);