-
Notifications
You must be signed in to change notification settings - Fork 310
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
#62 Canonical path fix #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,41 +181,46 @@ public static List<File> getSplitZipFiles(ZipModel zipModel) throws ZipException | |
return splitZipFiles; | ||
} | ||
|
||
public static String getRelativeFileName(String file, String rootFolderPath) { | ||
public static String getRelativeFileName(String file, String rootFolderPath) throws ZipException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above also here: Is it necessary to also change this method? I think just changing it above in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary. Please refer to my following comment. |
||
|
||
String fileName; | ||
if (isStringNotNullAndNotEmpty(rootFolderPath)) { | ||
File rootFolderFile = new File(rootFolderPath); | ||
String rootFolderFileRef = rootFolderFile.getPath(); | ||
try { | ||
String fileCanonicalPath = new File(file).getCanonicalPath(); | ||
if (isStringNotNullAndNotEmpty(rootFolderPath)) { | ||
File rootFolderFile = new File(rootFolderPath); | ||
String rootFolderFileRef = rootFolderFile.getCanonicalPath(); | ||
|
||
if (!rootFolderFileRef.endsWith(FILE_SEPARATOR)) { | ||
rootFolderFileRef += FILE_SEPARATOR; | ||
} | ||
if (!rootFolderFileRef.endsWith(FILE_SEPARATOR)) { | ||
rootFolderFileRef += FILE_SEPARATOR; | ||
} | ||
|
||
String tmpFileName = file.substring(rootFolderFileRef.length()); | ||
if (tmpFileName.startsWith(System.getProperty("file.separator"))) { | ||
tmpFileName = tmpFileName.substring(1); | ||
} | ||
String tmpFileName = fileCanonicalPath.substring(rootFolderFileRef.length()); | ||
if (tmpFileName.startsWith(System.getProperty("file.separator"))) { | ||
tmpFileName = tmpFileName.substring(1); | ||
} | ||
|
||
File tmpFile = new File(file); | ||
File tmpFile = new File(fileCanonicalPath); | ||
|
||
if (tmpFile.isDirectory()) { | ||
tmpFileName = tmpFileName.replaceAll("\\\\", "/"); | ||
tmpFileName += ZIP_FILE_SEPARATOR; | ||
} else { | ||
String bkFileName = tmpFileName.substring(0, tmpFileName.lastIndexOf(tmpFile.getName())); | ||
bkFileName = bkFileName.replaceAll("\\\\", "/"); | ||
tmpFileName = bkFileName + tmpFile.getName(); | ||
} | ||
if (tmpFile.isDirectory()) { | ||
tmpFileName = tmpFileName.replaceAll("\\\\", "/"); | ||
tmpFileName += ZIP_FILE_SEPARATOR; | ||
} else { | ||
String bkFileName = tmpFileName.substring(0, tmpFileName.lastIndexOf(tmpFile.getName())); | ||
bkFileName = bkFileName.replaceAll("\\\\", "/"); | ||
tmpFileName = bkFileName + tmpFile.getName(); | ||
} | ||
|
||
fileName = tmpFileName; | ||
} else { | ||
File relFile = new File(file); | ||
if (relFile.isDirectory()) { | ||
fileName = relFile.getName() + ZIP_FILE_SEPARATOR; | ||
fileName = tmpFileName; | ||
} else { | ||
fileName = relFile.getName(); | ||
File relFile = new File(fileCanonicalPath); | ||
if (relFile.isDirectory()) { | ||
fileName = relFile.getName() + ZIP_FILE_SEPARATOR; | ||
} else { | ||
fileName = relFile.getName(); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new ZipException(e); | ||
} | ||
|
||
return fileName; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to also change this method? I think just changing it above in
AbstractExtractFileTask.java
is enough?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently this change will not work because the
getDefaultFolderPath
is only used when callinggetRelativeFileName
in my following change.But this
setDefaultFolderPath
here will set default folder path to some path like/home/test/testDir/../testDir
if I'm adding a folder with not normalized folder path. I think this may lead to some other exceptions if some other method callsgetDefaultFolderPath
in future.I think it's better to fix it this time. What do you think?