-
Notifications
You must be signed in to change notification settings - Fork 18k
archive/tar: doesn't generate atime entries #17876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I played with this a bit, and it looks like the issue is that currently we're generating diff --git a/src/archive/tar/writer.go b/src/archive/tar/writer.go
index 596fb8b9e171..0d866d3fbf4a 100644
--- a/src/archive/tar/writer.go
+++ b/src/archive/tar/writer.go
@@ -145,11 +145,17 @@ func (tw *Writer) writeHeader(hdr *Header, allowPax bool) error {
f.formatNumeric(b, x)
}
- // Handle out of range ModTime carefully.
- var modTime int64
+ // Handle out of range ModTime, AccessTime, and ChangeTime carefully.
+ var modTime, accessTime, changeTime int64
if !hdr.ModTime.Before(minTime) && !hdr.ModTime.After(maxTime) {
modTime = hdr.ModTime.Unix()
}
+ if !hdr.AccessTime.Before(minTime) && !hdr.AccessTime.After(maxTime) {
+ accessTime = hdr.AccessTime.Unix()
+ }
+ if !hdr.ChangeTime.Before(minTime) && !hdr.ChangeTime.After(maxTime) {
+ changeTime = hdr.ChangeTime.Unix()
+ }
v7 := header.V7()
formatString(v7.Name(), hdr.Name, paxPath)
@@ -169,6 +175,9 @@ func (tw *Writer) writeHeader(hdr *Header, allowPax bool) error {
formatString(ustar.GroupName(), hdr.Gname, paxGname)
formatNumeric(ustar.DevMajor(), hdr.Devmajor, paxNone)
formatNumeric(ustar.DevMinor(), hdr.Devminor, paxNone)
+ // TODO: This doesn't work because we output USTAR rather than STAR or GNU.
+ //formatNumeric(ustar.AccessTime(), accessTime, paxAtime)
+ //formatNumeric(utar.ChangeTime(), changeTime, paxCtime)
// TODO(dsnet): The logic surrounding the prefix field is broken when trying
// to encode the header as GNU format. The challenge with the current logic |
I plan on overhauling the Writer logic in Go 1.9 and I have a fix for this. Thanks for the report. |
Change https://golang.org/cl/55570 mentions this issue: |
Change https://golang.org/cl/59230 mentions this issue: |
Nearly every Header obtained from FileInfoHeader via the FS has timestamps with sub-second resolution and the AccessTime and ChangeTime fields populated. This forces the PAX format to almost always be used, which has the following problems: * PAX is still not as widely supported compared to USTAR * The PAX headers will occupy at minimum 1KiB for every entry The old behavior of tar Writer had no support for sub-second resolution nor any support for AccessTime or ChangeTime, so had neither problem. Instead the Writer would just truncate sub-second information and ignore the AccessTime and ChangeTime fields. In this CL, we preserve the behavior such that the *default* behavior would output a USTAR header for most cases by truncating sub-second time measurements and ignoring AccessTime and ChangeTime. To use either of the features, users will need to explicitly specify that the format is PAX or GNU. The exact policy chosen is this: * USTAR and GNU may still be chosen even if sub-second measurements are present; they simply truncate the timestamp to the nearest second. As before, PAX uses sub-second resolutions. * If the Format is unspecified, then WriteHeader ignores AccessTime and ChangeTime when using the USTAR format. This ensures that USTAR may still be chosen for a vast majority of file entries obtained through FileInfoHeader. Updates #11171 Updates #17876 Change-Id: Icc5274d4245922924498fd79b8d3ae94d5717271 Reviewed-on: https://go-review.googlesource.com/59230 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This also happens on https://play.golang.org/, which you can see in this snippet: https://play.golang.org/p/QURChe1JI_.
What did you expect to see?
No errors in the above program.
What did you see instead?
From what I can tell, this is caused by the fact that
WriteHeader
doesn't in any way touch theAccessTime
of the structure. The same goes for theChangeTime
.The text was updated successfully, but these errors were encountered: