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) {
|
func NewArtifact(dir string) (packer.Artifact, error) {
|
||||||
files := make([]string, 0, 5)
|
files := make([]string, 0, 5)
|
||||||
visit := func(path string, info os.FileInfo, err error) error {
|
visit := func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := filepath.Walk(dir, visit); err != nil {
|
if err := filepath.Walk(dir, visit); err != nil {
|
||||||
|
|
|
@ -28,6 +28,9 @@ type artifact struct {
|
||||||
func NewArtifact(dir string) (packer.Artifact, error) {
|
func NewArtifact(dir string) (packer.Artifact, error) {
|
||||||
files := make([]string, 0, 5)
|
files := make([]string, 0, 5)
|
||||||
visit := func(path string, info os.FileInfo, err error) error {
|
visit := func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for _, unnecessaryFile := range unnecessaryFiles {
|
for _, unnecessaryFile := range unnecessaryFiles {
|
||||||
if unnecessary, _ := regexp.MatchString(unnecessaryFile, path); unnecessary {
|
if unnecessary, _ := regexp.MatchString(unnecessaryFile, path); unnecessary {
|
||||||
return os.RemoveAll(path)
|
return os.RemoveAll(path)
|
||||||
|
@ -38,7 +41,7 @@ func NewArtifact(dir string) (packer.Artifact, error) {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := filepath.Walk(dir, visit); err != 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
|
// Compile the artifact list
|
||||||
files := make([]string, 0, 5)
|
files := make([]string, 0, 5)
|
||||||
visit := func(path string, info os.FileInfo, err error) error {
|
visit := func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := filepath.Walk(b.config.OutputDir, visit); err != 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) {
|
func NewArtifact(dir string) (packer.Artifact, error) {
|
||||||
files := make([]string, 0, 5)
|
files := make([]string, 0, 5)
|
||||||
visit := func(path string, info os.FileInfo, err error) error {
|
visit := func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,13 @@ type localArtifact struct {
|
||||||
func NewLocalArtifact(dir string) (packer.Artifact, error) {
|
func NewLocalArtifact(dir string) (packer.Artifact, error) {
|
||||||
files := make([]string, 0, 5)
|
files := make([]string, 0, 5)
|
||||||
visit := func(path string, info os.FileInfo, err error) error {
|
visit := func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := filepath.Walk(dir, visit); err != 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
|
var crawlDirectoryFiles []string
|
||||||
crawlDirectory := func(path string, info os.FileInfo, err error) error {
|
crawlDirectory := func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
crawlDirectoryFiles = append(crawlDirectoryFiles, path)
|
crawlDirectoryFiles = append(crawlDirectoryFiles, path)
|
||||||
ui.Message(fmt.Sprintf("Adding file: %s", path))
|
ui.Message(fmt.Sprintf("Adding file: %s", path))
|
||||||
|
|
|
@ -21,6 +21,9 @@ const TestFixtures = "test-fixtures"
|
||||||
func getDirectory(path string) []string {
|
func getDirectory(path string) []string {
|
||||||
var result []string
|
var result []string
|
||||||
walk := func(path string, info os.FileInfo, err error) error {
|
walk := func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if info.IsDir() && !strings.HasSuffix(path, "/") {
|
if info.IsDir() && !strings.HasSuffix(path, "/") {
|
||||||
path = path + "/"
|
path = path + "/"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue