builds now
This commit is contained in:
		
							parent
							
								
									4ac80cfcec
								
							
						
					
					
						commit
						5c76824e14
					
				
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,2 +1,2 @@ | ||||
| src/*.pb.go | ||||
| /mfer | ||||
| mfer/*.pb.go | ||||
| /mfer.cmd | ||||
|  | ||||
							
								
								
									
										13
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								Makefile
									
									
									
									
									
								
							| @ -7,12 +7,11 @@ ARCH := $(shell uname -m) | ||||
| VERSION := $(shell git describe --always --dirty=-dirty) | ||||
| 
 | ||||
| GOLDFLAGS += -X main.Version=$(VERSION) | ||||
| GOLDFLAGS += -X main.Buildarch=$(ARCH) | ||||
| GOFLAGS := -ldflags "$(GOLDFLAGS)" | ||||
| 
 | ||||
| default: run | ||||
| 
 | ||||
| run: ./mfer | ||||
| run: ./mfer.cmd | ||||
| 	./$< | ||||
| 	./$< gen | ||||
| 
 | ||||
| @ -23,16 +22,16 @@ devprereqs: | ||||
| 	which gofumpt || go install -v mvdan.cc/gofumpt@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 | ||||
| 	cd src && go generate . | ||||
| 	cd cmd/mfer && go build -o ../../mfer $(GOFLAGS) . | ||||
| 	cd mfer && go generate . | ||||
| 	cd cmd/mfer && go build -o ../../mfer.cmd $(GOFLAGS) . | ||||
| 
 | ||||
| clean: | ||||
| 	rm -rfv src/*.pb.go ./mfer | ||||
| 	rm -rfv mfer/*.pb.go ./mfer | ||||
| 
 | ||||
| fmt: prereqs | ||||
| 	gofumpt -l -w src cmd | ||||
| 	gofumpt -l -w mfer internal cmd | ||||
| 	golangci-lint run --fix | ||||
| 	prettier -w *.json *.md | ||||
| 
 | ||||
|  | ||||
| @ -3,15 +3,14 @@ package main | ||||
| import ( | ||||
| 	"os" | ||||
| 
 | ||||
| 	mfer "git.eeqj.de/sneak/mfer/src" | ||||
| 	"git.eeqj.de/sneak/mfer/internal/cli" | ||||
| ) | ||||
| 
 | ||||
| var ( | ||||
| 	Appname   string = "mfer" | ||||
| 	Version   string | ||||
| 	Buildarch string | ||||
| 	Appname string = "mfer" | ||||
| 	Version string | ||||
| ) | ||||
| 
 | ||||
| func main() { | ||||
| 	os.Exit(mfer.Run(Appname, Version, Buildarch)) | ||||
| 	os.Exit(cli.Run(Appname, Version)) | ||||
| } | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| package mfer | ||||
| package cli | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
| @ -13,11 +13,10 @@ func init() { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func Run(Appname, Version, Buildarch string) int { | ||||
| 	m := &mfer{} | ||||
| func Run(Appname, Version string) int { | ||||
| 	m := &CLIApp{} | ||||
| 	m.appname = Appname | ||||
| 	m.version = Version | ||||
| 	m.buildarch = Buildarch | ||||
| 	m.exitCode = 0 | ||||
| 
 | ||||
| 	m.run() | ||||
							
								
								
									
										51
									
								
								internal/cli/manifest.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								internal/cli/manifest.go
									
									
									
									
									
										Normal 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 | ||||
| } | ||||
| 
 | ||||
| */ | ||||
| @ -1,4 +1,4 @@ | ||||
| package mfer | ||||
| package cli | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| @ -10,7 +10,7 @@ import ( | ||||
| 	"github.com/urfave/cli/v2" | ||||
| ) | ||||
| 
 | ||||
