@@ -223,49 +223,54 @@ object Archives {
223
223
* @param target folder to build package in
224
224
* @param name of output (without extension)
225
225
* @param mappings included in the output
226
- * @param top level directory
226
+ * @param topDirectory level directory
227
227
* @param options for tar command
228
228
* @return tar file
229
229
*
230
230
*/
231
- def makeTarballWithOptions (
232
- compressor : File => File ,
233
- ext : String
234
- )( target : File , name : String , mappings : Seq [( File , String )], top : Option [ String ], options : Seq [String ]) : File = {
235
- val relname = name
231
+ def makeTarballWithOptions (compressor : File => File , ext : String )( target : File ,
232
+ name : String ,
233
+ mappings : Seq [( File , String )],
234
+ topDirectory : Option [String ],
235
+ options : Seq [ String ]) : File = {
236
236
val tarball = target / (name + ext)
237
- IO .withTemporaryDirectory { f =>
238
- val rdir = f / relname
239
- val m2 = top map { dir =>
240
- mappings map { case (f, p) => f -> (rdir / dir / p) }
241
- } getOrElse {
242
- mappings map { case (f, p) => f -> (rdir / p) }
243
- }
237
+ IO .withTemporaryDirectory { tempDirectory =>
238
+ val workingDirectory = tempDirectory / name
239
+ val temporaryMappings = topDirectory
240
+ .map { dir =>
241
+ mappings map { case (f, p) => f -> (workingDirectory / dir / p) }
242
+ }
243
+ .getOrElse {
244
+ mappings map { case (f, p) => f -> (workingDirectory / p) }
245
+ }
244
246
245
- IO .copy(m2)
246
- // TODO - Is this enough?
247
- for ((from, to) <- m2 if (to.getAbsolutePath contains " /bin/" ) || from.canExecute) {
247
+ // create the working directory
248
+ IO .createDirectory(workingDirectory)
249
+ IO .copy(temporaryMappings)
250
+ // setExecutable does not always work. There are known issues with macOSx where
251
+ // the executable flags is missing after compression.
252
+ for ((from, to) <- temporaryMappings if (to.getAbsolutePath contains " /bin/" ) || from.canExecute) {
248
253
println(" Making " + to.getAbsolutePath + " executable" )
249
254
to.setExecutable(true , false )
250
255
}
251
256
252
257
IO .createDirectory(tarball.getParentFile)
253
258
254
259
// all directories that should be zipped
255
- val distdirs = top map (_ :: Nil ) getOrElse {
256
- IO .listFiles(rdir ).map(_.getName).toList // no top level dir, use all available
260
+ val distdirs = topDirectory. map(_ :: Nil ). getOrElse {
261
+ IO .listFiles(workingDirectory ).map(_.getName).toList // no top level dir, use all available
257
262
}
258
263
259
- val tmptar = f / (relname + " .tar" )
264
+ val temporaryTarFile = tempDirectory / (name + " .tar" )
260
265
261
- val cmd = Seq (" tar" ) ++ options ++ Seq (tmptar .getAbsolutePath) ++ distdirs
266
+ val cmd = Seq (" tar" ) ++ options ++ Seq (temporaryTarFile .getAbsolutePath) ++ distdirs
262
267
println(" Running with " + cmd.mkString(" " ))
263
- sys.process.Process (cmd, Some (rdir) ).! match {
268
+ sys.process.Process (cmd, workingDirectory ).! match {
264
269
case 0 => ()
265
270
case n =>
266
271
sys.error(" Error tarballing " + tarball + " . Exit code: " + n)
267
272
}
268
- IO .copyFile(compressor(tmptar ), tarball)
273
+ IO .copyFile(compressor(temporaryTarFile ), tarball)
269
274
}
270
275
tarball
271
276
}
0 commit comments