Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling long paths inside of archives #42

Open
osean-man opened this issue Jan 16, 2024 · 1 comment
Open

Handling long paths inside of archives #42

osean-man opened this issue Jan 16, 2024 · 1 comment

Comments

@osean-man
Copy link

I have scenarios where the total length of the file paths being extracted are too long for the system's maximum path length. Mostly with naming from languages outside of english. Anyway, before I make a PR, I was wondering if there is something I'm missing in the code that can supress this error or ideally can handle it properly?

Again, I am looking at the code and it doesn't look like it but, I can be blind sometimes, so I figured I'd ask before I start a PR.

And for the sake of clarity and example, I a check like this in rar.go:

func MaxPathLength ...
	// find the max path length based on the system and return it
   // or, if that's annoying, then just set the max to a const with some sane limit that works for all systems 
func (x *XFile) unrar(rarReader *rardecode.ReadCloser) (int64, []string, error) {
    ...
    for {
        header, err := rarReader.Next()
		...

        wfile := x.clean(header.Name)
        
        if len(wfile) > MaxPathLength() {
            // Skip the file with some warning or something...
            log.Warnf("Skipping file with long path: %s", wfile)
            continue

            // Or, what woiuld be even better is truncate the file name somehow inside the archive...
        }

    }
}

Your library came in as a life saver for me, so thank you for your work! 👍

PS: if I do a PR, I'm thinking a handler for this so the user can handle the logic for dealing with it but I'm open to whatever you think would be best for your package.

@davidnewhall
Copy link
Contributor

I was wondering if there is something I'm missing in the code

I've never hit a max length error, so never had to fix this problem.

You mentioned suppressing an error, but didn't provide one to suppress. You also asked about handling the error properly, but I'm not sure what that actually means. How that situation gets handled properly is likely subjective. The handler idea sounds ideal for this reason. We can work together to solve it, throw up a PR so we can collaborate.

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

No branches or pull requests

2 participants