Skip to content

Commit

Permalink
cmd: create missing directories for symlinks, see #385
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Mar 14, 2021
1 parent 24bcc49 commit 0a58518
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cmd/minify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,21 @@ func openOutputFile(output string) (*os.File, error) {
return w, nil
}

func createSymlink(input, output string) error {
if _, err := os.Stat(output); err == nil {
if err = os.Remove(output); err != nil {
return err
}
}
if err := os.MkdirAll(path.Dir(output), 0777); err != nil {
return err
}
if err := os.Symlink(input, output); err != nil {
return err
}
return nil
}

func minify(t Task) bool {
// synchronizing files that are not minified but just copied to the same directory, no action needed
if t.sync {
Expand All @@ -647,13 +662,7 @@ func minify(t Task) bool {
Error.Println(err)
return false
}
if _, err := os.Stat(t.dst); err == nil {
if err = os.Remove(t.dst); err != nil {
Error.Println(err)
return false
}
}
if err := os.Symlink(src, t.dst); err != nil {
if err := createSymlink(src, t.dst); err != nil {
Error.Println(err)
return false
}
Expand Down

0 comments on commit 0a58518

Please sign in to comment.