package file
import (
"strings"
"dagger.io/dagger"
"dagger.io/llb"
)
#Create: {
filename: !=""
permissions: int | *0o644
contents: string | bytes
#compute: [
llb.#WriteFile & {dest: filename, content: contents, mode: permissions},
]
}
#Append: {
from: dagger.#Artifact
orig: (#read & {path: filename, "from": from}).data
llb.#WriteFile & {dest: filename, content: "\(orig)\(contents)", mode: permissions},
#Read: {
contents: (#read & {path: filename, "from": from}).data
#read: {
path: !=""
data: {
string
llb.#Load & {"from": from},
llb.#Export & {source: path},
#Glob: {
glob: !=""
filenames: [...string]
files: (_#glob & {"glob": glob, "from": from}).data
// trim suffix because ls always ends with newline
filenames: strings.Split(strings.TrimSuffix(files, "\n"), "\n")
_#glob: {
_tmppath: "/tmp/ls.out"
llb.#Exec & {
args: ["sh", "-c", "ls \(glob) > \(_tmppath)"]
},
llb.#Export & {source: _tmppath},