use of org.jboss.fuse.patch.management.io.EOLFixingFileOutputStream in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceImpl method unpack.
/**
* Unpacks a ZIP file to targetDirectory
* @param zipFile
* @param targetDirectory
* @param skipInitialDirectories how many levels of a path to skip when unpacking (like skipping base directory inside ZIP)
* @throws IOException
*/
public static void unpack(File zipFile, File targetDirectory, int skipInitialDirectories) throws IOException {
try (ZipFile zf = new ZipFile(zipFile)) {
for (Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements(); ) {
ZipArchiveEntry entry = e.nextElement();
String name = entry.getName();
int skip = skipInitialDirectories;
while (skip-- > 0) {
name = name.substring(name.indexOf('/') + 1);
}
if (entry.isDirectory()) {
mkdirs(new File(targetDirectory, name));
} else /*if (!entry.isUnixSymlink())*/
{
File file = new File(targetDirectory, name);
mkdirs(file.getParentFile());
FileOutputStream output = new EOLFixingFileOutputStream(targetDirectory, file);
IOUtils.copyLarge(zf.getInputStream(entry), output);
closeQuietly(output);
if (Files.getFileAttributeView(file.toPath(), PosixFileAttributeView.class) != null) {
Files.setPosixFilePermissions(file.toPath(), getPermissionsFromUnixMode(file, entry.getUnixMode()));
}
}
}
}
}
use of org.jboss.fuse.patch.management.io.EOLFixingFileOutputStream in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceImpl method unzipKarafInstanceJar.
/**
* Unzips <code>bin</code> and <code>etc</code> from org.apache.karaf.instance.core.
* @param artifact
* @param targetDirectory
* @throws IOException
*/
private void unzipKarafInstanceJar(File artifact, File targetDirectory) throws IOException {
String prefix = "org/apache/karaf/instance/resources/";
try (ZipFile zf = new ZipFile(artifact)) {
for (Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements(); ) {
ZipArchiveEntry entry = e.nextElement();
String name = entry.getName();
if (!name.startsWith(prefix)) {
continue;
}
name = name.substring(prefix.length());
if (!name.startsWith("bin") && !name.startsWith("etc")) {
continue;
}
// flags from karaf.instance.core
// see: org.apache.karaf.instance.core.internal.InstanceServiceImpl.createInstance()
boolean windows = System.getProperty("os.name").startsWith("Win");
boolean cygwin = windows && new File(System.getProperty("karaf.home"), "bin/instance").exists();
if (!entry.isDirectory() && !entry.isUnixSymlink()) {
if (windows && !cygwin) {
if (name.startsWith("bin/") && !name.endsWith(".bat")) {
continue;
}
} else {
if (name.startsWith("bin/") && name.endsWith(".bat")) {
continue;
}
}
File file = new File(targetDirectory, name);
Utils.mkdirs(file.getParentFile());
FileOutputStream output = new EOLFixingFileOutputStream(targetDirectory, file);
IOUtils.copyLarge(zf.getInputStream(entry), output);
Utils.closeQuietly(output);
if (Files.getFileAttributeView(file.toPath(), PosixFileAttributeView.class) != null) {
if (name.startsWith("bin/") && !name.endsWith(".bat")) {
Files.setPosixFilePermissions(file.toPath(), getPermissionsFromUnixMode(file, 0775));
}
}
}
}
}
}
Aggregations