mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 18:11:35 +00:00
Merge pull request #1530 from ijc25/create-directories-from-yaml
Support creating of directories in files section
This commit is contained in:
commit
2407afbbe0
@ -29,6 +29,7 @@ type Moby struct {
|
||||
Daemon []MobyImage
|
||||
Files []struct {
|
||||
Path string
|
||||
Directory bool
|
||||
Contents string
|
||||
}
|
||||
Outputs []struct {
|
||||
@ -381,7 +382,7 @@ func filesystem(m *Moby) (*bytes.Buffer, error) {
|
||||
if f.Path == "" {
|
||||
return buf, errors.New("Did not specify path for file")
|
||||
}
|
||||
if f.Contents == "" {
|
||||
if !f.Directory && f.Contents == "" {
|
||||
return buf, errors.New("Contents of file not specified")
|
||||
}
|
||||
// we need all the leading directories
|
||||
@ -406,6 +407,21 @@ func filesystem(m *Moby) (*bytes.Buffer, error) {
|
||||
return buf, err
|
||||
}
|
||||
}
|
||||
|
||||
if f.Directory {
|
||||
if f.Contents != "" {
|
||||
return buf, errors.New("Directory with contents not allowed")
|
||||
}
|
||||
hdr := &tar.Header{
|
||||
Name: f.Path,
|
||||
Typeflag: tar.TypeDir,
|
||||
Mode: 0700,
|
||||
}
|
||||
err := tw.WriteHeader(hdr)
|
||||
if err != nil {
|
||||
return buf, err
|
||||
}
|
||||
} else {
|
||||
hdr := &tar.Header{
|
||||
Name: f.Path,
|
||||
Mode: 0600,
|
||||
@ -420,5 +436,6 @@ func filesystem(m *Moby) (*bytes.Buffer, error) {
|
||||
return buf, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return buf, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user