-
Notifications
You must be signed in to change notification settings - Fork 870
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
Fixed a bug in ArchiveExtractor that caused it to fail on case-insens… #843
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ bin | |
travis/codesigning.asc | ||
frontend-plugin-core/target | ||
frontend-maven-plugin/target | ||
|
||
#macOS | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ private void prepDestination(File path, boolean directory) throws IOException { | |
if (!path.getParentFile().exists()) { | ||
path.getParentFile().mkdirs(); | ||
} | ||
if(!path.getParentFile().canWrite()) { | ||
if (!path.getParentFile().canWrite()) { | ||
throw new AccessDeniedException( | ||
String.format("Could not get write permissions for '%s'", path.getParentFile().getAbsolutePath())); | ||
} | ||
|
@@ -60,17 +60,17 @@ public void extract(String archive, String destinationDirectory) throws ArchiveE | |
try (FileInputStream fis = new FileInputStream(archiveFile)) { | ||
if ("msi".equals(FileUtils.getExtension(archiveFile.getAbsolutePath()))) { | ||
String command = "msiexec /a " + archiveFile.getAbsolutePath() + " /qn TARGETDIR=\"" | ||
+ destinationDirectory + "\""; | ||
+ destinationDirectory + "\""; | ||
Process child = Runtime.getRuntime().exec(command); | ||
try { | ||
int result = child.waitFor(); | ||
if (result != 0) { | ||
throw new ArchiveExtractionException( | ||
"Could not extract " + archiveFile.getAbsolutePath() + "; return code " + result); | ||
"Could not extract " + archiveFile.getAbsolutePath() + "; return code " + result); | ||
} | ||
} catch (InterruptedException e) { | ||
throw new ArchiveExtractionException( | ||
"Unexpected interruption of while waiting for extraction process", e); | ||
"Unexpected interruption of while waiting for extraction process", e); | ||
} | ||
} else if ("zip".equals(FileUtils.getExtension(archiveFile.getAbsolutePath()))) { | ||
ZipFile zipFile = new ZipFile(archiveFile); | ||
|
@@ -80,7 +80,7 @@ public void extract(String archive, String destinationDirectory) throws ArchiveE | |
ZipEntry entry = entries.nextElement(); | ||
final File destPath = new File(destinationDirectory + File.separator + entry.getName()); | ||
prepDestination(destPath, entry.isDirectory()); | ||
if(!entry.isDirectory()){ | ||
if (!entry.isDirectory()) { | ||
InputStream in = null; | ||
OutputStream out = null; | ||
try { | ||
|
@@ -104,16 +104,18 @@ public void extract(String archive, String destinationDirectory) throws ArchiveE | |
tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(fis)); | ||
|
||
TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); | ||
String canonicalDestinationDirectory = new File(destinationDirectory).getCanonicalPath(); | ||
while (tarEntry != null) { | ||
// Create a file for this tarEntry | ||
final File destPath = new File(destinationDirectory + File.separator + tarEntry.getName()); | ||
prepDestination(destPath, tarEntry.isDirectory()); | ||
if (!destPath.getCanonicalPath().startsWith(canonicalDestinationDirectory)) { | ||
throw new IOException( | ||
"Expanding " + tarEntry.getName() + " would create file outside of " + canonicalDestinationDirectory | ||
); | ||
|
||
|
||
if (!startsWithPath(destPath.getCanonicalPath(), destinationDirectory)) { | ||
throw new IOException( | ||
"Expanding " + tarEntry.getName() + " would create file outside of " + destinationDirectory | ||
); | ||
} | ||
|
||
if (!tarEntry.isDirectory()) { | ||
destPath.createNewFile(); | ||
boolean isExecutable = (tarEntry.getMode() & 0100) > 0; | ||
|
@@ -139,4 +141,46 @@ public void extract(String archive, String destinationDirectory) throws ArchiveE | |
+ "'", e); | ||
} | ||
} | ||
|
||
/** | ||
* Do multiple file system checks that should enable the plugin to work on any file system | ||
* whether or not it's case sensitive or not. | ||
* | ||
* @param destPath | ||
* @param destDir | ||
* @return | ||
*/ | ||
private boolean startsWithPath(String destPath, String destDir) { | ||
if (destDir.startsWith(destDir)) { | ||
return true; | ||
} else if (destDir.length() > destPath.length()) { | ||
return false; | ||
} else { | ||
/* | ||
* The first check should handle case-sensitive file systems. We need this | ||
* in order to weed out case-sensitive file systems with a non-existent path | ||
* that slipped through the first test. | ||
*/ | ||
if (new File(destPath).exists() && !(new File(destPath.toLowerCase()).exists())) { | ||
eirslett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
} | ||
|
||
boolean retVal = true; | ||
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. Why is this stuff going on? Isn't it easier with |
||
for (int index = 0; index < destDir.length(); index++) { | ||
char left = destPath.charAt(index); | ||
char right = destDir.charAt(index); | ||
|
||
if (left != right) { | ||
char leftUc = Character.toUpperCase(left); | ||
char rightUc = Character.toUpperCase(right); | ||
|
||
if (leftUc != rightUc) { | ||
retVal = false; | ||
} | ||
} | ||
} | ||
|
||
return retVal; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Won't this check always be true? Is it supposed to be
destPath
?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.
That was a typo on my part.