diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-10-25 00:11:25 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-10-25 00:11:25 -0700 |
| commit | 7a51a9a5823576aa540684aac6424b5793a9e285 (patch) | |
| tree | 3a13456362488745fba5722332a76bfaed6ea727 /weed/storage/volume_super_block.go | |
| parent | 46ed2ca902e4a29ca7e8eb9ca2fc14c896cf2584 (diff) | |
| download | seaweedfs-7a51a9a5823576aa540684aac6424b5793a9e285.tar.xz seaweedfs-7a51a9a5823576aa540684aac6424b5793a9e285.zip | |
refactor: simplifying to ReadAt() and WriteAt()
Diffstat (limited to 'weed/storage/volume_super_block.go')
| -rw-r--r-- | weed/storage/volume_super_block.go | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/weed/storage/volume_super_block.go b/weed/storage/volume_super_block.go index 2c2553666..cb34a2347 100644 --- a/weed/storage/volume_super_block.go +++ b/weed/storage/volume_super_block.go @@ -92,7 +92,7 @@ func (v *Volume) maybeWriteSuperBlock() error { } if stat.Size() == 0 { v.SuperBlock.version = needle.CurrentVersion - _, e = v.dataFile.Write(v.SuperBlock.Bytes()) + _, e = v.dataFile.WriteAt(v.SuperBlock.Bytes(), 0) if e != nil && os.IsPermission(e) { //read-only, but zero length - recreate it! if v.dataFile, e = os.Create(v.dataFile.Name()); e == nil { @@ -123,11 +123,7 @@ func ReadSuperBlock(dataFile *os.File) (superBlock SuperBlock, err error) { return } } else { - if _, err = dataFile.Seek(0, 0); err != nil { - err = fmt.Errorf("cannot seek to the beginning of %s: %v", dataFile.Name(), err) - return - } - if _, e := dataFile.Read(header); e != nil { + if _, e := dataFile.ReadAt(header, 0); e != nil { err = fmt.Errorf("cannot read volume %s super block: %v", dataFile.Name(), e) return } |
