Canonicalize the path, i.e. remove ".." and "." occurences.
int dirIndex;
while ((dirIndex = path.indexOf("/./")) >= 0) { //$NON-NLS-1$
path = path.substring(0, dirIndex + 1)
+ path.substring(dirIndex + 3);
}
if (path.endsWith("/.")) { //$NON-NLS-1$
path = path.substring(0, path.length() - 1);
}
while ((dirIndex = path.indexOf("/../")) >= 0) { //$NON-NLS-1$
if (dirIndex != 0) {
path = path.substring(0, path
.lastIndexOf('/", dirIndex - 1))
+ path.substring(dirIndex + 3);
} else {
path = path.substring(dirIndex + 3);
}
}
if (path.endsWith("/..") && path.length() > 3) { //$NON-NLS-1$
path = path.substring(0, path.lastIndexOf('/",
path.length() - 4) + 1);
}
return path;