func populateHeaderCtime(h *tar.Header, fi os.FileInfo, _ map[uint64]string) { st, ok := fi.Sys().(*syscall.Stat_t) if !ok { return } sec, nsec := st.Ctimespec.Unix() ctime := time.Unix(sec, nsec) h.ChangeTime = ctime }
// fills tar.Header missing information (uid/gid, username/groupname, times ...) func FillHeader(hdr *tar.Header) { var cuname string cuid := os.Getuid() if curr, err := user.LookupId(fmt.Sprintf("%d", cuid)); err == nil { cuname = curr.Username } if hdr.Uid == 0 { if hdr.Uname == "" { hdr.Uid = cuid hdr.Uname = cuname } else { if usr, err := user.Lookup(hdr.Uname); err == nil { if i, err := fmt.Sscanf("%d", usr.Uid); err == nil { hdr.Uid = i hdr.Uname = usr.Username } } } } if hdr.Gid == 0 { if hdr.Gname == "" { if hdr.Uid != 0 { if usr, err := user.LookupId(fmt.Sprintf("%d", hdr.Uid)); err == nil { if i, err := fmt.Sscanf("%d", usr.Gid); err == nil { hdr.Gid = i } } } } } if hdr.ModTime.IsZero() { hdr.ModTime = time.Now() } if hdr.AccessTime.IsZero() { hdr.AccessTime = hdr.ModTime } if hdr.ChangeTime.IsZero() { hdr.ChangeTime = hdr.ModTime } }