42 throw new IOException(
"Directory " + dest.getAbsolutePath() +
" already exists. Unpacking exiting");
46 ArchiveEntry tarEntry = tarIn.getNextEntry();
47 while (tarEntry !=
null) {
50 int defaultMode = 0750;
54 mode = ((TarArchiveEntry) tarEntry).getMode();
57 mode = ((ZipArchiveEntry) tarEntry).getUnixMode();
63 if (_logger.isTraceEnabled())
64 _logger.debug(
"The mode on '" + tarEntry.getName() +
"' is " + Integer.toOctalString(mode));
65 if (grantUserPermsToGroup) {
66 int temp = mode & 0700;
69 if (_logger.isTraceEnabled())
70 _logger.debug(
"Now mode on '" + tarEntry.getName() +
"' is " + Integer.toOctalString(mode));
75 File destPath =
new File(dest, tarEntry.getName());
76 if (_logger.isTraceEnabled())
77 _logger.debug(
"working on: " + destPath.getCanonicalPath());
78 if (tarEntry.isDirectory()) {
81 destPath.createNewFile();
84 byte[] btoRead =
new byte[8192];
85 BufferedOutputStream bout =
new BufferedOutputStream(
new FileOutputStream(destPath));
87 boolean wroteAnything =
false;
88 while ((len = tarIn.read(btoRead)) != -1) {
89 if (_logger.isTraceEnabled())
90 _logger.debug(
"read " + len +
" bytes");
92 bout.write(btoRead, 0, len);
95 _logger.error(
"zero bytes read from: " + destPath.getCanonicalPath());
101 HashSet<PosixFilePermission> perms =
new HashSet<PosixFilePermission>();
103 if ((mode & 0400) != 0)
104 perms.add(PosixFilePermission.OWNER_READ);
105 if ((mode & 0200) != 0)
106 perms.add(PosixFilePermission.OWNER_WRITE);
107 if ((mode & 0100) != 0)
108 perms.add(PosixFilePermission.OWNER_EXECUTE);
110 if ((mode & 0040) != 0)
111 perms.add(PosixFilePermission.GROUP_READ);
112 if ((mode & 0020) != 0)
113 perms.add(PosixFilePermission.GROUP_WRITE);
114 if ((mode & 0010) != 0)
115 perms.add(PosixFilePermission.GROUP_EXECUTE);
117 if ((mode & 0004) != 0)
118 perms.add(PosixFilePermission.OTHERS_READ);
119 if ((mode & 0002) != 0)
120 perms.add(PosixFilePermission.OTHERS_WRITE);
121 if ((mode & 0001) != 0)
122 perms.add(PosixFilePermission.OTHERS_EXECUTE);
124 Files.setPosixFilePermissions(Paths.get(destPath.getCanonicalPath()), perms);
125 tarEntry = tarIn.getNextEntry();
130 public synchronized static void uncompressTarGZ(File tarFile, File dest,
boolean grantUserPermsToGroup)
throws IOException
132 TarArchiveInputStream tarIn =
new TarArchiveInputStream(
new GzipCompressorInputStream(
new FileInputStream(tarFile)));