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

Issue #55 - Correct ZIP entry names when created on a Windows system #56

Merged
merged 1 commit into from
Oct 29, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ object ZipHelper {
archive(mappings.toSeq, outputZip)
}

/**
* Replaces windows backslash file separator with a forward slash, this ensures the zip file entry is correct for
* any system it is extracted on.
* @param path The path of the file in the zip file
*/
private def normalizePath(path: String) = {
val sep = java.io.File.separatorChar
if (sep == '/')
path
else
path.replace(sep, '/')
}


private def archive(sources: Seq[FileMapping], outputFile: File): Unit = {
if(outputFile.isDirectory) sys.error("Specified output file " + outputFile + " is a directory.")
Expand All @@ -73,7 +86,7 @@ object ZipHelper {
IO createDirectory outputDir
withZipOutput(outputFile) { output =>
for(FileMapping(file, name, mode) <- sources; if !file.isDirectory) {
val entry = new ZipArchiveEntry(file, name)
val entry = new ZipArchiveEntry(file, normalizePath(name))
// Now check to see if we have permissions for this sucker.
mode foreach (entry.setUnixMode)
output putArchiveEntry entry
Expand Down