#extract directory name from dagger.Directory type?

1 messages · Page 1 of 1 (latest)

leaden bluff
#

in order to emit some output, i would like to include the basename of the dagger.Directory that was passed in. Am I missing something super obvious here? I would have expected something like a .Name() method on that type 😦

sudden bramble
#

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.

leaden bluff
#

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.

sudden bramble
#

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
soft mirage
#

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 🙂

leaden bluff
#

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 😂

https://github.com/dagger/dagger/issues/9522

GitHub

What are you trying to do? I am specifically in the go sdk, so my example is specific to that, but I assume this is not "just a change to the go sdk." I am importing a directory into a fu...

soft mirage
# leaden bluff I found where I thought it needed to go in core/schema/directory.go, but then lo...

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

GitHub

An engine to run your pipelines in containers. Contribute to dagger/dagger development by creating an account on GitHub.

marsh lion
#

and i remember. it didn't just work

#

but i cannot remember why 😄

#

sooooo. good luck 😄

velvet hare
#

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 host
  • GitRef.tree() -> use the last component of the path of the git repo remote?
  • Directory.directory() -> use the dirname in the context of the parent directory
  • directory() -> optional name argument? Just call it "" or "/" if no name provided?

Other fun questions:

  • Do symlinks complicate this?
  • What if I open / ?
soft mirage
#

Why can’t we just work this out with the dir path? I do not understand the name setting logic

velvet hare
#

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

marsh lion
#

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

velvet hare
#

I agree & would never support getting the full path. But the directory's name (last part of the path) feels safe to share

soft mirage
tacit spire