|
|
@ -2,6 +2,7 @@ package backend |
|
|
|
|
|
|
|
import ( |
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog" |
|
|
|
. "github.com/chrislusf/seaweedfs/weed/storage/types" |
|
|
|
"os" |
|
|
|
"time" |
|
|
|
) |
|
|
@ -22,11 +23,15 @@ func NewDiskFile(f *os.File) *DiskFile { |
|
|
|
if err != nil { |
|
|
|
glog.Fatalf("stat file %s: %v", f.Name(), err) |
|
|
|
} |
|
|
|
offset := stat.Size() |
|
|
|
if offset%NeedlePaddingSize != 0 { |
|
|
|
offset = offset + (NeedlePaddingSize - offset%NeedlePaddingSize) |
|
|
|
} |
|
|
|
|
|
|
|
return &DiskFile{ |
|
|
|
fullFilePath: f.Name(), |
|
|
|
File: f, |
|
|
|
fileSize: stat.Size(), |
|
|
|
fileSize: offset, |
|
|
|
modTime: stat.ModTime(), |
|
|
|
} |
|
|
|
} |
|
|
@ -47,6 +52,10 @@ func (df *DiskFile) WriteAt(p []byte, off int64) (n int, err error) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func (df *DiskFile) Append(p []byte) (n int, err error) { |
|
|
|
return df.WriteAt(p, df.fileSize) |
|
|
|
} |
|
|
|
|
|
|
|
func (df *DiskFile) Truncate(off int64) error { |
|
|
|
err := df.File.Truncate(off) |
|
|
|
if err == nil { |
|
|
|
xxxxxxxxxx