Skip to content

Commit 2d4e647

Browse files
committed
nad: untangle nested ternary statements into flat if control flows
1 parent 3792948 commit 2d4e647

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

bin/nad/nad_cp.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ static int setfile(const struct stat *fs, int fd)
947947
static struct timeval tv[2];
948948
struct stat ts;
949949
int gotstat, islink, fdval;
950+
int result;
950951
mode_t mode;
951952
rval = 0;
952953
fdval = fd != -1;
@@ -966,8 +967,15 @@ static int setfile(const struct stat *fs, int fd)
966967
rval = 1;
967968
}
968969

969-
if (fdval ? fstat(fd, &ts) :
970-
(islink ? lstat(to.p_path, &ts) : stat(to.p_path, &ts))) {
970+
if (fdval) {
971+
result = fstat(fd, &ts);
972+
} else if (islink) {
973+
result = lstat(to.p_path, &ts);
974+
} else {
975+
result = stat(to.p_path, &ts);
976+
}
977+
978+
if (result) {
971979
gotstat = 0;
972980
} else {
973981
gotstat = 1;
@@ -981,11 +989,17 @@ static int setfile(const struct stat *fs, int fd)
981989
* the mode; current BSD behavior is to remove all setuid bits on
982990
* chown. If chown fails, lose setuid/setgid bits.
983991
*/
984-
if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid
985-
&& fdval ? fchown(fd, fs->st_uid, fs->st_gid) :
986-
(islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) :
987-
chown(to.p_path, fs->st_uid, fs->st_gid))) {
988-
if (errno != EPERM) {
992+
993+
if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid) {
994+
if (fdval) {
995+
result = fchown(fd, fs->st_uid, fs->st_gid);
996+
} else if (islink) {
997+
result = lchown(to.p_path, fs->st_uid, fs->st_gid);
998+
} else {
999+
result = chown(to.p_path, fs->st_uid, fs->st_gid);
1000+
}
1001+
1002+
if (result != 0 && errno != EPERM) {
9891003
SLOG("chown: %s: %s", to.p_path, strerror(errno));
9901004
rval = 1;
9911005
}

0 commit comments

Comments
 (0)