Skip to content

Commit

Permalink
filestore: track close err, lints (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: jsign <jsign.uy@gmail.com>
  • Loading branch information
jsign authored and hannahhoward committed Jan 2, 2020
1 parent c789fa9 commit 86ecc3c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions filestore/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewLocalFileStore(basedirectory Path) (FileStore, error) {
if err != nil {
return nil, fmt.Errorf("error getting %s info: %s", base, err.Error())
}
if false == info.IsDir() {
if !info.IsDir() {
return nil, fmt.Errorf("%s is not a directory", base)
}
return &fileStore{string(base)}, nil
Expand All @@ -32,17 +32,15 @@ func (fs fileStore) filename(p Path) string {

func (fs fileStore) Open(p Path) (File, error) {
name := fs.filename(p)
_, err := os.Stat(name)
if err != nil {
if _, err := os.Stat(name); err != nil {
return nil, fmt.Errorf("error trying to open %s: %s", name, err.Error())
}
return newFile(Path(fs.base), p)
}

func (fs fileStore) Create(p Path) (File, error) {
name := fs.filename(p)
_, err := os.Stat(name)
if err == nil {
if _, err := os.Stat(name); err == nil {
return nil, fmt.Errorf("file %s already exists", name)
}
return newFile(Path(fs.base), p)
Expand All @@ -53,12 +51,12 @@ func (fs fileStore) Store(p Path, src File) (Path, error) {
if err != nil {
return Path(""), err
}
defer dest.Close()
_, err = io.Copy(dest, src)
if err != nil {

if _, err = io.Copy(dest, src); err != nil {
dest.Close()
return Path(""), err
}
return Path(fs.filename(p)), nil
return Path(fs.filename(p)), dest.Close()
}

func (fs fileStore) Delete(p Path) error {
Expand All @@ -75,5 +73,5 @@ func (fs fileStore) CreateTemp() (File, error) {
return nil, err
}
filename := filepath.Base(f.Name())
return &fd{File: f, basepath: fs.base, filename: filename,}, nil
return &fd{File: f, basepath: fs.base, filename: filename}, nil
}

0 comments on commit 86ecc3c

Please sign in to comment.