Skip to content

Commit 08e1564

Browse files
committed
nad: merge enclosing if statements
1 parent c9b1229 commit 08e1564

File tree

3 files changed

+48
-59
lines changed

3 files changed

+48
-59
lines changed

bin/nad/nad_cp.c

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,11 @@ static int copy(const char *path,
505505
}
506506

507507
/* Convert basename to appropriate volume encoding */
508-
if (dvolume.vol->v_path) {
509-
if ((convert_dots_encoding(&svolume, &dvolume, to.p_path, MAXPATHLEN)) == -1) {
510-
SLOG("Error converting name for %s", to.p_path);
511-
badcp = rval = 1;
512-
return -1;
513-
}
508+
if (dvolume.vol->v_path
509+
&& (convert_dots_encoding(&svolume, &dvolume, to.p_path, MAXPATHLEN)) == -1) {
510+
SLOG("Error converting name for %s", to.p_path);
511+
badcp = rval = 1;
512+
return -1;
514513
}
515514

516515
switch (statp->st_mode & S_IFMT) {
@@ -557,13 +556,12 @@ static int copy(const char *path,
557556
bdestroy(addir);
558557
}
559558

560-
if (svolume.vol->v_path && ADVOL_V2_OR_EA(svolume.vol->v_adouble)) {
561-
/* copy metadata file */
562-
if (dvolume.vol->vfs->vfs_copyfile(dvolume.vol, -1, path, to.p_path)) {
563-
SLOG("Error copying adouble for %s -> %s", path, to.p_path);
564-
badcp = rval = 1;
565-
break;
566-
}
559+
/* copy metadata file */
560+
if (svolume.vol->v_path && ADVOL_V2_OR_EA(svolume.vol->v_adouble)
561+
&& dvolume.vol->vfs->vfs_copyfile(dvolume.vol, -1, path, to.p_path)) {
562+
SLOG("Error copying adouble for %s -> %s", path, to.p_path);
563+
badcp = rval = 1;
564+
break;
567565
}
568566

569567
/* Get CNID of Parent and add new childir to CNID database */
@@ -607,11 +605,8 @@ static int copy(const char *path,
607605
umask(omask);
608606
}
609607

610-
if (pflag) {
611-
if (setfile(statp, -1)) {
612-
rval = 1;
613-
}
614-
608+
if (pflag && setfile(statp, -1)) {
609+
rval = 1;
615610
#if 0
616611

617612
if (preserve_dir_acls(statp, curr->fts_accpath, to.p_path) != 0) {
@@ -644,13 +639,12 @@ static int copy(const char *path,
644639
if (dvolume.vol->v_path && ADVOL_V2_OR_EA(dvolume.vol->v_adouble)) {
645640
mode_t omask = umask(0);
646641

647-
if (svolume.vol->v_path && ADVOL_V2_OR_EA(svolume.vol->v_adouble)) {
648-
/* copy ad-file */
649-
if (dvolume.vol->vfs->vfs_copyfile(dvolume.vol, -1, path, to.p_path)) {
650-
SLOG("Error copying adouble for %s -> %s", path, to.p_path);
651-
badcp = rval = 1;
652-
break;
653-
}
642+
/* copy ad-file */
643+
if (svolume.vol->v_path && ADVOL_V2_OR_EA(svolume.vol->v_adouble)
644+
&& dvolume.vol->vfs->vfs_copyfile(dvolume.vol, -1, path, to.p_path)) {
645+
SLOG("Error copying adouble for %s -> %s", path, to.p_path);
646+
badcp = rval = 1;
647+
break;
654648
}
655649

656650
/* Get CNID of Parent and add new childir to CNID database */
@@ -1002,34 +996,33 @@ static int setfile(const struct stat *fs, int fd)
1002996
* the mode; current BSD behavior is to remove all setuid bits on
1003997
* chown. If chown fails, lose setuid/setgid bits.
1004998
*/
1005-
if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid)
1006-
if (fdval ? fchown(fd, fs->st_uid, fs->st_gid) :
1007-
(islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) :
1008-
chown(to.p_path, fs->st_uid, fs->st_gid))) {
1009-
if (errno != EPERM) {
1010-
SLOG("chown: %s: %s", to.p_path, strerror(errno));
1011-
rval = 1;
1012-
}
1013-
1014-
mode &= ~(S_ISUID | S_ISGID);
1015-
}
1016-
1017-
if (!gotstat || mode != ts.st_mode)
1018-
if (fdval ? fchmod(fd, mode) : chmod(to.p_path, mode)) {
1019-
SLOG("chmod: %s: %s", to.p_path, strerror(errno));
999+
if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid
1000+
&& fdval ? fchown(fd, fs->st_uid, fs->st_gid) :
1001+
(islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) :
1002+
chown(to.p_path, fs->st_uid, fs->st_gid))) {
1003+
if (errno != EPERM) {
1004+
SLOG("chown: %s: %s", to.p_path, strerror(errno));
10201005
rval = 1;
10211006
}
10221007

1008+
mode &= ~(S_ISUID | S_ISGID);
1009+
}
1010+
1011+
if ((!gotstat || mode != ts.st_mode)
1012+
&& (fdval ? fchmod(fd, mode) : chmod(to.p_path, mode))) {
1013+
SLOG("chmod: %s: %s", to.p_path, strerror(errno));
1014+
rval = 1;
1015+
}
1016+
10231017
#ifdef HAVE_ST_FLAGS
10241018

1025-
if (!gotstat || fs->st_flags != ts.st_flags)
1026-
if (fdval ?
1027-
fchflags(fd, fs->st_flags) :
1028-
(islink ? lchflags(to.p_path, fs->st_flags) :
1029-
chflags(to.p_path, fs->st_flags))) {
1030-
SLOG("chflags: %s: %s", to.p_path, strerror(errno));
1031-
rval = 1;
1032-
}
1019+
if (!gotstat || fs->st_flags != ts.st_flags) && fdval ?
1020+
fchflags(fd, fs->st_flags) :
1021+
(islink ? lchflags(to.p_path, fs->st_flags) :
1022+
chflags(to.p_path, fs->st_flags))) {
1023+
SLOG("chflags: %s: %s", to.p_path, strerror(errno));
1024+
rval = 1;
1025+
}
10331026

10341027
#endif
10351028
return rval;

bin/nad/nad_mv.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,10 @@ static int do_move(const char *from, const char *to)
363363
return -1;
364364
}
365365

366-
if (!S_ISLNK(sb.st_mode)) {
367-
/* Can't mv(1) a mount point. */
368-
if (realpath(from, path) == NULL) {
369-
SLOG("cannot resolve %s: %s: %s", from, path, strerror(errno));
370-
return 1;
371-
}
366+
/* Can't mv(1) a mount point. */
367+
if (!S_ISLNK(sb.st_mode) && realpath(from, path) == NULL) {
368+
SLOG("cannot resolve %s: %s: %s", from, path, strerror(errno));
369+
return 1;
372370
}
373371
} else { /* != EXDEV */
374372
SLOG("rename %s to %s: %s", from, to, strerror(errno));

bin/nad/nad_util.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,9 @@ int openvol(AFPObj *obj, const char *path, afpvol_t *vol)
142142

143143
void closevol(afpvol_t *vol)
144144
{
145-
if (vol->vol) {
146-
if (vol->vol->v_cdb) {
147-
cnid_close(vol->vol->v_cdb);
148-
vol->vol->v_cdb = NULL;
149-
}
145+
if (vol->vol && vol->vol->v_cdb) {
146+
cnid_close(vol->vol->v_cdb);
147+
vol->vol->v_cdb = NULL;
150148
}
151149

152150
memset(vol, 0, sizeof(afpvol_t));

0 commit comments

Comments
 (0)