On Tuesday 27 September 2005 14:54, Paul Eggert wrote:
> Ian Turner <[EMAIL PROTECTED]> writes:
> > OK. Here's a revised patch.
>
> Sorry, one wasn't included in your message. Could you please
> resend the message to bug-tar, with the patch included? Thanks.
Done.
> > I wasn't sure about the right way to document the --atime-preserve
> > option. Right now I define the argument as "replace|=system", so that
> > --help shows --atime-preserve[=replace|=system]. But this strikes me as a
> > hack. Let me know if you have a better idea.
>
> I'd suggest using a metavariable, e.g., --atime-preserve[=METHOD].
Done.
diff -aur --exclude='*.m4' --exclude=Makefile.in tar-1.15.1/doc/tar.texi tar-1.15.1-noatime/doc/tar.texi
--- tar-1.15.1/doc/tar.texi 2004-12-18 11:20:19.000000000 -0800
+++ tar-1.15.1-noatime/doc/tar.texi 2005-09-27 15:22:10.000000000 -0700
@@ -119,7 +119,9 @@
@set xref-append @xref{add}
@set pxref-append @pxref{add}
[EMAIL PROTECTED] op-atime-preserve @kbd{--atime-preserve}
[EMAIL PROTECTED] op-atime-preserve @kbd{--atime-preserve[=METHOD]}
[EMAIL PROTECTED] op-atime-preserve-replace @kbd{--atime-preserve=replace}
[EMAIL PROTECTED] op-atime-preserve-system @kbd{--atime-preserve=system}
@set ref-atime-preserve @ref{Attributes}
@set xref-atime-preserve @xref{Attributes}
@set pxref-atime-preserve @pxref{Attributes}
@@ -2661,15 +2663,32 @@
@FIXME-xref{}
@item --atime-preserve
[EMAIL PROTECTED] --atime-preserve=replace
[EMAIL PROTECTED] --atime-preserve=system
Tells @command{tar} to preserve the access time field in a file's inode when
-reading it. Due to limitations in the @code{utimes} system call, the
+reading it. This option is only effective on files that you own,
+unless you're root.
+
+There are two different modes of
+operation.. @value{op-atime-preserve-replace} (the default) uses the
[EMAIL PROTECTED] system call. Due to limitations in this call, the
modification time field is also preserved, which may cause problems if
the file is simultaneously being modified by another program.
This option is incompatible with incremental backups, because
-preserving the access time involves updating the last-changed time.
[EMAIL PROTECTED] will update the last-changed time.
Also, this option does not work on files that you do not own,
unless you're root.
+
[EMAIL PROTECTED] does not have any of the limitations
+of @value{op-atime-preserve-replace}: That is, it will avoid changing
+the atime in the first place, without touching the mtime or ctime, and
+without interfering with any updates caused by other
+programs. However, it may not work at all if your platform or
+filesystem does not support the O_NOATIME system call. Worse, at this
+time there is no way to know in all cases if this option is supported or
+not. Sometimes tar knows for sure, in which case it will complain and
+exit right away.
@FIXME-xref{}
@item [EMAIL PROTECTED]
@@ -5300,7 +5319,7 @@
Incremental dumps depend crucially on time stamps, so the results are
unreliable if you modify a file's time stamps during dumping (e.g.@:
-with the @samp{--atime-preserve} option), or if you set the clock
+with the @samp{--atime-preserve=replace} option), or if you set the clock
backwards.
Despite it should be obvious that a device has a non-volatile value, NFS
@@ -7392,20 +7411,31 @@
@UNREVISED
When @command{tar} reads files, this causes them to have the access
-times updated. To have @command{tar} attempt to set the access times
-back to what they were before they were read, use the
[EMAIL PROTECTED] option.
+times updated. To avoid this, use the @value{op-atime-preserve} option,
+which can either reset the atime retroactively or avoid changing it in
+the first place, depending on system support.
Handling of file attributes
@table @kbd
@item --atime-preserve
-Preserve access times on files that are read.
-This doesn't work for files that
-you don't own, unless you're root, and it doesn't interact with
[EMAIL PROTECTED] --atime-preserve=replace
[EMAIL PROTECTED] --atime-preserve=system
+Don't change the access time on files that are read.
+This doesn't work for files that you don't own, unless you're root.
+
[EMAIL PROTECTED] (the default if a specific variant
+is not chosen) works on most systems, but resets the ctime instead of
+the atime. Because of this, it doesn't interact with
incremental dumps nicely (@pxref{Backups}), and it can set access or
modification times incorrectly if other programs access the file while
[EMAIL PROTECTED] is running; but it is good enough for some purposes.
[EMAIL PROTECTED] is running.
+
[EMAIL PROTECTED] avoids changing the atime in the
+first place, by opening files with the O_NOATIME system call. However,
+this may or may not work on any given operating system or
+filesystem. If tar knows for sure it won't work. it wil complain right
+away.
@item -m
@itemx --touch
diff -aur --exclude='*.m4' --exclude=Makefile.in tar-1.15.1/lib/system.h tar-1.15.1-noatime/lib/system.h
--- tar-1.15.1/lib/system.h 2004-09-06 06:49:42.000000000 -0700
+++ tar-1.15.1-noatime/lib/system.h 2005-09-26 19:25:52.000000000 -0700
@@ -114,6 +114,13 @@
# define O_BINARY 0
#endif
+/* Check if we have O_NOATIME */
+#ifdef O_NOATIME
+# define HAVE_O_NOATIME (1)
+#else
+# define O_NOATIME (0)
+#endif
+
/* Declare file status routines and bits. */
#include <sys/stat.h>
diff -aur --exclude='*.m4' --exclude=Makefile.in tar-1.15.1/src/common.h tar-1.15.1-noatime/src/common.h
--- tar-1.15.1/src/common.h 2004-12-21 06:31:58.000000000 -0800
+++ tar-1.15.1-noatime/src/common.h 2005-09-26 19:45:56.000000000 -0700
@@ -133,7 +133,14 @@
than newer_mtime_option. */
GLOBAL int after_date_option;
-GLOBAL bool atime_preserve_option;
+enum atime_preserve {
+ DONT_ATIME_PRESERVE,
+ REPLACE_ATIME_PRESERVE,
+ SYSTEM_ATIME_PRESERVE /*,
+ HEURISTIC_ATIME_PRESERVE <-- Later. */
+};
+
+GLOBAL enum atime_preserve atime_preserve_option;
GLOBAL bool backup_option;
diff -aur --exclude='*.m4' --exclude=Makefile.in tar-1.15.1/src/compare.c tar-1.15.1-noatime/src/compare.c
--- tar-1.15.1/src/compare.c 2004-09-06 04:30:29.000000000 -0700
+++ tar-1.15.1-noatime/src/compare.c 2005-09-26 19:36:32.000000000 -0700
@@ -263,7 +263,10 @@
goto quit;
}
- diff_handle = open (current_stat_info.file_name, O_RDONLY | O_BINARY);
+ diff_handle = open (current_stat_info.file_name,
+ O_RDONLY | O_BINARY |
+ (atime_preserve_option == SYSTEM_ATIME_PRESERVE ?
+ O_NOATIME : 0));
if (diff_handle < 0)
{
@@ -299,7 +302,7 @@
if (status != 0)
close_error (current_stat_info.file_name);
- if (atime_preserve_option)
+ if (atime_preserve_option == REPLACE_ATIME_PRESERVE)
utime (current_stat_info.file_name, &restore_times);
quit:
diff -aur --exclude='*.m4' --exclude=Makefile.in tar-1.15.1/src/create.c tar-1.15.1-noatime/src/create.c
--- tar-1.15.1/src/create.c 2004-10-04 02:21:31.000000000 -0700
+++ tar-1.15.1-noatime/src/create.c 2005-09-26 19:36:18.000000000 -0700
@@ -1400,7 +1400,7 @@
if (S_ISDIR (st->stat.st_mode))
{
dump_dir (st, top_level, parent_device);
- if (atime_preserve_option)
+ if (atime_preserve_option == REPLACE_ATIME_PRESERVE)
utime (p, &restore_times);
return;
}
@@ -1423,7 +1423,9 @@
if (file_dumpable_p (st))
{
fd = open (st->orig_file_name,
- O_RDONLY | O_BINARY);
+ O_RDONLY | O_BINARY |
+ ( atime_preserve_option == SYSTEM_ATIME_PRESERVE ?
+ O_NOATIME : 0));
if (fd < 0)
{
if (!top_level && errno == ENOENT)
@@ -1468,7 +1470,7 @@
abort ();
}
- if (atime_preserve_option)
+ if (atime_preserve_option == REPLACE_ATIME_PRESERVE)
utime (st->orig_file_name, &restore_times);
file_count_links (st);
return;
diff -aur --exclude='*.m4' --exclude=Makefile.in tar-1.15.1/src/tar.c tar-1.15.1-noatime/src/tar.c
--- tar-1.15.1/src/tar.c 2004-12-21 06:11:26.000000000 -0800
+++ tar-1.15.1-noatime/src/tar.c 2005-09-27 15:22:27.000000000 -0700
@@ -332,8 +332,14 @@
N_("force NAME as group for added files"), 31 },
{"mode", MODE_OPTION, N_("CHANGES"), 0,
N_("force (symbolic) mode CHANGES for added files"), 31 },
- {"atime-preserve", ATIME_PRESERVE_OPTION, 0, 0,
+#ifdef HAVE_O_NOATIME
+ {"atime-preserve", ATIME_PRESERVE_OPTION, N_("METHOD"),
+ OPTION_ARG_OPTIONAL,
N_("don't change access times on dumped files"), 31 },
+#else
+ {"atime-preserve", ATIME_PRESERVE_OPTION, 0, OPTION_ARG_OPTIONAL,
+ N_("reset access times on dumped files"), 31 },
+#endif
{"touch", 'm', 0, 0,
N_("don't extract file modified time"), 31 },
{"same-owner", SAME_OWNER_OPTION, 0, 0,
@@ -919,7 +925,21 @@
break;
case ATIME_PRESERVE_OPTION:
- atime_preserve_option = true;
+
+ if (arg) {
+ if (strcasecmp("replace", arg) == 0)
+ atime_preserve_option = REPLACE_ATIME_PRESERVE;
+#ifdef HAVE_O_NOATIME
+ else if (strcasecmp("system", arg) == 0)
+ atime_preserve_option = SYSTEM_ATIME_PRESERVE;
+#endif
+ else
+ USAGE_ERROR ((0, 0,
+ _("Invalid --atime-preserve option %s"), arg));
+ } else {
+ atime_preserve_option = REPLACE_ATIME_PRESERVE;
+ }
+
break;
case CHECKPOINT_OPTION:
_______________________________________________
Bug-tar mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-tar