builds now

This commit is contained in:
Jeffrey Paul 2022-12-02 01:31:49 +01:00
parent 4ac80cfcec
commit 5c76824e14
11 changed files with 153 additions and 112 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
src/*.pb.go mfer/*.pb.go
/mfer /mfer.cmd

View File

@ -7,12 +7,11 @@ ARCH := $(shell uname -m)
VERSION := $(shell git describe --always --dirty=-dirty) VERSION := $(shell git describe --always --dirty=-dirty)
GOLDFLAGS += -X main.Version=$(VERSION) GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildarch=$(ARCH)
GOFLAGS := -ldflags "$(GOLDFLAGS)" GOFLAGS := -ldflags "$(GOLDFLAGS)"
default: run default: run
run: ./mfer run: ./mfer.cmd
./$< ./$<
./$< gen ./$< gen
@ -23,16 +22,16 @@ devprereqs:
which gofumpt || go install -v mvdan.cc/gofumpt@latest which gofumpt || go install -v mvdan.cc/gofumpt@latest
which golangci-lint || go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest which golangci-lint || go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
mfer: $(PROTOC_GEN_GO) src/*.go cmd/*/*.go mfer.cmd: $(PROTOC_GEN_GO) mfer/*.go internal/*/*.go cmd/*/*.go
protoc --version protoc --version
cd src && go generate . cd mfer && go generate .
cd cmd/mfer && go build -o ../../mfer $(GOFLAGS) . cd cmd/mfer && go build -o ../../mfer.cmd $(GOFLAGS) .
clean: clean:
rm -rfv src/*.pb.go ./mfer rm -rfv mfer/*.pb.go ./mfer
fmt: prereqs fmt: prereqs
gofumpt -l -w src cmd gofumpt -l -w mfer internal cmd
golangci-lint run --fix golangci-lint run --fix
prettier -w *.json *.md prettier -w *.json *.md

View File

@ -3,15 +3,14 @@ package main
import ( import (
"os" "os"
mfer "git.eeqj.de/sneak/mfer/src" "git.eeqj.de/sneak/mfer/internal/cli"
) )
var ( var (
Appname string = "mfer" Appname string = "mfer"
Version string Version string
Buildarch string
) )
func main() { func main() {
os.Exit(mfer.Run(Appname, Version, Buildarch)) os.Exit(cli.Run(Appname, Version))
} }

View File

@ -1,4 +1,4 @@
package mfer package cli
import ( import (
"os" "os"
@ -13,11 +13,10 @@ func init() {
} }
} }
func Run(Appname, Version, Buildarch string) int { func Run(Appname, Version string) int {
m := &mfer{} m := &CLIApp{}
m.appname = Appname m.appname = Appname
m.version = Version m.version = Version
m.buildarch = Buildarch
m.exitCode = 0 m.exitCode = 0
m.run() m.run()

51
internal/cli/manifest.go Normal file
View File

@ -0,0 +1,51 @@
package cli
import (
"git.eeqj.de/sneak/mfer/mfer"
"github.com/spf13/afero"
)
type Job struct {
innerpb *mfer.MFFileInner
outerpb *mfer.MFFile
fileCount int64
totalSize int64
afs afero.Fs
}
func (m *Job) scanForFiles() error {
m.innerpb = &mfer.MFFileInner{}
m.innerpb.Version = mfer.MFFileInner_ONE
return nil
}
/*
walkErr := filepath.Walk(m.sourcePath, func(itemPath string, info os.FileInfo, err error) error {
// we do not include the manifest file in the manifest
if itemPath == "index.mf" {
return nil
}
fpi := mfer.MFFilePath{}
fpi.Path = itemPath
fpi.Size = info.Size()
m.innerpb.Files = append(m.innerpb.Files, &fpi)
m.fileCount++
m.totalSize += fpi.Size
return nil
})
if walkErr != nil {
log.Fatal(walkErr)
return walkErr
}
fmt.Printf("%#v\n", m.innerpb)
fmt.Printf("filecount = %#v\n", m.fileCount)
fmt.Printf("totalsize = %#v\n", m.totalSize)
return nil
}
*/

View File

