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;
}
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;
}
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());
}
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;
}
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);
}
Aggregations