Merge pull request #4467 from mitchellh/walksafe
always check for an error first when walking a path
This commit is contained in:
commit
54fdef8199
|
@ -23,11 +23,14 @@ type artifact struct {
|
|||
func NewArtifact(dir string) (packer.Artifact, error) {
|
||||
files := make([]string, 0, 5)
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := filepath.Walk(dir, visit); err != nil {
|
||||
|
|
|
@ -28,6 +28,9 @@ type artifact struct {
|
|||
func NewArtifact(dir string) (packer.Artifact, error) {
|
||||
files := make([]string, 0, 5)
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, unnecessaryFile := range unnecessaryFiles {
|
||||
if unnecessary, _ := regexp.MatchString(unnecessaryFile, path); unnecessary {
|
||||
return os.RemoveAll(path)
|
||||
|
@ -38,7 +41,7 @@ func NewArtifact(dir string) (packer.Artifact, error) {
|
|||
files = append(files, path)
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := filepath.Walk(dir, visit); err != nil {
|
||||
|
|
|
@ -444,11 +444,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
// Compile the artifact list
|
||||
files := make([]string, 0, 5)
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := filepath.Walk(b.config.OutputDir, visit); err != nil {
|
||||
|
|
|
@ -23,6 +23,9 @@ type artifact struct {
|
|||
func NewArtifact(dir string) (packer.Artifact, error) {
|
||||
files := make([]string, 0, 5)
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
}
|
||||
|
|
|
@ -23,11 +23,13 @@ type localArtifact struct {
|
|||
func NewLocalArtifact(dir string) (packer.Artifact, error) {
|
||||
files := make([]string, 0, 5)
|
||||
visit := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := filepath.Walk(dir, visit); err != nil {
|
||||
|
|
|
@ -114,6 +114,9 @@ func (s *StepCreateFloppy) Run(state multistep.StateBag) multistep.StepAction {
|
|||
|
||||
var crawlDirectoryFiles []string
|
||||
crawlDirectory := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
crawlDirectoryFiles = append(crawlDirectoryFiles, path)
|
||||
ui.Message(fmt.Sprintf("Adding file: %s", path))
|
||||
|
|
|
@ -21,6 +21,9 @@ const TestFixtures = "test-fixtures"
|
|||
func getDirectory(path string) []string {
|
||||
var result []string
|
||||
walk := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() && !strings.HasSuffix(path, "/") {
|
||||
path = path + "/"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue