44 "bufio"
55 "fmt"
66 "io"
7+ "log"
78 "os"
89 "os/exec"
910 "path/filepath"
@@ -16,7 +17,11 @@ func FileContains(path, line string) bool {
1617 if err != nil {
1718 return false
1819 }
19- defer file .Close ()
20+ defer func () {
21+ if err := file .Close (); err != nil {
22+ log .Printf ("failed to close file: %v" , err )
23+ }
24+ }()
2025
2126 scanner := bufio .NewScanner (file )
2227 for scanner .Scan () {
@@ -33,7 +38,11 @@ func AppendToFile(path string, lines []string) error {
3338 if err != nil {
3439 return err
3540 }
36- defer file .Close ()
41+ defer func () {
42+ if err := file .Close (); err != nil {
43+ log .Printf ("failed to close file: %v" , err )
44+ }
45+ }()
3746
3847 for _ , line := range lines {
3948 if _ , err := file .WriteString (line + "\n " ); err != nil {
@@ -46,7 +55,9 @@ func AppendToFile(path string, lines []string) error {
4655
4756func EnsureSymlink (from , to string ) error {
4857 if _ , err := os .Lstat (from ); err == nil {
49- os .Remove (from )
58+ if err := os .Remove (from ); err != nil {
59+ return fmt .Errorf ("fail to remove %s" , from )
60+ }
5061 }
5162
5263 if runtime .GOOS == "windows" {
@@ -135,13 +146,21 @@ func copyFile(src, dst string) error {
135146 if err != nil {
136147 return err
137148 }
138- defer source .Close ()
149+ defer func () {
150+ if err := source .Close (); err != nil {
151+ log .Printf ("failed to close file: %v" , err )
152+ }
153+ }()
139154
140155 destination , err := os .Create (dst )
141156 if err != nil {
142157 return err
143158 }
144- defer destination .Close ()
159+ defer func () {
160+ if err := destination .Close (); err != nil {
161+ log .Printf ("failed to close file: %v" , err )
162+ }
163+ }()
145164
146165 _ , err = io .Copy (destination , source )
147166 return err
0 commit comments