私のインストーラーに組み込まれている mysql や tomcat などの tarball の解凍と解凍を処理する実行スクリプトを install4j に追加しようとしています。これらの tar を ant のビルド プロセスの一部として展開できることはわかっていますが、少なくとも 1 つのユース ケースではそれができません。
org.apache.tools.tar.TarEntry および TarInputStream クラスを使用して、Run Script アクションに以下のコードを含めました。これはかなりうまく機能していますが、1 つのバグがあります。
この実装を使用すると、99 文字を超えるファイル パスが切り捨てられ、結果のファイルが最上位ディレクトリに展開されます。
これが私の実装のバグなのか、Apache ツール クラスの問題なのかを突き止めようとしています。99 文字を超える場合、tarEntry.getName() がパス全体を返していないようです。TarInputStream の機能を書き直さなくても、これを回避する簡単な方法はありますか? Tar.Entry には isGNULongNameEntry メソッドがありますが、これが true を返したときにファイルをどこに置くべきかを説明する信頼できる方法を見つけられないようです。
助言がありますか?
import java.io.*;
import java.util.zip.*;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
String outputDirectory = "mysql";
File tgzFile = new File(context.getInstallationDirectory(), outputDirectory + File.separator + "mysql-5.5.17-linux2.6-i686.tar.gz");
// Create the Tar input stream.
FileInputStream fin = new FileInputStream(tgzFile);
GZIPInputStream gin = new GZIPInputStream(fin);
TarInputStream tin = new TarInputStream(gin);
// Create the destination directory.
File outputDir = new File(outputDirectory);
outputDir.mkdir();
// Extract files.
TarEntry tarEntry = tin.getNextEntry();
while (tarEntry != null) {
File destPath = new File(context.getInstallationDirectory(), outputDirectory + File.separator + tarEntry.getName());
tarEntry.isGNULongNameEntry()
if (tarEntry.isDirectory()) {
destPath.mkdirs();
} else {
// If the parent directory of a file doesn't exist, create it.
if (!destPath.getParentFile().exists())
destPath.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(destPath);
tin.copyEntryContents(fout);
fout.close();
// Presserve the last modified date of the tar'd files.
destPath.setLastModified(tarEntry.getModTime().getTime());
}
tarEntry = tin.getNextEntry();
}
tin.close();
return true;