-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It turns out Chtimes does not affect the parent directory mtime, because no matter how I order the tar headers for root and subdirectories, it doesn't seem to matter which order I restore the timestamps in. I included a test to ensure this is true in the CI platform (linux)
- Loading branch information
Showing
8 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Builds the `subdir-appears-first.tar.gz` test dependency for TestUnpack_HeaderOrdering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"archive/tar" | ||
"compress/gzip" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
w, err := os.Create("../subdir-appears-first.tar.gz") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer w.Close() | ||
|
||
gzipW, err := gzip.NewWriterLevel(w, gzip.BestSpeed) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer gzipW.Close() | ||
|
||
tarW := tar.NewWriter(gzipW) | ||
defer tarW.Close() | ||
|
||
// The order of headers to write to the output file | ||
targets := []string{ | ||
"super/duper", | ||
"super/duper/trooper", | ||
"super", | ||
"super/duper/trooper/foo.txt", | ||
} | ||
|
||
for _, t := range targets { | ||
info, err := os.Stat(t) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
header := &tar.Header{ | ||
Format: tar.FormatUnknown, | ||
Name: t, | ||
ModTime: info.ModTime(), | ||
Mode: int64(info.Mode()), | ||
} | ||
|
||
switch { | ||
case info.IsDir(): | ||
header.Typeflag = tar.TypeDir | ||
header.Name += "/" | ||
default: | ||
header.Typeflag = tar.TypeReg | ||
header.Size = info.Size() | ||
} | ||
|
||
// Write the header first to the archive. | ||
if err := tarW.WriteHeader(header); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Added %q, unix nano mtime %d / %d\n", header.Name, info.ModTime().Unix(), info.ModTime().UnixNano()) | ||
|
||
if info.IsDir() { | ||
continue | ||
} | ||
|
||
f, err := os.Open(t) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
_, err = io.Copy(tarW, f) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
fmt.Printf("Copy these values into the | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
placeholder |