feat: Add support for UNIX-specific tar info

This commit is contained in:
Felix Pojtinger
2021-11-14 20:24:17 +01:00
parent 004ef4ea3d
commit e3f038c119
6 changed files with 27 additions and 32 deletions
-7
View File
@@ -8,7 +8,6 @@ import (
"bytes"
"context"
"database/sql"
"encoding/json"
"flag"
"fmt"
"io"
@@ -118,11 +117,6 @@ func main() {
break
}
paxRecords, err := json.Marshal(hdr.PAXRecords)
if err != nil {
panic(err)
}
dbhdr := &models.Header{
Typeflag: int64(hdr.Typeflag),
Name: hdr.Name,
@@ -138,7 +132,6 @@ func main() {
Changetime: hdr.ChangeTime,
Devmajor: hdr.Devmajor,
Devminor: hdr.Devminor,
Paxrecords: string(paxRecords),
Format: int64(hdr.Format),
Record: int64(record),
Block: int64(i),
+21 -1
View File
@@ -9,7 +9,10 @@ import (
"os"
"path/filepath"
"syscall"
"time"
"unsafe"
"golang.org/x/sys/unix"
)
// See https://github.com/benmcclelland/mtio
@@ -90,6 +93,24 @@ func main() {
return err
}
hdr.Format = tar.FormatGNU // Required for AccessTime, ChangeTime etc.
var unixStat syscall.Stat_t
if err := syscall.Stat(path, &unixStat); err != nil {
return err
}
mtimesec, mtimensec := unixStat.Mtim.Unix()
atimesec, atimensec := unixStat.Atim.Unix()
ctimesec, ctimensec := unixStat.Ctim.Unix()
hdr.ModTime = time.Unix(mtimesec, mtimensec)
hdr.AccessTime = time.Unix(atimesec, atimensec)
hdr.ChangeTime = time.Unix(ctimesec, ctimensec)
hdr.Devmajor = int64(unix.Major(unixStat.Dev))
hdr.Devminor = int64(unix.Minor(unixStat.Dev))
hdr.Name = path
log.Println(hdr)
@@ -98,7 +119,6 @@ func main() {
return err
}
// Skip writing non-regular files
if !info.Mode().IsRegular() {
return nil
}