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

Suggestion: Improvement of check if filepath is relative #821

Open
o0lwj0o opened this issue Jan 10, 2019 · 3 comments
Open

Suggestion: Improvement of check if filepath is relative #821

o0lwj0o opened this issue Jan 10, 2019 · 3 comments

Comments

@o0lwj0o
Copy link

o0lwj0o commented Jan 10, 2019

I have found that you check if a filepath is relative by “filepath.startWith(“/”)”. However the File offer an official API File. isAbsolute().

isAbsolute
public boolean isAbsolute()
Tests whether this abstract pathname is absolute. The definition of absolute pathname is system dependent. On UNIX systems, a pathname is absolute if its prefix is "/". On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by "\", or if its prefix is "\\".
Returns:
true if this abstract pathname is absolute, false otherwise

This will not only meet your need, but also deal with the different expression of relative file path.

Although there may be a lot of work, i think it is worth refactoring it.

Detail websites and lines are listed below

22 | https://github.com/vrapper/vrapper/blob/master/net.sourceforge.vrapper.core/src/net/sourceforge/vrapper/vim/commands/EditFileCommand.java
59 | https://github.com/vrapper/vrapper/blob/master/plugins/ports/net.sourceforge.vrapper.plugin.splitEditor/src/net/sourceforge/vrapper/plugin/splitEditor/commands/SplitEditorCommand.java
235 | https://github.com/vrapper/vrapper/blob/master/net.sourceforge.vrapper.core/src/net/sourceforge/vrapper/vim/register/DefaultRegisterManager.java
307 622 | https://github.com/vrapper/vrapper/blob/master/net.sourceforge.vrapper.eclipse/src/net/sourceforge/vrapper/eclipse/platform/EclipseFileService.java

Best regards

@keforbes
Copy link
Contributor

Have you actually ran into an issue and proven that this fixes the issue or is this just an idea from eyeballing the code?

I don't remember the specifics, but I think I was doing it this way because the filepath is actually generated by Eclipse where the path always starts with /projectname rather than the actual path on disk.
See here:

It's been awhile since I've looked at this code so it's entirely possible you're right, and I'm sure there are opportunities for refactoring. However, in this instance, I believe there is a reason for using startsWith('/') which isn't just ignorance on my part. This isn't an OS-dependent feature, it's relative to the Eclipse workspace root dir rather than the disk root dir.

@keforbes
Copy link
Contributor

Also, here's a link to my rant from almost 7 years ago which might be relevant:
#114 (comment)

@albertdev
Copy link
Member

albertdev commented Jan 11, 2019

Thank you for taking an interest in Vrapper!

I believe that Eclipse uses URIs and hence the URI path separator (i.e. a regular slash) in its file APIs, and so I agree with what @keforbes is saying.

I'm running Windows so I'll double-check when I got some free time (January tends to be a time to meet friends and family, so free time tends to be scarce).

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

3 participants