grim/convey

b96052b55497
Parents 080eb3a53eac
Children e9f522b69dea
Fix up the import task so it works again
--- a/workspace/fileio.go Sat Jul 27 11:33:28 2019 -0500
+++ b/workspace/fileio.go Sat Jul 27 13:09:03 2019 -0500
@@ -17,10 +17,12 @@
package workspace
import (
+ "fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
+ "strings"
)
func (ws *Workspace) TaskDirectory(name string) (string, error) {
@@ -61,10 +63,60 @@
return os.Rename(tmp.Name(), dst)
}
+func (ws *Workspace) copyDir(src, dst string, perm os.FileMode) error {
+ err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
+ // make sure we're copying files that are at the same level as convey.yml or
+ // deeper.
+ if !strings.HasPrefix(path, ws.parent) {
+ return fmt.Errorf(
+ "attempted to copy %q which is outside of the run context of %q",
+ path,
+ ws.parent,
+ )
+ }
+
+ // make sure we're don't try to import anything from the .convey directory
+ if strings.HasPrefix(path, ws.root) {
+ return nil
+ }
+
+ // at this point we're going to do something so we need to the real
+ // destination name
+ realDst := filepath.Join(ws.volumePath, strings.TrimPrefix(path, ws.parent))
+
+ // if path is a directory, create it
+ if info.IsDir() {
+ err := os.Mkdir(realDst, 0755)
+
+ // this will get called with the root of the volume, so we need to
+ // handle the error if it exists.
+ if os.IsExist(err) {
+ return nil
+ }
+
+ return err
+ }
+
+ // at this point we have a file so let's copy it
+ return ws.copyFile(path, realDst, 0644)
+ })
+
+ return err
+}
+
func (ws *Workspace) Import(src, dst string) error {
realDst := filepath.Join(ws.volumePath, dst)
- return ws.copyFile(src, realDst, 0644)
+ file, err := os.Stat(src)
+ if err != nil {
+ return err
+ }
+
+ if file.IsDir() {
+ return ws.copyDir(src, realDst, 0644)
+ } else {
+ return ws.copyFile(src, realDst, 0644)
+ }
}
func (ws *Workspace) Export(src, dst string) error {
--- a/workspace/workspace.go Sat Jul 27 11:33:28 2019 -0500
+++ b/workspace/workspace.go Sat Jul 27 13:09:03 2019 -0500
@@ -24,18 +24,20 @@
)
type Workspace struct {
+ parent string
+ root string
path string
volumePath string
}
-func New(root string) (*Workspace, error) {
- parent := filepath.Join(root, ".convey")
- err := os.MkdirAll(parent, 0700)
+func New(parent string) (*Workspace, error) {
+ root := filepath.Join(parent, ".convey")
+ err := os.MkdirAll(root, 0700)
if err != nil {
return nil, err
}
- path, err := ioutil.TempDir(parent, "")
+ path, err := ioutil.TempDir(root, "")
if err != nil {
return nil, err
}
@@ -47,6 +49,8 @@
}
workspace := &Workspace{
+ parent: parent,
+ root: root,
path: path,
volumePath: volumePath,
}