diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2023-01-26 21:37:30 +0100 |
---|---|---|
committer | Serge Hallyn <serge@hallyn.com> | 2023-10-21 21:37:38 -0500 |
commit | 2fa907a522203fa169491d4bb50d5b8586986a49 (patch) | |
tree | 60d3edc85e5b737c3f02d97c902eefa18a09ca21 | |
parent | fa68441bc4be8edeaad8d104344e987b31ed44e6 (diff) |
libmisc/copydir: do not forget errors from directory copy
copydir.c:429:4: warning: Value stored to 'err' is never read [deadcode.DeadStores]
Also reduce indentation by bailing out early.
(cherry picked from commit d89f2fb06d1b81b56299f9d0bfe7a927a2282f19)
-rw-r--r-- | lib/copydir.c | 93 |
1 files changed, 47 insertions, 46 deletions
diff --git a/lib/copydir.c b/lib/copydir.c index 483d5b15..6a80d7e7 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -404,63 +404,64 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst, if (fstatat(src->dirfd, src->name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { /* If we cannot stat the file, do not care. */ - } else { - mt[0].tv_sec = sb.st_atim.tv_sec; - mt[0].tv_nsec = sb.st_atim.tv_nsec; + return 0; + } - mt[1].tv_sec = sb.st_mtim.tv_sec; - mt[1].tv_nsec = sb.st_mtim.tv_nsec; + mt[0].tv_sec = sb.st_atim.tv_sec; + mt[0].tv_nsec = sb.st_atim.tv_nsec; - if (S_ISDIR (sb.st_mode)) { - err = copy_dir (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + mt[1].tv_sec = sb.st_mtim.tv_sec; + mt[1].tv_nsec = sb.st_mtim.tv_nsec; - /* - * If the destination already exists do nothing. - * This is after the copy_dir above to still iterate into subdirectories. - */ - if (fstatat(dst->dirfd, dst->name, &sb, AT_SYMLINK_NOFOLLOW) != -1) { - return 0; - } + if (S_ISDIR (sb.st_mode)) { + err = copy_dir (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); + } - /* - * Copy any symbolic links - */ + /* + * If the destination already exists do nothing. + * This is after the copy_dir above to still iterate into subdirectories. + */ + if (fstatat(dst->dirfd, dst->name, &sb, AT_SYMLINK_NOFOLLOW) != -1) { + return err; + } - else if (S_ISLNK (sb.st_mode)) { - err = copy_symlink (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + /* + * Copy any symbolic links + */ - /* - * See if this is a previously copied link - */ + else if (S_ISLNK (sb.st_mode)) { + err = copy_symlink (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); + } - else if ((lp = check_link (src->full_path, &sb)) != NULL) { - err = copy_hardlink (dst, reset_selinux, lp); - } + /* + * See if this is a previously copied link + */ - /* - * Deal with FIFOs and special files. The user really - * shouldn't have any of these, but it seems like it - * would be nice to copy everything ... - */ + else if ((lp = check_link (src->full_path, &sb)) != NULL) { + err = copy_hardlink (dst, reset_selinux, lp); + } - else if (!S_ISREG (sb.st_mode)) { - err = copy_special (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + /* + * Deal with FIFOs and special files. The user really + * shouldn't have any of these, but it seems like it + * would be nice to copy everything ... + */ - /* - * Create the new file and copy the contents. The new - * file will be owned by the provided UID and GID values. - */ + else if (!S_ISREG (sb.st_mode)) { + err = copy_special (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); + } - else { - err = copy_file (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + /* + * Create the new file and copy the contents. The new + * file will be owned by the provided UID and GID values. + */ + + else { + err = copy_file (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); } return err; |