Skip to content

Commit

Permalink
fix: don't error if file to replaces lines in doesn't exist
Browse files Browse the repository at this point in the history
`ensure` should be used if a file should be created when one doesn't
exist.
  • Loading branch information
femnad committed Apr 26, 2024
1 parent 6ac5e95 commit 238cf3a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion provision/ensurelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provision

import (
"bufio"
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -69,7 +70,9 @@ func ensure(file string, tmpFile *os.File, line entity.LineInFile) (result ensur

func replace(file string, tmpFile *os.File, line entity.LineInFile) (result ensureResult, err error) {
srcFile, err := os.Open(file)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return result, nil
} else if err != nil {
return
}
defer srcFile.Close()
Expand Down

0 comments on commit 238cf3a

Please sign in to comment.