]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
refactor(dracut-install): simplify open() call in cp()
authorMarcos Mello <marcosfrm@gmail.com>
Wed, 11 Sep 2024 01:38:06 +0000 (22:38 -0300)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 11 Sep 2024 16:29:45 +0000 (12:29 -0400)
Flipping `S_IFMT` gives the file mode bits.

src/install/dracut-install.c

index bb0005206fbefd9991a95749f9d1cd0c613be442..96bc2eb646c7f8d45223ec8971a158d050538c9b 100644 (file)
@@ -364,13 +364,9 @@ static int cp(const char *src, const char *dst)
                 if (source_desc < 0)
                         goto normal_copy;
 
-                dest_desc =
-                        open(dst, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC,
-                             (sb.st_mode) & (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO));
-
-                if (dest_desc < 0) {
+                dest_desc = open(dst, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, sb.st_mode & ~S_IFMT);
+                if (dest_desc < 0)
                         goto normal_copy;
-                }
 
                 ret = clone_file(dest_desc, source_desc);