org.apache.commons.compress.archivers.tar.TarConstants Java Examples

The following examples show how to use org.apache.commons.compress.archivers.tar.TarConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MountableFile.java    From testcontainers-java with MIT License 6 votes vote down vote up
@UnstableAPI
public static int getUnixFileMode(final Path path) {
    try {
        int unixMode = (int) Files.readAttributes(path, "unix:mode").get("mode");
        // Truncate mode bits for z/OS
        if ("OS/390".equals(SystemUtils.OS_NAME) ||
            "z/OS".equals(SystemUtils.OS_NAME) ||
            "zOS".equals(SystemUtils.OS_NAME) ) {
            unixMode &= TarConstants.MAXID;
            unixMode |= Files.isDirectory(path) ? 040000 : 0100000;
        }
        return unixMode;
    } catch (IOException | UnsupportedOperationException e) {
        // fallback for non-posix environments
        int mode = DEFAULT_FILE_MODE;
        if (Files.isDirectory(path)) {
            mode = DEFAULT_DIR_MODE;
        } else if (Files.isExecutable(path)) {
            mode |= 0111; // equiv to +x for user/group/others
        }

        return mode;
    }
}
 
Example #2
Source File: MCRTarServlet.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void sendCompressedDirectory(MCRPath file, BasicFileAttributes attrs,
    TarArchiveOutputStream container) throws IOException {
    TarArchiveEntry entry = new TarArchiveEntry(getFilename(file), TarConstants.LF_DIR);
    entry.setModTime(attrs.lastModifiedTime().toMillis());
    container.putArchiveEntry(entry);
    container.closeArchiveEntry();
}
 
Example #3
Source File: Archiver.java    From digdag with Apache License 2.0 5 votes vote down vote up
private TarArchiveEntry createSymlinkEntryOrNull(Path projectPath, Path absPath, String resourceName,
        boolean copyOutgoingSymlinks)
        throws IOException
{
    Path rawDest = Files.readSymbolicLink(absPath);
    Path normalizedAbsDest = absPath.getParent().resolve(rawDest).normalize();

    if (!normalizedAbsDest.startsWith(projectPath)) {
        // outside of projectPath
        if (copyOutgoingSymlinks) {
            return null;
        }
        throw new IllegalArgumentException(String.format(ENGLISH,
                    "Invalid symbolic link: Given path '%s' is outside of project directory '%s'. Consider to add --copy-outgoing-symlinks option", normalizedAbsDest, projectPath));
    }

    // Create a TarArchiveEntry of symlink
    TarArchiveEntry e = new TarArchiveEntry(resourceName, TarConstants.LF_SYMLINK);

    // absolute path will be invalid on a server. convert it to a relative path
    Path normalizedRelativeDest = absPath.getParent().relativize(normalizedAbsDest);

    String linkName = normalizedRelativeDest.toString();

    // TarArchiveEntry(File) does this normalization but setLinkName doesn't. So do it here:
    linkName = linkName.replace(File.separatorChar, '/');
    e.setLinkName(linkName);

    return e;
}
 
Example #4
Source File: PTarArchiveInput.java    From jphp with Apache License 2.0 4 votes vote down vote up
@Signature
public void __construct(InputStream inputStream) {
    __construct(inputStream, TarConstants.DEFAULT_BLKSIZE);
}