Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
fix(dfget): add err handling in dfget
Browse files Browse the repository at this point in the history
Signed-off-by: hwdef <[email protected]>
  • Loading branch information
hwdef committed Sep 19, 2019
1 parent 266923d commit e317d52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dfget/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ func (suite *ConfigSuite) TestProperties_Load(c *check.C) {
for idx, v := range cases {
filename := filepath.Join(dirName, fmt.Sprintf("%d.%s", idx, v.ext))
if v.create {
ioutil.WriteFile(filename, []byte(v.content), os.ModePerm)
err := ioutil.WriteFile(filename, []byte(v.content), os.ModePerm)
c.Assert(err, check.IsNil)
}
p := &Properties{}
err := p.Load(filename)
Expand Down
3 changes: 2 additions & 1 deletion dfget/config/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func (suite *ConfigSuite) TestMetaData(c *check.C) {
err := meta.Persist()
if v.e != nil {
c.Assert(err, check.IsNil)
meta.Load()
err := meta.Load()
c.Assert(err, check.IsNil)
v.e.MetaPath = v.path
c.Assert(v.e, check.DeepEquals, meta)
} else {
Expand Down
8 changes: 6 additions & 2 deletions dfget/core/downloader/p2p_downloader/client_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func (cw *ClientWriter) init() (err error) {
}

cw.serviceFile, _ = fileutils.OpenFile(cw.serviceFilePath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0755)
fileutils.Link(cw.serviceFilePath, cw.clientFilePath)
if err := fileutils.Link(cw.serviceFilePath, cw.clientFilePath); err != nil {
return err
}
}

cw.result = true
Expand Down Expand Up @@ -183,7 +185,9 @@ func (cw *ClientWriter) write(piece *Piece) error {

func writePieceToFile(piece *Piece, file *os.File) error {
start := int64(piece.PieceNum) * (int64(piece.PieceSize) - 5)
file.Seek(start, 0)
if _, err := file.Seek(start, 0); err != nil {
return err
}

buf := bufio.NewWriterSize(file, 4*1024*1024)
_, err := io.Copy(buf, piece.RawContent())
Expand Down

0 comments on commit e317d52

Please sign in to comment.