func getEntryTypeString(e *os.FileInfo) string { if e.IsDirectory() { return "/" } else if e.IsBlock() { return "<>" } else if e.IsFifo() { return ">>" } else if e.IsSymlink() { return "@" } else if e.IsSocket() { return "&" } else if e.IsRegular() && (e.Mode&0001 == 0001) { return "*" } return "" }
func NewCommonFileMap(fileName string, fi *os.FileInfo) map[string]interface{} { m := NewCommonFilenameMap(fileName) // Common elements (from file-common.txt) if !fi.IsSymlink() { m["unixPermission"] = fmt.Sprintf("0%o", fi.Permission()) } if fi.Uid != -1 { m["unixOwnerId"] = fi.Uid if user := getUserFromUid(fi.Uid); user != "" { m["unixOwner"] = user } } if fi.Gid != -1 { m["unixGroupId"] = fi.Gid if group := getGroupFromGid(fi.Gid); group != "" { m["unixGroup"] = group } } if mtime := fi.Mtime_ns; mtime != 0 { m["unixMtime"] = RFC3339FromNanos(mtime) } // Include the ctime too, if it differs. if ctime := fi.Ctime_ns; ctime != 0 && fi.Mtime_ns != fi.Ctime_ns { m["unixCtime"] = RFC3339FromNanos(ctime) } return m }
func (p *Propolis) SetRequestMetaData(req *http.Request, info *os.FileInfo) { // file permissions: grant "public-read" if the file grants world read permission if info.Permission()&s_iroth != 0 { req.Header.Set("X-Amz-Acl", acl_public) } else { req.Header.Set("X-Amz-Acl", acl_private) } // user id: store the numeric and symbolic names user, err := user.LookupId(info.Uid) if err != nil { req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d", info.Uid)) } else { req.Header.Set("X-Amz-Meta-Uid", fmt.Sprintf("%d (%s)", info.Uid, user.Username)) } // group id: just store the numeric id for now until Go supports looking up group names req.Header.Set("X-Amz-Meta-Gid", fmt.Sprintf("%d", info.Gid)) // store the permissions as an octal number req.Header.Set("X-Amz-Meta-Mode", fmt.Sprintf("0%o", info.Mode)) // store the modified date in a nice format sec := info.Mtime_ns / 1e9 ns := info.Mtime_ns % 1e9 date := time.SecondsToLocalTime(sec).String() if ns == 0 { req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d (%s)", sec, date)) } else { req.Header.Set("X-Amz-Meta-Mtime", fmt.Sprintf("%d.%09d (%s)", sec, ns, date)) } // set the content-type by looking up the MIME type mimetype := default_mime_type switch { case info.IsDirectory(): mimetype = directory_mime_type case info.IsSymlink(): mimetype = symlink_mime_type default: if dot := strings.LastIndex(info.Name, "."); dot >= 0 && dot+1 < len(info.Name) { extension := strings.ToLower(info.Name[dot:]) if kind := mime.TypeByExtension(extension); kind != "" { mimetype = kind } } } req.Header.Set("Content-Type", mimetype) }
func symbol(f *os.FileInfo) (s string) { switch { case f.IsDirectory(): s = "/" case f.IsFifo(): s = "|" case f.IsSocket(): s = "=" case f.IsSymlink(): target, err := os.Readlink(f.Name) Errhandler(err) s = " -> " + target } return }