/**
* Reads from a tar stream and stores obtained files to the base dir.
*/
private static void readFromTar(String name, File baseDir, InputStream in) throws IOException {
TarInputStream t = new TarInputStream(in);
try {
TarEntry te;
while ((te = t.getNextEntry()) != null) {
File f = new File(baseDir,te.getName());
if(te.isDirectory()) {
f.mkdirs();
} else {
File parent = f.getParentFile();
if (parent != null) parent.mkdirs();
byte linkFlag = (Byte) LINKFLAG_FIELD.get(te);
if (linkFlag==TarEntry.LF_SYMLINK) {
new FilePath(f).symlinkTo(te.getLinkName(), TaskListener.NULL);
} else {
IOUtils.copy(t,f);
f.setLastModified(te.getModTime().getTime());
int mode = te.getMode()&0777;
if(mode!=0 && !Functions.isWindows()) // be defensive
_chmod(f,mode);
}
}
}
} catch(IOException e) {
throw new IOException2("Failed to extract "+name,e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // process this later
throw new IOException2("Failed to extract "+name,e);
} catch (IllegalAccessException e) {
throw new IOException2("Failed to extract "+name,e);
} finally {
t.close();
}
}