use of com.jn.agileway.ssh.client.sftp.attrs.FileMode in project agileway by fangjinuo.
the class SynergySftps method fromSftpFileAttributes.
public static FileAttrs fromSftpFileAttributes(SftpFileAttributes attributes) {
if (attributes == null) {
return null;
}
FileAttrs attrs = new FileAttrs();
if (attributes.hasSize()) {
attrs.setSize(attributes.getSize().longValue());
}
if (attributes.hasAccessTime()) {
attrs.setAccessTime(attributes.getAccessedTime().bigIntValue().intValue());
}
if (attributes.hasModifiedTime()) {
attrs.setModifyTime(attributes.getModifiedTime().bigIntValue().intValue());
}
if (attributes.hasUID()) {
String uid = attributes.getUID();
if (Numbers.isNumber(uid)) {
attrs.setUid(Integer.parseInt(uid));
}
}
if (attributes.hasGID()) {
String gid = attributes.getGID();
if (Numbers.isNumber(gid)) {
attrs.setGid(Integer.parseInt(gid));
}
}
FileType fileType = FileType.UNKNOWN;
if (attributes.isFile()) {
fileType = FileType.REGULAR;
} else if (attributes.isDirectory()) {
fileType = FileType.DIRECTORY;
} else if (attributes.isBlock()) {
fileType = FileType.BLOCK_SPECIAL;
} else if (attributes.isCharacter()) {
fileType = FileType.CHAR_SPECIAL;
} else if (attributes.isFifo()) {
fileType = FileType.FIFO_SPECIAL;
} else if (attributes.isSocket()) {
fileType = FileType.SOCKET_SPECIAL;
} else if (attributes.isLink()) {
fileType = FileType.SYMBOLIC_LINK;
}
int permissions = attributes.getPermissions().intValue();
com.jn.agileway.ssh.client.sftp.attrs.FileMode fileMode = FileMode.createFileMode(fileType, permissions);
attrs.setFileMode(fileMode);
return attrs;
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileMode in project agileway by fangjinuo.
the class Ssh2Sftps method fromSsh2FileAttributes.
public static FileAttrs fromSsh2FileAttributes(SFTPv3FileAttributes attributes) {
if (attributes == null) {
return null;
}
FileAttrs attrs = new FileAttrs();
if (attributes.size != null) {
attrs.setSize(attributes.size);
}
if (attributes.atime != null) {
attrs.setAccessTime(attributes.atime.intValue());
}
if (attributes.mtime != null) {
attrs.setModifyTime(attributes.mtime.intValue());
}
if (attributes.uid != null) {
attrs.setUid(attributes.uid);
}
if (attributes.gid != null) {
attrs.setGid(attributes.gid);
}
if (attributes.permissions != null) {
FileMode fileMode = new FileMode(attributes.permissions);
attrs.setFileMode(fileMode);
}
return attrs;
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileMode in project agileway by fangjinuo.
the class FileModeTests method test0.
void test0(FileType fileType, int permissions) {
FileMode mode = FileMode.createFileMode(fileType, permissions);
Assert.assertEquals(fileType, mode.getType());
Assert.assertEquals(permissions, mode.getPermissionsMask());
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileMode 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;
}
Aggregations