Skip to content

Commit

Permalink
Merge pull request #8 from coreydaley/fix_l_flag
Browse files Browse the repository at this point in the history
fix -l flag
  • Loading branch information
coreydaley authored Mar 15, 2023
2 parents e8ed184 + 334b868 commit d4a13e5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,21 @@ func Format(files *chan string, wg *sync.WaitGroup, groupRegExpMatchers []v1alph
if !bytes.Equal(oldFile, out) {
fmt.Fprintf(os.Stdout, "%s is not organized \n", path)
}
}

info, err = os.Stat(path)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to stat %q: %s", path, err.Error())
continue
}
if !info.ModTime().Equal(oldModTime) {
fmt.Fprintf(os.Stderr, "%s was modified while formatting, cowardly refusing to overwrite", path)
continue
}
if err = os.WriteFile(path, out, info.Mode()); err != nil {
fmt.Fprintf(os.Stderr, "unable to write to path %q, %s", path, err.Error())
} else {
info, err = os.Stat(path)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to stat %q: %s", path, err.Error())
continue
}
if !info.ModTime().Equal(oldModTime) {
fmt.Fprintf(os.Stderr, "%s was modified while formatting, cowardly refusing to overwrite", path)
continue
}
if err = os.WriteFile(path, out, info.Mode()); err != nil {
fmt.Fprintf(os.Stderr, "unable to write to path %q, %s", path, err.Error())
}
}

}
}

0 comments on commit d4a13e5

Please sign in to comment.