Skip to content

Commit

Permalink
Make 'yo generate overwrite yo_db file (cloudspannerecosystem#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyamagu2 authored and zchee committed Mar 1, 2021
1 parent dbc65c3 commit f93f8e4
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,12 @@ func (g *Generator) getFile(ds *basicDataSet, t *TBuf) (*os.File, error) {
// default open mode
mode := os.O_RDWR | os.O_CREATE | os.O_TRUNC

// stat file to determine if file already exists
// stat file to determine if file is a directory.
fi, err := os.Stat(filename)
if err == nil && fi.IsDir() {
return nil, errors.New("filename cannot be directory")
}

// skip
if t.TemplateType == YOTemplate && fi != nil {
return nil, nil
}

// open file
f, err = os.OpenFile(filename, mode, 0666)
if err != nil {
Expand Down Expand Up @@ -231,11 +226,6 @@ func (g *Generator) writeTypes(ds *basicDataSet) error {
return err
}

// should only be nil when type == yo
if f == nil {
continue
}

// write segment
if _, err = t.Buf.WriteTo(f); err != nil {
return err
Expand Down

0 comments on commit f93f8e4

Please sign in to comment.