mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
archive/zip: read and write unix file modes
R=golang-dev, rsc, adg CC=golang-dev https://golang.org/cl/5124044
This commit is contained in:
parent
d53afb8d83
commit
ecda69e667
5 changed files with 86 additions and 15 deletions
|
|
@ -26,6 +26,7 @@ type ZipTestFile struct {
|
|||
Content []byte // if blank, will attempt to compare against File
|
||||
File string // name of file to compare to (relative to testdata/)
|
||||
Mtime string // modified time in format "mm-dd-yy hh:mm:ss"
|
||||
Mode uint32
|
||||
}
|
||||
|
||||
// Caution: The Mtime values found for the test files should correspond to
|
||||
|
|
@ -47,11 +48,13 @@ var tests = []ZipTest{
|
|||
Name: "test.txt",
|
||||
Content: []byte("This is a test text file.\n"),
|
||||
Mtime: "09-05-10 12:12:02",
|
||||
Mode: 0x81a4,
|
||||
},
|
||||
{
|
||||
Name: "gophercolor16x16.png",
|
||||
File: "gophercolor16x16.png",
|
||||
Mtime: "09-05-10 15:52:58",
|
||||
Mode: 0x81a4,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -162,6 +165,8 @@ func readTestFile(t *testing.T, ft ZipTestFile, f *File) {
|
|||
t.Errorf("%s: mtime=%s (%d); want %s (%d)", f.Name, time.SecondsToUTC(got), got, mtime, want)
|
||||
}
|
||||
|
||||
testFileMode(t, f, ft.Mode)
|
||||
|
||||
size0 := f.UncompressedSize
|
||||
|
||||
var b bytes.Buffer
|
||||
|
|
@ -203,6 +208,19 @@ func readTestFile(t *testing.T, ft ZipTestFile, f *File) {
|
|||
}
|
||||
}
|
||||
|
||||
func testFileMode(t *testing.T, f *File, want uint32) {
|
||||
mode, err := f.Mode()
|
||||
if want == 0 {
|
||||
if err == nil {
|
||||
t.Errorf("%s mode: got %v, want none", f.Name, mode)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Errorf("%s mode: %s", f.Name, err)
|
||||
} else if mode != want {
|
||||
t.Errorf("%s mode: want 0x%x, got 0x%x", f.Name, want, mode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidFiles(t *testing.T) {
|
||||
const size = 1024 * 70 // 70kb
|
||||
b := make([]byte, size)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue