Skip to content

Commit

Permalink
Merge pull request #56 from doswell/windows-zip-name-fix
Browse files Browse the repository at this point in the history
Issue #55 - Correct ZIP entry names when created on a Windows system
  • Loading branch information
jsuereth committed Oct 29, 2013
2 parents 8f94469 + 04a566d commit 3c00ac7
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit 3c00ac7

Please sign in to comment.