refactor functions

This commit is contained in:
Chris Lu 2014-03-23 21:57:10 -07:00
parent b1f083cb60
commit a0955aa4dd
3 changed files with 6 additions and 1 deletions

View file

@ -14,6 +14,9 @@ type FileId struct {
Hashcode uint32 Hashcode uint32
} }
func NewFileIdFromNeedle(VolumeId VolumeId, n *Needle) *FileId {
return &FileId{VolumeId: VolumeId, Key: n.Id, Hashcode: n.Cookie}
}
func NewFileId(VolumeId VolumeId, Key uint64, Hashcode uint32) *FileId { func NewFileId(VolumeId VolumeId, Key uint64, Hashcode uint32) *FileId {
return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode} return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode}
} }

View file

@ -208,6 +208,7 @@ func (v *Volume) Destroy() (err error) {
} }
func (v *Volume) write(n *Needle) (size uint32, err error) { func (v *Volume) write(n *Needle) (size uint32, err error) {
glog.V(4).Infof("writing needle %s", NewFileIdFromNeedle(v.Id, n).String())
if v.readOnly { if v.readOnly {
err = fmt.Errorf("%s is read-only", v.dataFile) err = fmt.Errorf("%s is read-only", v.dataFile)
return return
@ -249,6 +250,7 @@ func (v *Volume) write(n *Needle) (size uint32, err error) {
} }
func (v *Volume) delete(n *Needle) (uint32, error) { func (v *Volume) delete(n *Needle) (uint32, error) {
glog.V(4).Infof("delete needle %s", NewFileIdFromNeedle(v.Id, n).String())
if v.readOnly { if v.readOnly {
return 0, fmt.Errorf("%s is read-only", v.dataFile) return 0, fmt.Errorf("%s is read-only", v.dataFile)
} }

View file

@ -130,7 +130,7 @@ type nameParams struct {
} }
func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (err error) { func walker(vid storage.VolumeId, n *storage.Needle, version storage.Version) (err error) {
key := storage.NewFileId(vid, n.Id, n.Cookie).String() key := storage.NewFileIdFromNeedle(vid, n).String()
if tarFh != nil { if tarFh != nil {
fnTmplBuf.Reset() fnTmplBuf.Reset()
if err = fnTmpl.Execute(fnTmplBuf, if err = fnTmpl.Execute(fnTmplBuf,