Search in sources :

Example 1 with PosixFilePermissions

use of com.jn.langx.util.io.file.PosixFilePermissions in project agileway by fangjinuo.

the class SftpFileObject method doSetReadable.

@Override
protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws Exception {
    PosixFilePermissions posixFilePermissions = Sftps.getPosixPermission(getSftpSession().open(relPath, OpenMode.READ, null));
    int oldPerm = posixFilePermissions.getPermissions();
    if (readable) {
        posixFilePermissions.addPermission(FilePermission.USR_R);
    } else {
        posixFilePermissions.removePermission(FilePermission.USR_R);
    }
    if (!ownerOnly) {
        posixFilePermissions.addPermission(FilePermission.GRP_R);
        posixFilePermissions.addPermission(FilePermission.OTH_R);
    }
    if (posixFilePermissions.getPermissions() == oldPerm) {
        return true;
    }
    FileMode fileMode = FileMode.createFileMode(getFileAttrs().getFileMode().getType(), posixFilePermissions.getPermissions());
    getFileAttrs().setFileMode(fileMode);
    flushStat();
    return true;
}
Also used : FileMode(com.jn.agileway.ssh.client.sftp.attrs.FileMode) PosixFilePermissions(com.jn.langx.util.io.file.PosixFilePermissions)

Example 2 with PosixFilePermissions

use of com.jn.langx.util.io.file.PosixFilePermissions in project agileway by fangjinuo.

the class SftpFileObject method doSetWritable.

@Override
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws Exception {
    PosixFilePermissions posixFilePermissions = Sftps.getPosixPermission(getSftpSession().open(relPath, OpenMode.READ, null));
    int oldPerm = posixFilePermissions.getPermissions();
    if (writable) {
        posixFilePermissions.addPermission(FilePermission.USR_W);
    } else {
        posixFilePermissions.removePermission(FilePermission.USR_W);
    }
    if (!ownerOnly) {
        posixFilePermissions.addPermission(FilePermission.GRP_W);
        posixFilePermissions.addPermission(FilePermission.OTH_W);
    }
    if (posixFilePermissions.getPermissions() == oldPerm) {
        return true;
    }
    FileMode fileMode = FileMode.createFileMode(getFileAttrs().getFileMode().getType(), posixFilePermissions.getPermissions());
    getFileAttrs().setFileMode(fileMode);
    flushStat();
    return true;
}
Also used : FileMode(com.jn.agileway.ssh.client.sftp.attrs.FileMode) PosixFilePermissions(com.jn.langx.util.io.file.PosixFilePermissions)

Example 3 with PosixFilePermissions

use of com.jn.langx.util.io.file.PosixFilePermissions in project agileway by fangjinuo.

the class TarFileEntryFileAttrsCopier method accept.

@Override
public void accept(ArchiveEntry archiveEntry, File file) {
    TarArchiveEntry entry = (TarArchiveEntry) archiveEntry;
    PosixFilePermissions permissions = new PosixFilePermissions(entry.getMode(), true, true);
    file.setWritable(permissions.isWritable());
    file.setReadable(permissions.isReadable());
    file.setExecutable(permissions.isExecutable());
}
Also used : PosixFilePermissions(com.jn.langx.util.io.file.PosixFilePermissions) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 4 with PosixFilePermissions

use of com.jn.langx.util.io.file.PosixFilePermissions in project agileway by fangjinuo.

the class SftpFileObject method doSetExecutable.

@Override
protected boolean doSetExecutable(boolean executable, boolean ownerOnly) throws Exception {
    PosixFilePermissions posixFilePermissions = Sftps.getPosixPermission(getSftpSession().open(relPath, OpenMode.READ, null));
    int oldPerm = posixFilePermissions.getPermissions();
    if (executable) {
        posixFilePermissions.addPermission(FilePermission.USR_X);
    } else {
        posixFilePermissions.removePermission(FilePermission.USR_X);
    }
    if (!ownerOnly) {
        posixFilePermissions.addPermission(FilePermission.GRP_X);
        posixFilePermissions.addPermission(FilePermission.OTH_X);
    }
    if (posixFilePermissions.getPermissions() == oldPerm) {
        return true;
    }
    FileMode fileMode = FileMode.createFileMode(getFileAttrs().getFileMode().getType(), posixFilePermissions.getPermissions());
    getFileAttrs().setFileMode(fileMode);
    flushStat();
    return true;
}
Also used : FileMode(com.jn.agileway.ssh.client.sftp.attrs.FileMode) PosixFilePermissions(com.jn.langx.util.io.file.PosixFilePermissions)

Example 5 with PosixFilePermissions

use of com.jn.langx.util.io.file.PosixFilePermissions in project agileway by fangjinuo.

the class Sftps method getPosixPermission.

public static PosixFilePermissions getPosixPermission(SftpFile sftpFile) throws IOException {
    FileAttrs attrs = sftpFile.getAttributes();
    int[] groupIds = sftpFile.getSession().getSshConnection().getGroupIds();
    boolean inGroup = Collects.newArrayList(PrimitiveArrays.wrap(groupIds)).contains(attrs.getGid());
    int uid = sftpFile.getSession().getSshConnection().getUid();
    boolean isOwner = attrs.getUid() == uid;
    return new PosixFilePermissions(attrs.getFileMode().getPermissionsMask(), isOwner, inGroup);
}
Also used : FileAttrs(com.jn.agileway.ssh.client.sftp.attrs.FileAttrs) PosixFilePermissions(com.jn.langx.util.io.file.PosixFilePermissions)

Aggregations

PosixFilePermissions (com.jn.langx.util.io.file.PosixFilePermissions)5 FileMode (com.jn.agileway.ssh.client.sftp.attrs.FileMode)3 FileAttrs (com.jn.agileway.ssh.client.sftp.attrs.FileAttrs)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1