Package com.sshtools.common.sftp
Class PosixPermissions
java.lang.Object
com.sshtools.common.sftp.PosixPermissions
PosixPermissions and PosixPermissions.PosixPermissionsBuilder allow querying
and creation of an immutable set of posix file permissions. Natively, this is
a stored as a set of PosixFilePermission, but may be expressed and
parsed in a variety of different ways, such as octal strings, "file mode
strings", raw unsigned values. A mode may also be created by combining user,
group and other elements.
Note that these classes only deal with the basic user, group; and other file
access mode elements e.g. rw-r--r--. Other common Posix
indicators such as the 'd' for directory prefix, 's' for Set UID indicators,
'l' for links etc, are not parsed or generated here. Neither are the extended
SFTP bitmask flags.
This makes use of the existing core Java classes PosixFilePermission
and PosixFilePermissions, adding additional functionality and a
builder pattern for creation.
For example, to set the full set of permissions in one go :-
sftp.chmod(PosixPermissionsBuilder.create().
fromFileModeString("rw-rw-rw-").
build(), "/path/to/file");
Or to retrieve permission, remove write permissions and set them back :-
sftp.chmod(PosixPermissionsBuilder.create().
fromPosixPermissions(sftp.stat("/path/to/file").getPosixPermissions).
withoutWritePermissions().
build(), "/path/to/file");
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PosixPermissionsEmpty set of permissions (has a bitmask value ofzero) -
Method Summary
Modifier and TypeMethodDescriptionGet theStringrepresentation of these permissions.intasInt()Get the mode as a signed integer.longasLong()Get the mode as an unsigned long.Return the UNIX style mode mask.Get the set of individual permissions.com.sshtools.common.util.UnsignedInteger32asUInt32()Get the mode as an unsigned 32 bit integer.booleanbooleanhas(PosixFilePermission... permissions) Get if these permissions contain all of the provided permissions.inthashCode()booleanisEmpty()Get if this is an empty set of permissions.static inttoMask(PosixFilePermission permission) Get the bitmask flag value for a given permission.toString()
-
Field Details
-
EMPTY
Empty set of permissions (has a bitmask value ofzero)
-
-
Method Details
-
toMask
Get the bitmask flag value for a given permission.- Parameters:
permission- permission- Returns:
- bitmask flag value
-
asFileModesString
Get theStringrepresentation of these permissions. It is guaranteed that the returnedStringcan be parsed by thePosixPermissions.PosixPermissionsBuilder.fromFileModeString(String)method.- Returns:
- the string representation of the permission set
-
asInt
public int asInt()Get the mode as a signed integer. Note, you would never usually want to use this value without further manipulation to account for the sign bit. It is recommended you useasLong()orasUInt32()which guarantee the value will never be negative.- Returns:
- permissions as unsigned long
-
asLong
public long asLong()Get the mode as an unsigned long. Note, the value will never be greater than the 32 bits needs to store a mode natively.- Returns:
- permissions as unsigned long
-
asMaskString
Return the UNIX style mode mask. This will be in the same format as that which may be parsed byPosixPermissions.PosixPermissionsBuilder.fromMaskString(String).- Returns:
- mask string
-
asPermissions
Get the set of individual permissions.- Returns:
- permissions
-
asUInt32
public com.sshtools.common.util.UnsignedInteger32 asUInt32()Get the mode as an unsigned 32 bit integer.- Returns:
- permissions as unsigned 32 bit integer
-
has
Get if these permissions contain all of the provided permissions.- Parameters:
perms- permissions to test for- Returns:
- true if all permissions are contained
-
isEmpty
public boolean isEmpty()Get if this is an empty set of permissions.- Returns:
- empty
-
hashCode
public int hashCode() -
equals
-
toString
-