Skip to content

Commit

Permalink
more go-ish
Browse files Browse the repository at this point in the history
  • Loading branch information
dav-m85 committed Sep 11, 2022
1 parent ab0690f commit 2db85fe
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cmd/convert.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"crypto/sha1"
Expand Down
48 changes: 24 additions & 24 deletions main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"path/filepath"
"time"

"github.com/dav-m85/hashsnap/core"
"github.com/dav-m85/hashsnap"
"github.com/google/uuid"
bar "github.com/schollz/progressbar/v3"
)
Expand Down Expand Up @@ -89,13 +89,13 @@ func main() {
}
if spath == "" {
var err error
spath, err = core.LookupFrom(wd)
spath, err = hashsnap.LookupFrom(wd)
if err != nil {
panic(err)
}
}
if spath == "" {
spath = filepath.Join(wd, core.STATE_NAME)
spath = filepath.Join(wd, hashsnap.STATE_NAME)
}

// Main command switch
Expand Down Expand Up @@ -124,7 +124,7 @@ main:

case trimCmd.Name():
var withsNonce []uuid.UUID
var i *core.Info
var i *hashsnap.Info
if i, err = readInfo(spath); err != nil {
break
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func create(spy io.Writer) error {
enc := gob.NewEncoder(f)

// Write info node
err = enc.Encode(core.Info{
err = enc.Encode(hashsnap.Info{
Version: 1,
RootPath: wd,
CreatedAt: time.Now(),
Expand All @@ -217,18 +217,18 @@ func create(spy io.Writer) error {
defer cleanup()

skipper := func(n fs.FileInfo) bool {
return !n.Mode().IsDir() && (!n.Mode().IsRegular() || n.Size() == 0 || n.Name() == core.STATE_NAME)
return !n.Mode().IsDir() && (!n.Mode().IsRegular() || n.Size() == 0 || n.Name() == hashsnap.STATE_NAME)
}

// ⛲️ Source by exploring all nodes
files, err := core.WalkFS(ctx, skipper, wd)
files, err := hashsnap.WalkFS(ctx, skipper, wd)
if err != nil {
return err
}

// 🏭 Hash them all and write hashes to statefile
var c int
for x := range core.Hasher(ctx, wd, spy, files) {
for x := range hashsnap.Hasher(ctx, wd, spy, files) {
c++
if err := enc.Encode(x); err != nil {
return err
Expand All @@ -251,13 +251,13 @@ func info() error {

dec := gob.NewDecoder(f)

i := new(core.Info)
i := new(hashsnap.Info)
if err = dec.Decode(i); err != nil {
return err
}
fmt.Fprintf(output, "%s\n", i)

nodes := &core.DecoderIterator{
nodes := &hashsnap.DecoderIterator{
Decoder: dec,
}

Expand All @@ -268,18 +268,18 @@ func info() error {
var count int64

if verbose {
t := core.NewTree(i)
t := hashsnap.NewTree(i)
if err := t.ReadIterator(nodes); err != nil {
return fmt.Errorf("statefile %s nodes error: %w", spath, err)
}
ti := core.NewTreeIterator(t)
ti := hashsnap.NewTreeIterator(t)
for ti.Next() {
n := ti.Node()
if n.Mode.IsDir() {
continue
}

fmt.Fprintf(output, "\t%s %s\n", color.Green+t.RelPath(n)+color.Reset, core.ByteSize(n.Size)) // children is not up to date here
fmt.Fprintf(output, "\t%s %s\n", color.Green+t.RelPath(n)+color.Reset, hashsnap.ByteSize(n.Size)) // children is not up to date here

size = size + n.Size
count++
Expand All @@ -298,11 +298,11 @@ func info() error {
}
}

fmt.Fprintf(output, "Totalling %s and %d files\n", core.ByteSize(size), count)
fmt.Fprintf(output, "Totalling %s and %d files\n", hashsnap.ByteSize(size), count)
return nil
}

func readTree(path string) (*core.Tree, error) {
func readTree(path string) (*hashsnap.Tree, error) {
f, err := os.OpenFile(path, os.O_RDONLY, 0666)
if err != nil {
return nil, err
Expand All @@ -311,16 +311,16 @@ func readTree(path string) (*core.Tree, error) {

dec := gob.NewDecoder(f)

i := new(core.Info)
i := new(hashsnap.Info)
if err = dec.Decode(i); err != nil {
return nil, err
}

nodes := &core.DecoderIterator{
nodes := &hashsnap.DecoderIterator{
Decoder: dec,
}

t := core.NewTree(i)
t := hashsnap.NewTree(i)

if err := t.ReadIterator(nodes); err != nil {
return nil, err
Expand All @@ -329,7 +329,7 @@ func readTree(path string) (*core.Tree, error) {
return t, nil
}

func readInfo(path string) (*core.Info, error) {
func readInfo(path string) (*hashsnap.Info, error) {
f, err := os.OpenFile(path, os.O_RDONLY, 0666)
if err != nil {
return nil, err
Expand All @@ -338,7 +338,7 @@ func readInfo(path string) (*core.Info, error) {

dec := gob.NewDecoder(f)

i := new(core.Info)
i := new(hashsnap.Info)
if err = dec.Decode(i); err != nil {
return nil, err
}
Expand All @@ -347,13 +347,13 @@ func readInfo(path string) (*core.Info, error) {
}

func trim(delete bool, withs ...string) error {
matches := make(core.HashGroup)
matches := make(hashsnap.HashGroup)

cur, err := readTree(spath)
if err != nil {
return err
}
if err := core.Each(core.NewTreeIterator(cur), matches.Add); err != nil {
if err := hashsnap.Each(hashsnap.NewTreeIterator(cur), matches.Add); err != nil {
return err
}

Expand All @@ -362,7 +362,7 @@ func trim(delete bool, withs ...string) error {
if err != nil {
return err
}
if err := core.Each(core.NewTreeIterator(x), matches.Intersect); err != nil {
if err := hashsnap.Each(hashsnap.NewTreeIterator(x), matches.Intersect); err != nil {
return err
}
}
Expand Down Expand Up @@ -401,6 +401,6 @@ func trim(delete bool, withs ...string) error {
waste = waste + int64(g.WastedSize())
}

fmt.Fprintf(output, "%d duplicated groups, totalling %s wasted space\n", count, core.ByteSize(waste))
fmt.Fprintf(output, "%d duplicated groups, totalling %s wasted space\n", count, hashsnap.ByteSize(waste))
return nil
}
2 changes: 1 addition & 1 deletion core/filewalker.go → filewalker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion core/fs.go → fs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import "os"

Expand Down
2 changes: 1 addition & 1 deletion core/group.go → group.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"crypto/sha1"
Expand Down
2 changes: 1 addition & 1 deletion core/group_test.go → group_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"crypto/sha1"
Expand Down
2 changes: 1 addition & 1 deletion core/hasher.go → hasher.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion core/iterator.go → iterator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion core/lookup.go → lookup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ clean:
rm build/arm5/hashsnap

build/arm5/hashsnap:
GOARM=5 GOARCH=arm go build -o $@ main.go
GOARM=5 GOARCH=arm go build -o $@ cmd/main.go
2 changes: 1 addition & 1 deletion core/node.go → node.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"crypto/sha1"
Expand Down
2 changes: 1 addition & 1 deletion core/test.go → test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

var F func(t *Tree, path string, content string)
var expect func(t *Tree, path string)
Expand Down
2 changes: 1 addition & 1 deletion core/tree.go → tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion core/units.go → units.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package core
package hashsnap

import "fmt"

Expand Down

0 comments on commit 2db85fe

Please sign in to comment.