refactor: Use PAX headers directly instead of protobuf for encoding action info

This commit is contained in:
Felicitas Pojtinger
2021-11-19 00:26:58 +01:00
parent f00532db6a
commit f41c96b59e
+11 -16
View File
@@ -5,7 +5,6 @@ package main
import ( import (
"archive/tar" "archive/tar"
"bufio" "bufio"
"encoding/base64"
"flag" "flag"
"io" "io"
"io/fs" "io/fs"
@@ -17,9 +16,7 @@ import (
"time" "time"
"unsafe" "unsafe"
api "github.com/pojntfx/stfs/pkg/api/proto/v1"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"google.golang.org/protobuf/proto"
) )
// See https://github.com/benmcclelland/mtio // See https://github.com/benmcclelland/mtio
@@ -28,9 +25,15 @@ const (
MTEOM = 12 // Goto end of recorded media (for appending files) MTEOM = 12 // Goto end of recorded media (for appending files)
MTBSR = 4 // Backward space record MTBSR = 4 // Backward space record
STFSVersion = 1
STFSVersionPAX = "STFS.Version" STFSVersionPAX = "STFS.Version"
STFSHeaderPAX = "STFS.Header" STFSVersion = 1
STFSActionPAX = "STFS.Action"
STFSActionCreate = "CREATE"
STFSActionUpdate = "UPDATE"
STFSActionDelete = "DELETE"
STFSReplacesPAX = "STFS.Replaces"
blockSize = 512 blockSize = 512
) )
@@ -134,19 +137,11 @@ func main() {
hdr.Devmajor = int64(unix.Major(unixStat.Dev)) hdr.Devmajor = int64(unix.Major(unixStat.Dev))
hdr.Devminor = int64(unix.Minor(unixStat.Dev)) hdr.Devminor = int64(unix.Minor(unixStat.Dev))
stfsHeader := &api.Header{
Action: api.Action_CREATE,
}
encodedHeader, err := proto.Marshal(stfsHeader)
if err != nil {
return err
}
hdr.Name = path hdr.Name = path
hdr.PAXRecords = map[string]string{ hdr.PAXRecords = map[string]string{
STFSVersionPAX: strconv.Itoa(STFSVersion), STFSVersionPAX: strconv.Itoa(STFSVersion),
STFSHeaderPAX: base64.StdEncoding.EncodeToString(encodedHeader), STFSActionPAX: STFSActionUpdate,
STFSReplacesPAX: "",
} }
hdr.Format = tar.FormatPAX hdr.Format = tar.FormatPAX