do not truncate file if any error happens. Truncating will lose all

files after this file entry.
This commit is contained in:
Chris Lu 2013-02-11 22:54:46 -08:00
parent 2ca983b6d8
commit b395a5289b

View file

@ -143,17 +143,9 @@ func (v *Volume) delete(n *Needle) (uint32, error) {
nv, ok := v.nm.Get(n.Id)
//fmt.Println("key", n.Id, "volume offset", nv.Offset, "data_size", n.Size, "cached size", nv.Size)
if ok {
if err := v.nm.Delete(n.Id); err != nil {
return 0, err
}
offset, err := v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)
if err != nil {
return 0, fmt.Errorf("cannot get datafile (%s) position: %s", v.dataFile, err)
}
if _, err = n.Append(v.dataFile, v.Version()); err != nil {
v.dataFile.Truncate(offset)
return 0, err
}
v.nm.Delete(n.Id)
v.dataFile.Seek(int64(nv.Offset*NeedlePaddingSize), 0)
_, err := n.Append(v.dataFile, v.Version())
return nv.Size, err
}
return 0, nil