Skip to content

Commit b0c8504

Browse files
committed
more robust syncDir
1 parent f547358 commit b0c8504

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

backends/fs/fs.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88
"sort"
99
"strings"
10-
"syscall"
1110

1211
"github.com/PowerDNS/simpleblob"
1312
)
@@ -148,6 +147,16 @@ func syncDir(name string) error {
148147
if err != nil {
149148
return err
150149
}
151-
defer dir.Close()
152-
return dir.Sync()
150+
info, err := dir.Stat()
151+
if err != nil {
152+
return err
153+
}
154+
if !info.IsDir() {
155+
_ = dir.Close()
156+
return fmt.Errorf("%s: not a dir", name)
157+
}
158+
if err := dir.Sync(); err != nil {
159+
return err
160+
}
161+
return dir.Close()
153162
}

0 commit comments

Comments
 (0)