mirror of
https://github.com/vbatts/dedupe-linker.git
synced 2024-11-15 21:28:37 +00:00
filling out base functionality
This commit is contained in:
parent
842fa03b61
commit
aa6273d315
3 changed files with 37 additions and 13 deletions
33
base/base.go
33
base/base.go
|
@ -1,24 +1,41 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func InitVarBase(base string) error {
|
||||
for _, path := range []string{"dedup/blobs", "dedup/state"} {
|
||||
if err := os.MkdirAll(filepath.Join(base, path), 0755); err != nil {
|
||||
return err
|
||||
func NewBase(path string, hashName string) (*Base, error) {
|
||||
for _, p := range []string{"dedup/blobs" + hashName, "dedup/state"} {
|
||||
if err := os.MkdirAll(filepath.Join(path, p), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return &Base{Path: path, HashName: hashName}, nil
|
||||
}
|
||||
|
||||
type Base struct {
|
||||
Path string
|
||||
Path string
|
||||
HashName string
|
||||
}
|
||||
|
||||
func (b Base) HasBlob(hashType crypto.Hash, sum string) bool {
|
||||
// GetBlob store the content from src, for the sum and hashType
|
||||
func (b Base) GetBlob(sum string) (io.Reader, error) {
|
||||
// XXX
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// PutBlob store the content from src, for the sum and hashType
|
||||
//
|
||||
// we take the sum up front to avoid recalculation and tempfiles
|
||||
func (b Base) PutBlob(sum string, src io.Reader) error {
|
||||
// XXX
|
||||
return nil
|
||||
}
|
||||
|
||||
// HasBlob tests whether a blob with this sum exists
|
||||
func (b Base) HasBlob(sum string) bool {
|
||||
// XXX
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package cryptomap
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
|
@ -10,6 +10,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var knownCiphers = map[string]crypto.Hash{
|
||||
"md5": crypto.MD5,
|
||||
}
|
||||
|
||||
func DetermineHash(str string) (h crypto.Hash) {
|
||||
switch strings.ToLower(str) {
|
||||
case "md5":
|
11
main.go
11
main.go
|
@ -9,6 +9,7 @@ import (
|
|||
"runtime"
|
||||
|
||||
"./base"
|
||||
"./cryptomap"
|
||||
"./file"
|
||||
)
|
||||
|
||||
|
@ -27,13 +28,15 @@ func init() {
|
|||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if err := base.InitVarBase(*flVarBase); err != nil {
|
||||
|
||||
// TODO the *flCipher has not been checked yet, and would cause the directory to get created
|
||||
ourbase, err := base.NewBase(*flVarBase, *flCipher)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var (
|
||||
hash = DetermineHash(*flCipher)
|
||||
ourbase = base.Base{Path: *flVarBase}
|
||||
hash = cryptomap.DetermineHash(*flCipher)
|
||||
//infos = []*file.FileHashInfo{}
|
||||
//mu = sync.Mutex{}
|
||||
//results := make(chan file.FileHashInfo, 2)
|
||||
|
@ -55,7 +58,7 @@ func main() {
|
|||
done <- struct{}{}
|
||||
}
|
||||
fmt.Printf("%s %s\n", fi.Hash, fi.Path)
|
||||
if ourbase.HasBlob(fi.HashType, fi.Hash) {
|
||||
if ourbase.HasBlob(fi.Hash) {
|
||||
// TODO check if they have the same Inode
|
||||
// if not, then clobber
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue