java - Short filename causing issues with two otherwise identical Paths -


i used

files.createtempfile("hello", "txt");

to create temporary file , stored returned path.

i have eclipse ifile resource linked temporary file created:

linkedfile.createlink(tempfile.touri(), iresource.none, null);

if want path resource, call

linkedfile.getlocation().tofile().topath()

on local machine, works 100% fine. on remote test machine, 2 different paths:

from files.createtempfile: c:\users\userna~1\appdata\local\temp\hello3606197456871226795txt

from getlocation().tofile().topath() c:\users\username_testing\appdata\local\temp\hello3606197456871226795txt

the folder username_testing , folder gets turned short filename, , direct creation of temporary.

these 2 paths not considered equal path.equals(...), causing failing of tests on remote machine.

in general, makes me bit nervous using path.equals(...) though in actual real operation of application haven't had issues yet. there way can force system always use long filenames? there i'm missing should aware of when path equality checks, or when converting paths 1 form another?

update #1: specific issue caused %temp% on target windows machine returning path using short filename, doesn't happen on local machine. test code creates temporary files , folders won't affect real application. obvious solution current problem fix %temp% tests run fine in both places, solution not viable in general sense. nice if there way rectify situation without modifying target computer or jumping native or windows specific code, since used no such code directly both paths.

i found good, portable solution problem, no need use platform-specific code. answer quite simple:

path.torealpath()

used this:

path correctedtempfile = tempfile.torealpath()

essentially, using torealpath() version, thankfully removes short filenames, comparisons against other paths taken eclipse resources. believe eclipse implementation using long paths consistency, in turn use torealpath rid of potential paths may use short filenames


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -