post-processor/vagrant: properly close file handles [GH-100]
This commit is contained in:
parent
87edf67177
commit
89e07b875d
|
@ -22,6 +22,8 @@ BUG FIXES:
|
||||||
the output path.
|
the output path.
|
||||||
* vagrant: Properly configure the provider-specific post-processors so
|
* vagrant: Properly configure the provider-specific post-processors so
|
||||||
things like `vagrantfile_template` work. [GH-129]
|
things like `vagrantfile_template` work. [GH-129]
|
||||||
|
* vagrant: Close filehandles when copying files so Windows can
|
||||||
|
rename files. [GH-100]
|
||||||
|
|
||||||
## 0.1.4 (July 2, 2013)
|
## 0.1.4 (July 2, 2013)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,27 @@ type OutputPathTemplate struct {
|
||||||
Provider string
|
Provider string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copies a file by copying the contents of the file to another place.
|
||||||
|
func CopyContents(dst, src string) error {
|
||||||
|
srcF, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer srcF.Close()
|
||||||
|
|
||||||
|
dstF, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer dstF.Close()
|
||||||
|
|
||||||
|
if _, err := io.Copy(dstF, srcF); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// DirToBox takes the directory and compresses it into a Vagrant-compatible
|
// DirToBox takes the directory and compresses it into a Vagrant-compatible
|
||||||
// box. This function does not perform checks to verify that dir is
|
// box. This function does not perform checks to verify that dir is
|
||||||
// actually a proper box. This is an expected precondition.
|
// actually a proper box. This is an expected precondition.
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -66,19 +65,9 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
|
||||||
// Copy all of the original contents into the temporary directory
|
// Copy all of the original contents into the temporary directory
|
||||||
for _, path := range artifact.Files() {
|
for _, path := range artifact.Files() {
|
||||||
ui.Message(fmt.Sprintf("Copying: %s", path))
|
ui.Message(fmt.Sprintf("Copying: %s", path))
|
||||||
src, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
defer src.Close()
|
|
||||||
|
|
||||||
dst, err := os.Create(filepath.Join(dir, filepath.Base(path)))
|
dstPath := filepath.Join(dir, filepath.Base(path))
|
||||||
if err != nil {
|
if err := CopyContents(dstPath, path); err != nil {
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
defer dst.Close()
|
|
||||||
|
|
||||||
if _, err := io.Copy(dst, src); err != nil {
|
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -51,19 +50,9 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
|
||||||
// Copy all of the original contents into the temporary directory
|
// Copy all of the original contents into the temporary directory
|
||||||
for _, path := range artifact.Files() {
|
for _, path := range artifact.Files() {
|
||||||
ui.Message(fmt.Sprintf("Copying: %s", path))
|
ui.Message(fmt.Sprintf("Copying: %s", path))
|
||||||
src, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
defer src.Close()
|
|
||||||
|
|
||||||
dst, err := os.Create(filepath.Join(dir, filepath.Base(path)))
|
dstPath := filepath.Join(dir, filepath.Base(path))
|
||||||
if err != nil {
|
if err := CopyContents(dstPath, path); err != nil {
|
||||||
return nil, false, err
|
|
||||||
}
|
|
||||||
defer dst.Close()
|
|
||||||
|
|
||||||
if _, err := io.Copy(dst, src); err != nil {
|
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue