thrau / jarchivelib

A simple archiving and compression library for Java
https://github.com/thrau/jarchivelib
Apache License 2.0
199 stars 36 forks source link

Archive creation fails if directory name is shorter than 3 characters #64

Open michaelboyles opened 6 years ago

michaelboyles commented 6 years ago

File.createTempFile is called with the given directory's name as a prefix. If it's too short, this will fail with an IllegalArgumentException. The prefix should be padded so this doesn't happen.

File destinationFile = new File("/var/tmp/1")
File sourceFile = new File("/var/tmp/2")

Archiver arch = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP)
File archiveFile = arch.create("64cacf30-b294-49f4-b166-032a808d73cd", destinationFile, sourceFile)

See: https://stackoverflow.com/questions/48806562/java-io-file-prefix-string-too-short-but-its-not

axelhuberty commented 6 years ago

The prefix should use the String archive instead of the File destination name. If the value is still too short, simply provide a constant value (jarch), this is a temporary file so this is not important.