]> Dogcows Code - chaz/tar/blobdiff - src/compare.c
tar: another --atime-preserve race fix
[chaz/tar] / src / compare.c
index 2a314dafa12473874b926a996d7feaaa1ffd9943..204c5dc16dd38f204bea980e84bc4045e78387c5 100644 (file)
@@ -222,7 +222,9 @@ diff_file (void)
             ? O_NOATIME
             : 0);
 
-         diff_handle = open (file_name, O_RDONLY | O_BINARY | atime_flag);
+         diff_handle = open (file_name,
+                             (O_RDONLY | O_BINARY | O_CLOEXEC | O_NOCTTY
+                              | O_NONBLOCK | atime_flag));
 
          if (diff_handle < 0)
            {
@@ -241,10 +243,10 @@ diff_file (void)
 
              if (atime_preserve_option == replace_atime_preserve)
                {
-                 struct timespec ts[2];
-                 ts[0] = get_stat_atime (&stat_data);
-                 ts[1] = get_stat_mtime (&stat_data);
-                 if (set_file_atime (diff_handle, file_name, ts) != 0)
+                 struct timespec atime = get_stat_atime (&stat_data);
+                 if (set_file_atime (diff_handle, AT_FDCWD, file_name,
+                                     atime, 0)
+                     != 0)
                    utime_error (file_name);
                }
 
@@ -379,8 +381,7 @@ diff_dumpdir (void)
   else
     dev = stat_data.st_dev;
 
-  dumpdir_buffer = directory_contents
-                    (scan_directory (current_stat_info.file_name, dev, false));
+  dumpdir_buffer = directory_contents (scan_directory (&current_stat_info));
 
   if (dumpdir_buffer)
     {
@@ -397,6 +398,10 @@ diff_multivol (void)
   struct stat stat_data;
   int fd, status;
   off_t offset;
+  int atime_flag =
+    (atime_preserve_option == system_atime_preserve
+     ? O_NOATIME
+     : 0);
 
   if (current_stat_info.had_trailing_slash)
     {
@@ -422,7 +427,10 @@ diff_multivol (void)
       return;
     }
 
-  fd = open (current_stat_info.file_name, O_RDONLY | O_BINARY);
+
+  fd = open (current_stat_info.file_name,
+            (O_RDONLY | O_BINARY | O_CLOEXEC | O_NOCTTY | O_NONBLOCK
+             | atime_flag));
 
   if (fd < 0)
     {
This page took 0.023347 seconds and 4 git commands to generate.