#extract directory name from dagger.Directory type?
1 messages · Page 1 of 1 (latest)
Did you have tried something like await folder.name() where folder is your Directory variable ? (my snippets is for Python)
Have done this with success a few days ago for a File variable.
i think you are 100% correct that there should be a name method in the go sdk, but i am not seeing one. what you have is exactly what i would have expected to be able to do in the go sdk 😢
we have an ID method that returns a unique identifier for the directory, but def not what i am looking for.
Back to the office and I've checked. For a File object, I can retrieve his name but not for a Directory.
For instance, for a File the code below is valid.
if await application_file.name() == ".env":
# It's a the .env file
Hey 😄
I think we could add a method to get the path if this directory, then you can easily get its name.
Feel free to open an issue and we'll add it to the directory API after team's approval 🙂
I found where I thought it needed to go in core/schema/directory.go, but then lost myself in the dagql library. i'm not a developer by trade, so I'm a slowpoke when diving into this stuff - couple that with my inability to do something without understanding it thoroughly and here we are 😂
No problem! Thanks a lot for that issue, I'll pick it up whenever I have time
/cc @marsh lion do you have any thought that might make this complex to implement? I think it just a matter of exposing the path that we store in Dir there: https://github.com/dagger/dagger/blob/35aa68f437ab0880f51aab6de0b3482589c3e66e/core/directory.go#L29
i remember trying to do this before 😄
and i remember. it didn't just work
but i cannot remember why 😄
sooooo. good luck 😄
I'm guessing llb itself doesn't support that, so you'd have to carry that state purely at the dagger layer, and implement methods for setting a name specific to each method:
Host.directory()-> get the dirname in the context of the hostGitRef.tree()-> use the last component of the path of the git repo remote?Directory.directory()-> use the dirname in the context of the parent directorydirectory()-> optional name argument? Just call it""or"/"if no name provided?
Other fun questions:
- Do symlinks complicate this?
- What if I open
/?
Why can’t we just work this out with the dir path? I do not understand the name setting logic
Yes, it's just that "the dir path" has different meanings depending on where the dir came from. For example maybe it came from a dag.Git().Tag.Tree() call; or dag.Host().Directory() call
mm, that's actually a reason i think we probably shouldn't support getting the full path - it depends so much on where it comes from and feels dangerously close to leaking information between functions (i also really can't imagine a use case where you need the full path, where it's not hugely fragile to what you pass in)
we shouldn't make it possible to have a function that takes a File, but that requires it to have a "path" that's constructed in a specific way (it feels like bugs in modules waiting to happen)
i would rather just restrict it to the last portion - you're allowed to just get the name of the directory
I agree & would never support getting the full path. But the directory's name (last part of the path) feels safe to share
PR opened : https://github.com/dagger/dagger/pull/9617
Based on https://discord.com/channels/707636530424053791/1336739628350439454.
This PR adds a function name to the Directory API to retrieve the latest name of the branch.
TODOS
API changes
Clien...
raised a general question here Tom https://github.com/dagger/dagger/pull/9617#issuecomment-2667306478. cc @velvet hare and Justin (avoid late ping)