forked from External/grumble
Update for Go 1.
This commit is contained in:
parent
4114a83d64
commit
e46a65109f
31 changed files with 901 additions and 202 deletions
|
|
@ -42,7 +42,7 @@ func (r *blobReader) Read(b []byte) (n int, err error) {
|
|||
if err != io.EOF {
|
||||
return
|
||||
}
|
||||
if !bytes.Equal(r.sum, r.hash.Sum()) {
|
||||
if !bytes.Equal(r.sum, r.hash.Sum(nil)) {
|
||||
err = ErrHashMismatch
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -14,11 +14,12 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type BlobStore struct {
|
||||
dir string
|
||||
lockfn string
|
||||
dir string
|
||||
lockfn string
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
@ -117,8 +118,9 @@ func NewBlobStore(path string) (bs *BlobStore, err error) {
|
|||
dirStructureExists = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bsf.Close()
|
||||
}
|
||||
bsf.Close()
|
||||
|
||||
if !dirStructureExists {
|
||||
for i := 0; i < 256; i++ {
|
||||
|
|
@ -132,7 +134,7 @@ func NewBlobStore(path string) (bs *BlobStore, err error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !fi.IsDirectory() {
|
||||
if !fi.IsDir() {
|
||||
return nil, ErrBadFile
|
||||
}
|
||||
} else if e.Err == os.ENOTDIR {
|
||||
|
|
@ -152,7 +154,7 @@ func NewBlobStore(path string) (bs *BlobStore, err error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !fi.IsDirectory() {
|
||||
if !fi.IsDir() {
|
||||
return nil, ErrBadFile
|
||||
}
|
||||
} else if e.Err == os.ENOTDIR {
|
||||
|
|
@ -174,8 +176,8 @@ func NewBlobStore(path string) (bs *BlobStore, err error) {
|
|||
}
|
||||
|
||||
bs = &BlobStore{
|
||||
dir: path,
|
||||
lockfn: lockfn,
|
||||
dir: path,
|
||||
lockfn: lockfn,
|
||||
}
|
||||
return bs, nil
|
||||
}
|
||||
|
|
@ -256,7 +258,7 @@ func (bs *BlobStore) Put(buf []byte) (key string, err error) {
|
|||
// disk.
|
||||
h := sha1.New()
|
||||
h.Write(buf)
|
||||
key = hex.EncodeToString(h.Sum())
|
||||
key = hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
// Get the components that make up the on-disk
|
||||
// path for the blob.
|
||||
|
|
@ -319,7 +321,7 @@ func (bs *BlobStore) Put(buf []byte) (key string, err error) {
|
|||
// On Unix, it checks for EEXIST. On Windows, it checks for EEXIST
|
||||
// and Errno code 183 (ERROR_ALREADY_EXISTS)
|
||||
func isExistError(err *os.PathError) (exists bool) {
|
||||
if e, ok := err.Err.(os.Errno); ok && e == win32AlreadyExists {
|
||||
if e, ok := err.Err.(syscall.Errno); ok && e == win32AlreadyExists {
|
||||
exists = true
|
||||
}
|
||||
if err.Err == os.EEXIST {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func TestMakeAllCreateAll(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !fi.IsDirectory() {
|
||||
if !fi.IsDir() {
|
||||
t.Errorf("Not a directory")
|
||||
}
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ func TestReadNonExistantKey(t *testing.T) {
|
|||
|
||||
h := sha1.New()
|
||||
h.Write([]byte{0x42})
|
||||
key := hex.EncodeToString(h.Sum())
|
||||
key := hex.EncodeToString(h.Sum(nil))
|
||||
buf, err := bs.Get(key)
|
||||
if err != ErrNoSuchKey {
|
||||
t.Error("Expected no such key %v, found it anyway. (buf=%v, err=%v)", key, buf, err)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (c) 2011 The Grumble Authors
|
||||
// The use of this source code is goverened by a BSD-style
|
||||
// license that can be found in the LICENSE-file.
|
||||
// Copyright (c) 2011 The Grumble Authors
|
||||
// The use of this source code is goverened by a BSD-style
|
||||
// license that can be found in the LICENSE-file.
|
||||
|
||||
package blobstore
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
// Acquire lockfile at path.
|
||||
// Acquire lockfile at path.
|
||||
func AcquireLockFile(path string) error {
|
||||
dir, fn := filepath.Split(path)
|
||||
lockfn := filepath.Join(dir, fn)
|
||||
|
|
@ -26,7 +26,8 @@ func AcquireLockFile(path string) error {
|
|||
|
||||
pid, err := strconv.Atoi(string(content))
|
||||
if err == nil {
|
||||
if syscall.Kill(pid, 0) == 0 {
|
||||
err = syscall.Kill(pid, 0)
|
||||
if err != nil {
|
||||
return ErrLocked
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +68,7 @@ func AcquireLockFile(path string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Release lockfile at path.
|
||||
// Release lockfile at path.
|
||||
func ReleaseLockFile(path string) error {
|
||||
return os.Remove(path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue