summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-08-25 22:23:24 +0200
committerAlejandro Colomar <alx@kernel.org>2023-10-20 21:05:33 +0200
commit7c93e1cdce2a334dc346c7aa564b13cae6d88eb7 (patch)
treed42206574708192dd0dd1ce47940876746bf0e79
parent088fe2618fcc286be0686d4c679d225d734427bb (diff)
lib/copydir.c: Invert conditional to reduce nesting
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--lib/copydir.c81
1 files changed, 40 insertions, 41 deletions
diff --git a/lib/copydir.c b/lib/copydir.c
index bbee719f..4c1b78be 100644
--- a/lib/copydir.c
+++ b/lib/copydir.c
@@ -314,51 +314,50 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info *
set_orig = true;
}
while ((0 == err) && (ent = readdir (dir)) != NULL) {
+ char *src_name, *dst_name;
+ size_t src_len, dst_len;
/*
* Skip the "." and ".." entries
*/
- if ((strcmp (ent->d_name, ".") != 0) &&
- (strcmp (ent->d_name, "..") != 0)) {
- char *src_name;
- char *dst_name;
- size_t src_len = strlen (ent->d_name) + 2;
- size_t dst_len = strlen (ent->d_name) + 2;
- src_len += strlen (src->full_path);
- dst_len += strlen (dst->full_path);
-
- src_name = MALLOC(src_len, char);
- dst_name = MALLOC(dst_len, char);
-
- if ((NULL == src_name) || (NULL == dst_name)) {
- err = -1;
- } else {
- /*
- * Build the filename for both the source and
- * the destination files.
- */
- struct path_info src_entry, dst_entry;
-
- (void) snprintf (src_name, src_len, "%s/%s",
- src->full_path, ent->d_name);
- (void) snprintf (dst_name, dst_len, "%s/%s",
- dst->full_path, ent->d_name);
-
- src_entry.full_path = src_name;
- src_entry.dirfd = dirfd(dir);
- src_entry.name = ent->d_name;
-
- dst_entry.full_path = dst_name;
- dst_entry.dirfd = dst_fd;
- dst_entry.name = ent->d_name;
-
- err = copy_entry (&src_entry, &dst_entry,
- reset_selinux,
- old_uid, new_uid,
- old_gid, new_gid);
- }
- free (src_name);
- free (dst_name);
+ if (strcmp(ent->d_name, ".") == 0 ||
+ strcmp(ent->d_name, "..") == 0)
+ {
+ continue;
+ }
+
+ src_len = strlen (ent->d_name) + 2;
+ dst_len = strlen (ent->d_name) + 2;
+ src_len += strlen (src->full_path);
+ dst_len += strlen (dst->full_path);
+
+ src_name = MALLOC(src_len, char);
+ dst_name = MALLOC(dst_len, char);
+
+ if ((NULL == src_name) || (NULL == dst_name)) {
+ err = -1;
+ } else {
+ /*
+ * Build the filename for both the source and
+ * the destination files.
+ */
+ struct path_info src_entry, dst_entry;
+
+ (void) snprintf (src_name, src_len, "%s/%s", src->full_path, ent->d_name);
+ (void) snprintf (dst_name, dst_len, "%s/%s", dst->full_path, ent->d_name);
+
+ src_entry.full_path = src_name;
+ src_entry.dirfd = dirfd(dir);
+ src_entry.name = ent->d_name;
+
+ dst_entry.full_path = dst_name;
+ dst_entry.dirfd = dst_fd;
+ dst_entry.name = ent->d_name;
+
+ err = copy_entry(&src_entry, &dst_entry, reset_selinux,
+ old_uid, new_uid, old_gid, new_gid);
}
+ free (src_name);
+ free (dst_name);
}
(void) closedir (dir);
(void) close (dst_fd);