diff options
Diffstat (limited to 'libgo/go/archive/zip/struct.go')
-rw-r--r-- | libgo/go/archive/zip/struct.go | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/libgo/go/archive/zip/struct.go b/libgo/go/archive/zip/struct.go index 67e96586294..35dcec6468b 100644 --- a/libgo/go/archive/zip/struct.go +++ b/libgo/go/archive/zip/struct.go @@ -57,8 +57,8 @@ type FileHeader struct { } // FileInfo returns an os.FileInfo for the FileHeader. -func (fh *FileHeader) FileInfo() os.FileInfo { - return headerFileInfo{fh} +func (h *FileHeader) FileInfo() os.FileInfo { + return headerFileInfo{h} } // headerFileInfo implements os.FileInfo. @@ -71,6 +71,7 @@ func (fi headerFileInfo) Size() int64 { return int64(fi.fh.UncompressedSi func (fi headerFileInfo) IsDir() bool { return fi.Mode().IsDir() } func (fi headerFileInfo) ModTime() time.Time { return fi.fh.ModTime() } func (fi headerFileInfo) Mode() os.FileMode { return fi.fh.Mode() } +func (fi headerFileInfo) Sys() interface{} { return fi.fh } // FileInfoHeader creates a partially-populated FileHeader from an // os.FileInfo. @@ -151,13 +152,20 @@ func (h *FileHeader) SetModTime(t time.Time) { h.ModifiedDate, h.ModifiedTime = timeToMsDosTime(t) } -// traditional names for Unix constants const ( - s_IFMT = 0xf000 - s_IFDIR = 0x4000 - s_IFREG = 0x8000 - s_ISUID = 0x800 - s_ISGID = 0x400 + // Unix constants. The specification doesn't mention them, + // but these seem to be the values agreed on by tools. + s_IFMT = 0xf000 + s_IFSOCK = 0xc000 + s_IFLNK = 0xa000 + s_IFREG = 0x8000 + s_IFBLK = 0x6000 + s_IFDIR = 0x4000 + s_IFCHR = 0x2000 + s_IFIFO = 0x1000 + s_ISUID = 0x800 + s_ISGID = 0x400 + s_ISVTX = 0x200 msdosDir = 0x10 msdosReadOnly = 0x01 @@ -205,10 +213,23 @@ func msdosModeToFileMode(m uint32) (mode os.FileMode) { func fileModeToUnixMode(mode os.FileMode) uint32 { var m uint32 - if mode&os.ModeDir != 0 { - m = s_IFDIR - } else { + switch mode & os.ModeType { + default: m = s_IFREG + case os.ModeDir: + m = s_IFDIR + case os.ModeSymlink: + m = s_IFLNK + case os.ModeNamedPipe: + m = s_IFIFO + case os.ModeSocket: + m = s_IFSOCK + case os.ModeDevice: + if mode&os.ModeCharDevice != 0 { + m = s_IFCHR + } else { + m = s_IFBLK + } } if mode&os.ModeSetuid != 0 { m |= s_ISUID @@ -216,13 +237,29 @@ func fileModeToUnixMode(mode os.FileMode) uint32 { if mode&os.ModeSetgid != 0 { m |= s_ISGID } + if mode&os.ModeSticky != 0 { + m |= s_ISVTX + } return m | uint32(mode&0777) } func unixModeToFileMode(m uint32) os.FileMode { - var mode os.FileMode - if m&s_IFMT == s_IFDIR { + mode := os.FileMode(m & 0777) + switch m & s_IFMT { + case s_IFBLK: + mode |= os.ModeDevice + case s_IFCHR: + mode |= os.ModeDevice | os.ModeCharDevice + case s_IFDIR: mode |= os.ModeDir + case s_IFIFO: + mode |= os.ModeNamedPipe + case s_IFLNK: + mode |= os.ModeSymlink + case s_IFREG: + // nothing to do + case s_IFSOCK: + mode |= os.ModeSocket } if m&s_ISGID != 0 { mode |= os.ModeSetgid @@ -230,5 +267,8 @@ func unixModeToFileMode(m uint32) os.FileMode { if m&s_ISUID != 0 { mode |= os.ModeSetuid } - return mode | os.FileMode(m&0777) + if m&s_ISVTX != 0 { + mode |= os.ModeSticky + } + return mode } |