Skip to content

Commit

Permalink
create directory for temporary files of metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Feb 16, 2017
1 parent 7491fa0 commit 40e1882
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"time"

Expand Down Expand Up @@ -81,7 +82,10 @@ func (g *Generator) Save(metadata interface{}) error {
if g.Tempfile == "" {
return fmt.Errorf("specify the name of temporary file")
}
if err = writeFileAtomically(g.Tempfile, data); err != nil {
if err := os.MkdirAll(filepath.Dir(g.Tempfile), 0755); err != nil {
return err
}
if err := writeFileAtomically(g.Tempfile, data); err != nil {
return fmt.Errorf("failed to write the metadata to temporary file: %v", err)
}
return nil
Expand Down

0 comments on commit 40e1882

Please sign in to comment.