dedupe-linker/base/base.go

50 lines
1.0 KiB
Go
Raw Normal View History

2014-09-12 20:10:10 +00:00
package base
import (
2014-09-16 21:12:52 +00:00
"io"
2014-09-12 20:10:10 +00:00
"os"
"path/filepath"
)
2014-09-16 21:12:52 +00:00
func NewBase(path string, hashName string) (*Base, error) {
2014-09-17 13:21:56 +00:00
root := filepath.Join(path, "dedup")
for _, p := range []string{"blobs/" + hashName, "state"} {
if err := os.MkdirAll(filepath.Join(root, p), 0755); err != nil {
2014-09-16 21:12:52 +00:00
return nil, err
2014-09-12 20:10:10 +00:00
}
}
2014-09-17 13:21:56 +00:00
return &Base{Path: root, HashName: hashName}, nil
2014-09-12 20:10:10 +00:00
}
type Base struct {
2014-09-16 21:12:52 +00:00
Path string
HashName string
}
2014-09-17 13:21:56 +00:00
func (b Base) blobPath(sum string) string {
if len(sum) < 3 {
return ""
}
return filepath.Join(b.Path, "blobs", b.HashName, sum[0:2], sum)
}
2014-09-16 21:12:52 +00:00
// 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
2014-09-12 20:10:10 +00:00
}
2014-09-16 21:12:52 +00:00
// HasBlob tests whether a blob with this sum exists
func (b Base) HasBlob(sum string) bool {
// XXX
2014-09-12 20:10:10 +00:00
return true
}