| type mfer struct { | ||||
| type CLIApp struct { | ||||
| 	appname     string | ||||
| 	version     string | ||||
| 	buildarch   string | ||||
| @ -20,12 +20,12 @@ type mfer struct { | ||||
| 	app         *cli.App | ||||
| } | ||||
| 
 | ||||
| func (m *mfer) printBanner() { | ||||
| func (m *CLIApp) printBanner() { | ||||
| 	s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(m.appname)).Srender() | ||||
| 	pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter
 | ||||
| } | ||||
| 
 | ||||
| func (m *mfer) disableStyling() { | ||||
| func (m *CLIApp) disableStyling() { | ||||
| 	pterm.DisableColor() | ||||
| 	pterm.DisableStyling() | ||||
| 	pterm.Debug.Prefix.Text = "" | ||||
| @ -36,7 +36,7 @@ func (m *mfer) disableStyling() { | ||||
| 	pterm.Fatal.Prefix.Text = "" | ||||
| } | ||||
| 
 | ||||
| func (m *mfer) run() { | ||||
| func (m *CLIApp) run() { | ||||
| 
 | ||||
| 	if NO_COLOR { | ||||
| 		// 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") | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (m *mfer) generateManifestOperation(c *cli.Context) error { | ||||
| func (m *CLIApp) generateManifestOperation(c *cli.Context) error { | ||||
| 	fmt.Println("generateManifest()") | ||||
| 	mgj, err := NewMFGenerationJobFromFilesystem(c.String("input")) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 		return err | ||||
| 	} | ||||
| 	mgj.scanForFiles() | ||||
| 	//mgj.outputFile = c.String("output")
 | ||||
| 	fmt.Printf("called with arg: %s", c.String("input")) | ||||
| 
 | ||||
| 	/* | ||||
| 
 | ||||
| 		mgj, err := NewMFGenerationJobFromFilesystem(c.String("input")) | ||||
| 		if err != nil { | ||||
| 			log.Fatal(err) | ||||
| 			return err | ||||
| 		} | ||||
| 		mgj.scanForFiles() | ||||
| 		//mgj.outputFile = c.String("output")
 | ||||
| 
 | ||||
| 	*/ | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										46
									
								
								mfer/manifest.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								mfer/manifest.go
									
									
									
									
									
										Normal 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 | ||||
| } | ||||
| @ -14,12 +14,12 @@ message MFFile { | ||||
|     } | ||||
| 
 | ||||
|     // required mffile root attributes 1xx | ||||
|     Version version = 101; | ||||
|     bytes innerMessage = 102; | ||||
|     Version version = 1; | ||||
|     bytes innerMessage = 2; | ||||
|     // these are used solely to detect corruption/truncation | ||||
|     // and not for cryptographic integrity. | ||||
|     int64 size = 103; | ||||
|     bytes sha256 = 104; | ||||
|     int64 size = 3; | ||||
|     bytes sha256 = 4; | ||||
| 
 | ||||
|     // 2xx for optional manifest root attributes | ||||
|     // think we might use gosignify instead of gpg: | ||||
| @ -35,18 +35,17 @@ message MFFile { | ||||
| 
 | ||||
| message MFFilePath { | ||||
|     // required attributes: | ||||
|     string path = 101; | ||||
|     int64 size = 102; | ||||
|     string path = 1; | ||||
|     int64 size = 2; | ||||
| 
 | ||||
|     // gotta have at least one: | ||||
|     repeated MFFileChecksum hashes = 201; | ||||
|     repeated MFFileChecksum hashes = 3; | ||||
| 
 | ||||
|     // optional per-file metadata | ||||
|     optional string mimeType = 301; | ||||
|     optional Timestamp mtime = 302; | ||||
|     optional Timestamp ctime = 303; | ||||
|     optional Timestamp atime = 304; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| message MFFileChecksum { | ||||
| @ -60,11 +59,10 @@ message MFFileInner { | ||||
|         NONE = 0; | ||||
|         ONE = 1; // only one for now | ||||
|     } | ||||
|     Version version = 101; | ||||
|     Version version = 1; | ||||
| 
 | ||||
|     // required manifest attributes: | ||||
|     int64 fileCount = 102; //FIXME is this necessary? | ||||
|     repeated MFFilePath files = 103; | ||||
|     repeated MFFilePath files = 2; | ||||
| 
 | ||||
|     // optional manifest attributes 2xx: | ||||
|     optional Timestamp createdAt = 201; | ||||
							
								
								
									
										13
									
								
								mfer/mfer_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								mfer/mfer_test.go
									
									
									
									
									
										Normal 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) { | ||||
| 
 | ||||
| } | ||||
| @ -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 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user