Add support for symlinks in files section

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack
2017-05-09 13:06:04 +01:00
parent 96ae98d2d5
commit cc2a3a645f
2 changed files with 14 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ type Moby struct {
Files []struct { Files []struct {
Path string Path string
Directory bool Directory bool
Symlink string
Contents string Contents string
} }
Outputs []struct { Outputs []struct {
@@ -438,7 +439,7 @@ func filesystem(m *Moby) (*bytes.Buffer, error) {
if f.Path == "" { if f.Path == "" {
return buf, errors.New("Did not specify path for file") return buf, errors.New("Did not specify path for file")
} }
if !f.Directory && f.Contents == "" { if !f.Directory && f.Contents == "" && f.Symlink == "" {
return buf, errors.New("Contents of file not specified") return buf, errors.New("Contents of file not specified")
} }
// we need all the leading directories // we need all the leading directories
@@ -477,6 +478,17 @@ func filesystem(m *Moby) (*bytes.Buffer, error) {
if err != nil { if err != nil {
return buf, err return buf, err
} }
} else if f.Symlink != "" {
hdr := &tar.Header{
Name: f.Path,
Typeflag: tar.TypeSymlink,
Mode: 0600,
Linkname: f.Symlink,
}
err := tw.WriteHeader(hdr)
if err != nil {
return buf, err
}
} else { } else {
hdr := &tar.Header{ hdr := &tar.Header{
Name: f.Path, Name: f.Path,

View File

@@ -20,6 +20,7 @@ var schema = string(`
"properties": { "properties": {
"path": {"type": "string"}, "path": {"type": "string"},
"directory": {"type": "boolean"}, "directory": {"type": "boolean"},
"symlink": {"type": "string"},
"contents": {"type": "string"} "contents": {"type": "string"}
} }
}, },