Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 45d70d7

Browse files
authored
Handle errors when walking the fs in tf instance provider (#724)
When walking the directory we need to check if an error is passed in and, if so, not process that entry since the associated `os.FileInfo` is `nil`. This appears to happen when a file has been removed after the directory listing has completed. Signed-off-by: Steven Kaufer <[email protected]>
1 parent 606793c commit 45d70d7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/provider/terraform/instance/apply.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func (p *plugin) handleFiles(fns tfFuncs) error {
171171
fs := &afero.Afero{Fs: p.fs}
172172
err = fs.Walk(p.Dir,
173173
func(path string, info os.FileInfo, err error) error {
174+
if err != nil {
175+
log.Debugf("Ignoring file %s due to error: %s", path, err)
176+
return nil
177+
}
174178
// Only the VM files are valid for pruning; once pruned then the group controller polling will
175179
// ensure that a replacement is created. There is no mechanism that ensures consistency for
176180
// dedicated and global resources.

pkg/provider/terraform/instance/plugin.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,11 @@ func (p *plugin) scanLocalFiles() (map[TResourceType]map[TResourceName]TResource
380380
fs := &afero.Afero{Fs: p.fs}
381381
// just scan the directory for the instance-*.tf.json files
382382
err := fs.Walk(p.Dir,
383-
384383
func(path string, info os.FileInfo, err error) error {
384+
if err != nil {
385+
log.Debugf("Ignoring file %s due to error: %s", path, err)
386+
return nil
387+
}
385388
matches := instanceTfFileRegex.FindStringSubmatch(info.Name())
386389

387390
if len(matches) == 4 {
@@ -820,6 +823,10 @@ func (p *plugin) listCurrentTfFiles() (map[string]map[TResourceType]map[TResourc
820823
fs := &afero.Afero{Fs: p.fs}
821824
err := fs.Walk(p.Dir,
822825
func(path string, info os.FileInfo, err error) error {
826+
if err != nil {
827+
log.Debugf("Ignoring file %s due to error: %s", path, err)
828+
return nil
829+
}
823830
matches := tfFileRegex.FindStringSubmatch(info.Name())
824831
if len(matches) == 3 {
825832
buff, err := ioutil.ReadFile(filepath.Join(p.Dir, info.Name()))
@@ -1078,6 +1085,10 @@ func (p *plugin) doDestroy(inst instance.ID, processAttach, executeTfApply bool)
10781085
fs := &afero.Afero{Fs: p.fs}
10791086
err = fs.Walk(p.Dir,
10801087
func(path string, info os.FileInfo, err error) error {
1088+
if err != nil {
1089+
log.Debugf("Ignoring file %s due to error: %s", path, err)
1090+
return nil
1091+
}
10811092
matches := instanceTfFileRegex.FindStringSubmatch(info.Name())
10821093
// Note that the current instance (being destroyed) still exists; filter
10831094
// this file out.

0 commit comments

Comments
 (0)