@ -1,4 +1,4 @@
package mfer package cli
import ( import (
"fmt" "fmt"
@ -10,7 +10,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
type mfer struct { type CLIApp struct {
appname string appname string
version string version string
buildarch string buildarch string
@ -20,12 +20,12 @@ type mfer struct {
app *cli.App app *cli.App
} }
func (m *mfer) printBanner() { func (m *CLIApp) printBanner() {
s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(m.appname)).Srender() s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(m.appname)).Srender()
pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter
} }
func (m *mfer) disableStyling() { func (m *CLIApp) disableStyling() {
pterm.DisableColor() pterm.DisableColor()
pterm.DisableStyling() pterm.DisableStyling()
pterm.Debug.Prefix.Text = "" pterm.Debug.Prefix.Text = ""
@ -36,7 +36,7 @@ func (m *mfer) disableStyling() {
pterm.Fatal.Prefix.Text = "" pterm.Fatal.Prefix.Text = ""
} }
func (m *mfer) run() { func (m *CLIApp) run() {
if NO_COLOR { if NO_COLOR {
// shoutout to rob pike who thinks it's juvenile // shoutout to rob pike who thinks it's juvenile
@ -91,20 +91,25 @@ func (m *mfer) run() {
} }
} }
func (m *mfer) validateManifestOperation(c *cli.Context) error { func (m *CLIApp) validateManifestOperation(c *cli.Context) error {
log.Fatal("unimplemented") log.Fatal("unimplemented")
return nil return nil
} }
func (m *mfer) generateManifestOperation(c *cli.Context) error { func (m *CLIApp) generateManifestOperation(c *cli.Context) error {
fmt.Println("generateManifest()") fmt.Println("generateManifest()")
mgj, err := NewMFGenerationJobFromFilesystem(c.String("input")) fmt.Printf("called with arg: %s", c.String("input"))
if err != nil {
log.Fatal(err)
return err
}
mgj.scanForFiles()
//mgj.outputFile = c.String("output")
/*
mgj, err := NewMFGenerationJobFromFilesystem(c.String("input"))
if err != nil {
log.Fatal(err)
return err
}
mgj.scanForFiles()
//mgj.outputFile = c.String("output")
*/
return nil return nil
} }

46
mfer/manifest.go Normal file
View File

@ -0,0 +1,46 @@
package mfer
import (
"io"
"io/fs"
"github.com/spf13/afero"
)
type ManifestFile struct {
Path string
FileInfo fs.FileInfo
}
type Manifest struct {
SourceFS afero.Fs
Files []*ManifestFile
}
func NewFromPath(inputPath string) (*Manifest, error) {
afs := afero.NewBasePathFs(afero.NewOsFs(), inputPath)
return NewFromFilesystem(afs)
}
func NewFromFilesystem(fs afero.Fs) (*Manifest, error) {
m := &Manifest{
SourceFS: fs,
}
m.Scan()
return m, nil
}
func (m *Manifest) Scan() {
afero.Walk(m.SourceFS, "", func(path string, info fs.FileInfo, err error) error {
nf := &ManifestFile{
Path: path,
FileInfo: info,
}
m.Files = append(m.Files, nf)
return nil
})
}
func (m *Manifest) Write(output io.Writer) error {
return nil
}

View File

@ -14,12 +14,12 @@ message MFFile {
} }
// required mffile root attributes 1xx // required mffile root attributes 1xx
Version version = 101; Version version = 1;
bytes innerMessage = 102; bytes innerMessage = 2;
// these are used solely to detect corruption/truncation // these are used solely to detect corruption/truncation
// and not for cryptographic integrity. // and not for cryptographic integrity.
int64 size = 103; int64 size = 3;
bytes sha256 = 104; bytes sha256 = 4;
// 2xx for optional manifest root attributes // 2xx for optional manifest root attributes
// think we might use gosignify instead of gpg: // think we might use gosignify instead of gpg:
@ -35,18 +35,17 @@ message MFFile {
message MFFilePath { message MFFilePath {
// required attributes: // required attributes:
string path = 101; string path = 1;
int64 size = 102; int64 size = 2;
// gotta have at least one: // gotta have at least one:
repeated MFFileChecksum hashes = 201; repeated MFFileChecksum hashes = 3;
// optional per-file metadata // optional per-file metadata
optional string mimeType = 301; optional string mimeType = 301;
optional Timestamp mtime = 302; optional Timestamp mtime = 302;
optional Timestamp ctime = 303; optional Timestamp ctime = 303;
optional Timestamp atime = 304; optional Timestamp atime = 304;
} }
message MFFileChecksum { message MFFileChecksum {
@ -60,11 +59,10 @@ message MFFileInner {
NONE = 0; NONE = 0;
ONE = 1; // only one for now ONE = 1; // only one for now
} }
Version version = 101; Version version = 1;
// required manifest attributes: // required manifest attributes:
int64 fileCount = 102; //FIXME is this necessary? repeated MFFilePath files = 2;
repeated MFFilePath files = 103;
// optional manifest attributes 2xx: // optional manifest attributes 2xx:
optional Timestamp createdAt = 201; optional Timestamp createdAt = 201;

13
mfer/mfer_test.go Normal file
View File

@ -0,0 +1,13 @@
package mfer
import "testing"
// Add those variables as well
var (
existingFolder = "./testdata/a-folder-that-exists"
nonExistingFolder = "./testdata/a-folder-that-does-not-exists"
)
func TestManifestGeneration(t *testing.T) {
}

View File

@ -1,69 +0,0 @@
package mfer
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/spf13/afero"
)
type MFGenerationJob struct {
sourcePath string
outputFile string
innerpb *MFFileInner
outerpb *MFFile
fileCount int64
totalSize int64
afs afero.Fs
}
func NewMFGenerationJobFromFilesystem(sourcePath string) (*MFGenerationJob, error) {
afs := afero.NewOsFs()
exists, err := afero.DirExists(afs, sourcePath)
if err != nil {
return nil, err
}
if !exists {
return nil, fmt.Errorf("source directory does not exist")
}
mgj := MFGenerationJob{}
mgj.afs = afs
mgj.sourcePath = sourcePath
return &mgj, nil
}
func (m *MFGenerationJob) scanForFiles() error {
m.innerpb = &MFFileInner{}
m.innerpb.Version = MFFileInner_ONE
walkErr := filepath.Walk(m.sourcePath, func(itemPath string, info os.FileInfo, err error) error {
// we do not include the manifest file in the manifest
if itemPath == "index.mf" {
return nil
}
fpi := MFFilePath{}
fpi.Path = itemPath
fpi.Size = info.Size()
m.innerpb.Files = append(m.innerpb.Files, &fpi)
m.fileCount++
m.totalSize += fpi.Size
return nil
})
if walkErr != nil {
log.Fatal(walkErr)
return walkErr
}
fmt.Printf("%#v\n", m.innerpb)
fmt.Printf("filecount = %#v\n", m.fileCount)
fmt.Printf("totalsize = %#v\n", m.totalSize)
return nil
}