Skip to content

Commit

Permalink
Correct ZIP entry names when created on a Windows system
Browse files Browse the repository at this point in the history
When a ZIP entry was created on a Windows system and used the Windows file
separator, the entries when unzipped on Linux, would include the directory
name as part of the filename.
  • Loading branch information
doswell committed Oct 29, 2013
1 parent 8f94469 commit 04a566d
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 04a566d

Please sign in to comment.