mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 18:41:37 +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
7a5cdfd90c
@ -28,8 +28,9 @@ type Moby struct {
|
|||||||
System []MobyImage
|
System []MobyImage
|
||||||
Daemon []MobyImage
|
Daemon []MobyImage
|
||||||
Files []struct {
|
Files []struct {
|
||||||
Path string
|
Path string
|
||||||
Contents string
|
Directory bool
|
||||||
|
Contents string
|
||||||
}
|
}
|
||||||
Outputs []struct {
|
Outputs []struct {
|
||||||
Format string
|
Format string
|
||||||
@ -381,7 +382,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.Contents == "" {
|
if !f.Directory && f.Contents == "" {
|
||||||
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
|
||||||
@ -406,18 +407,34 @@ func filesystem(m *Moby) (*bytes.Buffer, error) {
|
|||||||
return buf, err
|
return buf, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hdr := &tar.Header{
|
|
||||||
Name: f.Path,
|
if f.Directory {
|
||||||
Mode: 0600,
|
if f.Contents != "" {
|
||||||
Size: int64(len(f.Contents)),
|
return buf, errors.New("Directory with contents not allowed")
|
||||||
}
|
}
|
||||||
err := tw.WriteHeader(hdr)
|
hdr := &tar.Header{
|
||||||
if err != nil {
|
Name: f.Path,
|
||||||
return buf, err
|
Typeflag: tar.TypeDir,
|
||||||
}
|
Mode: 0700,
|
||||||
_, err = tw.Write([]byte(f.Contents))
|
}
|
||||||
if err != nil {
|
err := tw.WriteHeader(hdr)
|
||||||
return buf, err
|
if err != nil {
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hdr := &tar.Header{
|
||||||
|
Name: f.Path,
|
||||||
|
Mode: 0600,
|
||||||
|
Size: int64(len(f.Contents)),
|
||||||
|
}
|
||||||
|
err := tw.WriteHeader(hdr)
|
||||||
|
if err != nil {
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
_, err = tw.Write([]byte(f.Contents))
|
||||||
|
if err != nil {
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf, nil
|
return buf, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user