mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 02:21:34 +00:00
Merge pull request #27 from chanwit/add_source
add Source attribute to File
This commit is contained in:
commit
b47f3dec4a
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -35,6 +36,7 @@ type Moby struct {
|
|||||||
Directory bool
|
Directory bool
|
||||||
Symlink string
|
Symlink string
|
||||||
Contents string
|
Contents string
|
||||||
|
Source string
|
||||||
}
|
}
|
||||||
Outputs []struct {
|
Outputs []struct {
|
||||||
Format string
|
Format string
|
||||||
@ -671,8 +673,17 @@ func filesystem(m Moby) (*bytes.Buffer, error) {
|
|||||||
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 == "" && f.Symlink == "" {
|
if !f.Directory && f.Contents == "" && f.Symlink == "" {
|
||||||
|
if f.Source == "" {
|
||||||
return buf, errors.New("Contents of file not specified")
|
return buf, errors.New("Contents of file not specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contents, err := ioutil.ReadFile(f.Source)
|
||||||
|
if err != nil {
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
|
||||||
|
f.Contents = string(contents)
|
||||||
|
}
|
||||||
// we need all the leading directories
|
// we need all the leading directories
|
||||||
parts := strings.Split(path.Dir(f.Path), "/")
|
parts := strings.Split(path.Dir(f.Path), "/")
|
||||||
root := ""
|
root := ""
|
||||||
|
@ -21,7 +21,8 @@ var schema = string(`
|
|||||||
"path": {"type": "string"},
|
"path": {"type": "string"},
|
||||||
"directory": {"type": "boolean"},
|
"directory": {"type": "boolean"},
|
||||||
"symlink": {"type": "string"},
|
"symlink": {"type": "string"},
|
||||||
"contents": {"type": "string"}
|
"contents": {"type": "string"},
|
||||||
|
"source": {"type": "string"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
|
Loading…
Reference in New Issue
Block a user