diff options
Diffstat (limited to 'src/pkg/archive/tar/common.go')
-rw-r--r-- | src/pkg/archive/tar/common.go | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/pkg/archive/tar/common.go b/src/pkg/archive/tar/common.go index 60d207c48..1b961e3ec 100644 --- a/src/pkg/archive/tar/common.go +++ b/src/pkg/archive/tar/common.go @@ -13,6 +13,7 @@ package tar import ( + "bytes" "errors" "fmt" "os" @@ -82,9 +83,9 @@ func (fi headerFileInfo) Sys() interface{} { return fi.h } // Name returns the base name of the file. func (fi headerFileInfo) Name() string { if fi.IsDir() { - return path.Clean(fi.h.Name) + return path.Base(path.Clean(fi.h.Name)) } - return fi.h.Name + return path.Base(fi.h.Name) } // Mode returns the permission and mode bits for the headerFileInfo. @@ -174,9 +175,29 @@ const ( c_ISSOCK = 0140000 // Socket ) +// Keywords for the PAX Extended Header +const ( + paxAtime = "atime" + paxCharset = "charset" + paxComment = "comment" + paxCtime = "ctime" // please note that ctime is not a valid pax header. + paxGid = "gid" + paxGname = "gname" + paxLinkpath = "linkpath" + paxMtime = "mtime" + paxPath = "path" + paxSize = "size" + paxUid = "uid" + paxUname = "uname" + paxNone = "" +) + // FileInfoHeader creates a partially-populated Header from fi. // If fi describes a symlink, FileInfoHeader records link as the link target. // If fi describes a directory, a slash is appended to the name. +// Because os.FileInfo's Name method returns only the base name of +// the file it describes, it may be necessary to modify the Name field +// of the returned header to provide the full path name of the file. func FileInfoHeader(fi os.FileInfo, link string) (*Header, error) { if fi == nil { return nil, errors.New("tar: FileInfo is nil") @@ -257,3 +278,25 @@ func (sp *slicer) next(n int) (b []byte) { b, *sp = s[0:n], s[n:] return } + +func isASCII(s string) bool { + for _, c := range s { + if c >= 0x80 { + return false + } + } + return true +} + +func toASCII(s string) string { + if isASCII(s) { + return s + } + var buf bytes.Buffer + for _, c := range s { + if c < 0x80 { + buf.WriteByte(byte(c)) + } + } + return buf.String() +} |