Repository navigation
initial Directory + File implementations - #3168
Conversation
👷 Deploy request for cloak-docs pending review.Visit the deploys page to approve it
|
Signed-off-by: Alex Suraci <[email protected]>
b7c775a to
9c7b6ac
Compare
Signed-off-by: Alex Suraci <[email protected]>
efc450a to
1a88194
Compare
+ File { id, contents, size }
+ FileID
+ file(FileID!)
+ directory { file }
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Directory + File implementations
Signed-off-by: Alex Suraci <[email protected]>
aluzzardi
left a comment
There was a problem hiding this comment.
Looks great! Left a minor question.
Linter is complaining about a couple of things, LGTM otherwise
| ) | ||
|
|
||
| // Directory is a content-addressed directory. | ||
| type Directory struct { |
There was a problem hiding this comment.
Is the goal to move away from "models" being in a separate package (e.g. retire core/filesystem)?
I'm totally onboard with that, this is simpler, just wanted to double check
There was a problem hiding this comment.
I'm open to rearranging things, but yeah I figured I'd start with just putting it all together.
One option could be to move the schema glue out, but I think I would still prefer one big package for all the models to live in since they're inter-dependent (possibly with circles at some point?) and share a lot of common behavior (e.g. FooID scalar definitions and encoding/decoding). If we were to do per-type packages I think we'd end up with a /util package somewhere which feels a little awkward to me.
also remove unnecessary empty ID check Signed-off-by: Alex Suraci <[email protected]>
| } | ||
|
|
||
| // be sure to create the file under the working directory | ||
| dest = path.Join(cwd, dest) |
There was a problem hiding this comment.
My expectation would have been that if I provide a relative dest then it should be relative to cwd, but if dest is absolute then it should just be what I tell it. Not sure if that's aligned with everyone else's expectations, so not a blocker if others disagree.
There was a problem hiding this comment.
I'm trying to form an opinion on this, but don't understand what cwd is. Seems like an implementation detail?
There was a problem hiding this comment.
This line is to handle this possibly-edge case:
directory {
withNewFile(path: "foo/bar", contents: "bar") {
directory(path: "foo") {
withNewFile(path: "baz", contents: "baz") {
id
}
}
}
}The intention above is to create this file tree, since I did the withNewFile relative to the inner directory {}:
foo/bar
foo/baz
But without this line it would end up creating it in the root of the outer directory:
foo/bar
baz
And I think what @sipsma is suggesting is that if I explicitly pass an absolute path, like this:
directory {
withNewFile(path: "foo/bar", contents: "bar") {
directory(path: "foo") {
withNewFile(path: "/baz", contents: "baz") { # note absolute path
id
}
}
}
}...then it should end up with the above result, because I explicitly told it to create the file in the root of the directory.
foo/bar
baz
I think that makes sense from the standpoint of respecting the path syntax, but I wonder if it'll be hard to tell where exactly the "root" is in practice. 🤔 For example, if I take the id of the inner directory and hop into it from a context-free directory(id: $id) it feels a little weird to allow the user to create files outside of it.
directory(id: $subdir) {
withNewFile(path: "/absolute", content: "abs") {
id
}
}I suppose you'll still get an ID back with the outer directory modified, but I don't know how you would gain access to the file you created, unless we add an accessor to the parent dir.
There was a problem hiding this comment.
Ohhhh sorry, I totally misunderstood what cwd was actually. I just instantly assumed it was the implementation of "workdir" since that's usually what I think of when I see cwd, but that doesn't even make sense in Directory yet.
I agree that this should always be relative to the subdir (aka cwd var here) no matter whether it's relative or absolute. We should probably treat going to a subdir of a Directory spiritually the same as a chroot, shouldn't be able to access any files above that subdir once it's been selected.
There was a problem hiding this comment.
We should probably treat going to a subdir of a Directory spiritually the same as a chroot, shouldn't be able to access any files above that subdir once it's been selected.
Agreed!
And yeah the cwd name might be a bit misleading.
sipsma
left a comment
There was a problem hiding this comment.
No blocking comments, just little things. Looks amazing, a huge improvement over our previous implementation already!
| return nil, err | ||
| } | ||
|
|
||
| st = st.File(llb.Copy(srcSt, srcCwd, path.Join(cwd, subdir))) |
There was a problem hiding this comment.
nb: does this create any missing parent dirs if they don't exist yet?
There was a problem hiding this comment.
Nice catch, it didn't; fixed and added a test. I think it makes sense for it to create the parents to be consistent with withNewFile, but we can reconsider both in the future.
| } | ||
|
|
||
| // stringResolver is used to generate a scalar resolver for a stringable type. | ||
| func stringResolver[T ~string](sample T) router.ScalarResolver { |
Signed-off-by: Alex Suraci <[email protected]>
Implements the following portions of the API:
The rest of the spec is stubbed out to return errors. Also changes
git { tree }to return aDirectory!instead of aFilesystem!.Also introduces some utilities for encoding/decoding IDs and defining ID scalar types in the schema. I went a little ham with generics here, probably didn't need to, but they're shiny.