You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We'd probably also want this for Directory as well as File.
Out of curiosity, would we want a path field, or a name field (that just returns the last component)? I was thinking that it could be nice to be a bit more generic and allow getting the whole path - but one issue with this is that suppose I compare dir.File("foo/bar").Path() and dir.Dir("foo").File("bar").Path(). It feels like both of these should return the same string path value, but in each case, they both have different paths within their "root" directory (the first has "/" as it's root, the second has "/foo"). Maybe just having the last component here would make this easier? @sagikazarmark can you imagine a good case for getting the whole path, or would just the filename (which contains the file extension) be enough for your use case?
Some tools need the file extension to determine the content type (not a fool proof solution, but currently impossible when passing in a File)
GitHub releases need a file name. I tried creating a custom struct with an additional name attribute, but it's currently impossible to use custom structs as function parameters
When mounting several files in a container, I often need to use workarounds, like numbering (ie. file-1) due to not knowing the original file name. It makes debugging harder when there is a problem with one of the files.
I'm sure there are other scenarios where a file name would be useful, but these are the ones I had so far and probably the most common ones, too.
┃ /work
┃ total 12K
┃ drwxr-xr-x 2 root root 4.0K Jan 17 04:32 .
┃ drwxr-xr-x 1 root root 4.0K Jan 17 04:32 ..
┃ -rw-r--r-- 2 root root 34 Jan 15 17:21 dagger.json
• Engine: a045aaae0d17 (version v0.9.6)
As I said, it's a little inconvenient, but I realized that file.Name() would probably require a context and a trip to the engine as well, so it doesn't matter that much if I need to call Entries on an empty directory.
Activity
jedevc commentedon Jan 15, 2024
We'd probably also want this for
Directoryas well asFile.Out of curiosity, would we want a
pathfield, or anamefield (that just returns the last component)? I was thinking that it could be nice to be a bit more generic and allow getting the whole path - but one issue with this is that suppose I comparedir.File("foo/bar").Path()anddir.Dir("foo").File("bar").Path(). It feels like both of these should return the same string path value, but in each case, they both have different paths within their "root" directory (the first has "/" as it's root, the second has "/foo"). Maybe just having the last component here would make this easier? @sagikazarmark can you imagine a good case for getting the whole path, or would just the filename (which contains the file extension) be enough for your use case?sagikazarmark commentedon Jan 15, 2024
Most of the cases I have are just for the name.
Looking at Go's os.File: it also has a name, but I don't think it knows about the path.
sagikazarmark commentedon Jan 16, 2024
Some of the use cases I have:
I'm sure there are other scenarios where a file name would be useful, but these are the ones I had so far and probably the most common ones, too.
helderco commentedon Jan 16, 2024
I think it does preserve the name, just not exposed. If you add with empty path it should default to using that name:
sagikazarmark commentedon Jan 17, 2024
I guess that’s a good start, but a little inconvenient if I need the file name as an argument of a command.
sagikazarmark commentedon Jan 17, 2024
This doesn't work:
This does:
As I said, it's a little inconvenient, but I realized that
file.Name()would probably require a context and a trip to the engine as well, so it doesn't matter that much if I need to callEntrieson an empty directory.sagikazarmark commentedon Jan 17, 2024
After giving it a try, I think I still prefer getting the file name directly. This feels a bit hacky (see linked PR).
sagikazarmark commentedon Jan 17, 2024
🎉