Skip to content

Conversation

@joonas
Copy link

@joonas joonas commented Nov 15, 2025

Add function to map a fs.FS into a list of archives.FileInfo entries.

Fixes #61


The open question that remains is whether symlinks should be supported?

As best as I can tell, this is possible as of Go 1.25 when fs.ReadLinkFS is implemented by the FS, but that leaves the question about what should be done for Go 1.24 and below where this functionality does not exist?

For this initial pass, I opted to return an error if the function comes across a symlink on the provided fs.FS so we can talk about what is the appropriate way to handle this.

Add function to map a fs.FS into a list of FileInfo entries.

Fixes mholt#61

Signed-off-by: Joonas Bergius <joonas@bergi.us>
@joonas
Copy link
Author

joonas commented Dec 1, 2025

@mholt I'm curious if you had any thoughts on this approach for #61 🙂

Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for the delay...

I think this looks good, let's just make sure the comments make sense in the context of the FS instead of the OS file system.

archives.go Outdated
Comment on lines 162 to 164
// Map values should use slash ('/') as the separator regardless of
// the platform, as most archive formats standardize on that rune as the
// directory separator for filenames within an archive. For convenience, map
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is probably irrelevant, or at least should be reworded, for this context, since all fs.FS paths use / as path separators.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I reworded a bit, please let me know if you think you'd like to clarify it further.

archives.go Outdated
// which is expected to be prefixed by rootOnDisk (according to fs.WalkDirFunc godoc)
// and which will be placed into a folder rootInArchive in the archive.
func nameOnDiskToNameInArchive(nameOnDisk, rootOnDisk, rootInArchive string) string {
func nameOnDiskToNameInArchive(nameOnDisk, rootOnDisk, rootInArchive, separator string) string {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func nameOnDiskToNameInArchive(nameOnDisk, rootOnDisk, rootInArchive, separator string) string {
func nameOnDiskToNameInArchive(nameOnDisk, rootOnDisk, rootInArchive string, separator rune) string {

Thinking the separator should be a rune to keep it aligned with the actual values of filepath.Separator.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I went back and forth originally as to whether to use rune or string here, I changed it back to rune.

@mholt
Copy link
Owner

mholt commented Dec 3, 2025

As for:

The open question that remains is whether symlinks should be supported?

As best as I can tell, this is possible as of Go 1.25 when fs.ReadLinkFS is implemented by the FS, but that leaves the question about what should be done for Go 1.24 and below where this functionality does not exist?

I'm OK with not supporting older versions of Go... especially a version that is almost a year old. I think if anyone needs the new feature they can upgrade to the new version.

joonas and others added 2 commits December 4, 2025 19:07
Signed-off-by: Joonas Bergius <joonas@bergi.us>
…arator values

Signed-off-by: Joonas Bergius <joonas@bergi.us>
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
@joonas
Copy link
Author

joonas commented Dec 5, 2025

I'm OK with not supporting older versions of Go... especially a version that is almost a year old. I think if anyone needs the new feature they can upgrade to the new version.

Just to double check my understanding, are you suggesting one of these approaches:

  1. To drop Go 1.24 support completely with the new version (i.e. change go.mod to require go 1.25.0 and CI matrix across all workflows)?

  2. Alternatively, to put the ArchivesFromFS functionality in a separate file with a //go:build go1.25 build tag?

I'm assuming you meant option 1 from above, but I figured I'd double check before I went ahead and implemented.

@mholt
Copy link
Owner

mholt commented Dec 5, 2025

Right, thanks -- to clarify, I was thinking the first option (bump up the minimum version).

Signed-off-by: Joonas Bergius <joonas@bergi.us>
Signed-off-by: Joonas Bergius <joonas@bergi.us>
@joonas joonas requested a review from mholt December 7, 2025 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functionality for mapping files from fs.FS

2 participants