Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/lib/bundle: fix copyManifestDir so it actually copies file contents #237

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions pkg/lib/bundle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,17 @@ func WriteFile(fileName, directory string, content []byte) error {
return nil
}

// copy the contents of a flat manifest dir into an output dir
// copy the contents of a potentially nested manifest dir into an output dir.
func copyManifestDir(from, to string, overwrite bool) error {
fromFiles, err := ioutil.ReadDir(from)
if err != nil {
return err
}

if _, err := os.Stat(to); os.IsNotExist(err) {
os.MkdirAll(to, os.ModePerm)
if err = os.MkdirAll(to, os.ModePerm); err != nil {
return err
}
}

for _, fromFile := range fromFiles {
Expand All @@ -415,6 +417,11 @@ func copyManifestDir(from, to string, overwrite bool) error {
if err != nil {
return err
}
defer func() {
if err := contents.Close(); err != nil {
log.Fatal(err)
}
}()

toFilePath := filepath.Join(to, fromFile.Name())
_, err = os.Stat(toFilePath)
Expand All @@ -428,8 +435,13 @@ func copyManifestDir(from, to string, overwrite bool) error {
if err != nil {
return err
}
defer func() {
if err := toFile.Close(); err != nil {
log.Fatal(err)
}
}()

_, err = io.Copy(contents, toFile)
_, err = io.Copy(toFile, contents)
if err != nil {
return err
}
Expand Down