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

add normalized `.path()` to FileHandle #2617

Closed
ghost opened this Issue Dec 1, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@ghost

ghost commented Dec 1, 2014

It's a feature present both in core Java 7 lib (which is currently unsupported neither in libGDX nor on Android) [https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html#normalize%28%29] and in Apache Commons IO [http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FilenameUtils.html#normalize%28java.lang.String%29], and is a quite nice & simple feature. It makes the path more "canonical" by getting rid of e.g. . & .. and it's required in some cases, e.g. if the dotted paths point to internal JAR content (happened to me with relative texture paths provided from .MTL file); using an non-normalized path results in "file not found", using a normalized one works as expected.

Currently we have to either convert the FileHandle.path() by means of URI or include an additional library just for the sake of it, both being ugly & kludgy. Porting either Java 7's or Apache IO's normalizer (both are Open Source AFAIK) and exporting it as .pathNormalized() would be IMO the best solution here.

@ghost ghost changed the title from add path normalizer to FileHandle to add normalized `.path()` to FileHandle Dec 1, 2014

@NathanSweet

This comment has been minimized.

Show comment
Hide comment
@NathanSweet

NathanSweet Dec 1, 2014

Member

handle.file().getAbsolutePath() probably does most or all of what you need.

Member

NathanSweet commented Dec 1, 2014

handle.file().getAbsolutePath() probably does most or all of what you need.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Dec 1, 2014

Sadly, no. Tried it already, it's a no-go. As e.g. http://docs.oracle.com/javase/7/docs/api/java/io/File.html#getAbsolutePath%28%29 & http://stackoverflow.com/questions/1099300/whats-the-difference-between-getpath-getabsolutepath-and-getcanonicalpath show clearly - the functionalities of absolute path and normalized path are quite distinct. Absolute path is usually normalized when generated by OS (although that's not guaranteed vs absolute paths, only canonical paths), but not every normalized path has to be absolute. Sometimes you need a relative, yet normalized path. That's the exact case I described here. Also, absolute paths are resolved in OS-dependent way. The function that guarantees a normalized path is http://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath%28%29 - but it always returns an absolute path, so it can't be applied to paths that has to stay relative.

Having a normalizer to normalize relative paths is a completely valid use case - otherwise nobody would even care with creating a normalizer for paths IMO.

NB this is obviously an enhancement request, not a bug report.

ghost commented Dec 1, 2014

Sadly, no. Tried it already, it's a no-go. As e.g. http://docs.oracle.com/javase/7/docs/api/java/io/File.html#getAbsolutePath%28%29 & http://stackoverflow.com/questions/1099300/whats-the-difference-between-getpath-getabsolutepath-and-getcanonicalpath show clearly - the functionalities of absolute path and normalized path are quite distinct. Absolute path is usually normalized when generated by OS (although that's not guaranteed vs absolute paths, only canonical paths), but not every normalized path has to be absolute. Sometimes you need a relative, yet normalized path. That's the exact case I described here. Also, absolute paths are resolved in OS-dependent way. The function that guarantees a normalized path is http://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath%28%29 - but it always returns an absolute path, so it can't be applied to paths that has to stay relative.

Having a normalizer to normalize relative paths is a completely valid use case - otherwise nobody would even care with creating a normalizer for paths IMO.

NB this is obviously an enhancement request, not a bug report.

@ghost ghost referenced this issue Dec 23, 2014

Closed

ObjLoader group naming #2436

@badlogic

This comment has been minimized.

Show comment
Hide comment
@badlogic

badlogic Feb 2, 2015

Member

I welcome a PR, i don't think we'll implement this otherwise.

Member

badlogic commented Feb 2, 2015

I welcome a PR, i don't think we'll implement this otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment