Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
5b5fb162
Commit
5b5fb162
authored
1 year ago
by
juanf
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-13521: Fixing build, adding more methods to the Unix replacement class
parent
98c8b143
No related branches found
No related tags found
1 merge request
!40
SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib-base/build.gradle
+1
-0
1 addition, 0 deletions
lib-base/build.gradle
lib-base/source/java/ch/systemsx/cisd/base/unix/Posix.java
+85
-3
85 additions, 3 deletions
lib-base/source/java/ch/systemsx/cisd/base/unix/Posix.java
with
86 additions
and
3 deletions
lib-base/build.gradle
+
1
−
0
View file @
5b5fb162
...
@@ -22,6 +22,7 @@ sourceSets {
...
@@ -22,6 +22,7 @@ sourceSets {
}
}
jar
{
jar
{
duplicatesStrategy
'include'
archiveName
"${project.group}-base-${version}.jar"
archiveName
"${project.group}-base-${version}.jar"
manifest
{
manifest
{
attributes
'Main-Class'
:
'ch.systemsx.cisd.base.BuildAndEnvironmentInfo'
attributes
'Main-Class'
:
'ch.systemsx.cisd.base.BuildAndEnvironmentInfo'
...
...
This diff is collapsed.
Click to expand it.
lib-base/source/java/ch/systemsx/cisd/base/unix/Posix.java
+
85
−
3
View file @
5b5fb162
/*
/*
* Copyright
ETH 2023 Zürich, Scientific IT Services
* Copyright
2007 - 2018 ETH Zuerich, CISD and SIS.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -13,26 +13,64 @@
...
@@ -13,26 +13,64 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
ch.systemsx.cisd.base.unix
;
package
ch.systemsx.cisd.base.unix
;
import
ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked
;
import
ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked
;
import
com.sun.security.auth.module.UnixSystem
;
import
com.sun.security.auth.module.UnixSystem
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.lang.management.ManagementFactory
;
import
java.nio.file.FileSystem
;
import
java.nio.file.FileSystems
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.attribute.GroupPrincipal
;
import
java.nio.file.attribute.PosixFilePermission
;
import
java.nio.file.attribute.PosixFilePermission
;
import
java.nio.file.attribute.UserPrincipal
;
import
java.nio.file.attribute.UserPrincipalLookupService
;
import
java.util.Set
;
import
java.util.Set
;
public
class
Posix
public
final
class
Posix
{
{
// Make constructor private to make clear is a utility class
private
Posix
()
{
}
public
static
boolean
isOperational
()
{
return
true
;
}
// Available on unix systems JDK 11 onwards
// Available on unix systems JDK 11 onwards
private
static
UnixSystem
unixSystem
=
new
com
.
sun
.
security
.
auth
.
module
.
UnixSystem
();
private
static
UnixSystem
unixSystem
=
new
UnixSystem
();
//
//
// User Functions
// User Functions
//
//
public
static
int
getEuid
()
{
try
{
String
processId
=
ManagementFactory
.
getRuntimeMXBean
().
getName
().
split
(
"@"
)[
0
];
String
command
=
"id -u "
+
processId
;
Process
process
=
Runtime
.
getRuntime
().
exec
(
command
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
output
=
reader
.
readLine
();
reader
.
close
();
if
(
output
!=
null
)
{
return
Integer
.
parseInt
(
output
);
}
else
{
throw
new
IOExceptionUnchecked
(
"Failed to retrieve user ID."
);
}
}
catch
(
IOException
|
NumberFormatException
ex
)
{
throw
new
IOExceptionUnchecked
(
ex
);
}
}
public
static
int
getUid
()
public
static
int
getUid
()
{
{
return
(
int
)
unixSystem
.
getUid
();
return
(
int
)
unixSystem
.
getUid
();
...
@@ -43,10 +81,54 @@ public class Posix
...
@@ -43,10 +81,54 @@ public class Posix
return
(
int
)
unixSystem
.
getGid
();
return
(
int
)
unixSystem
.
getGid
();
}
}
public
static
String
tryGetUserNameForUid
(
int
uid
)
throws
IOExceptionUnchecked
{
try
{
FileSystem
fileSystem
=
FileSystems
.
getDefault
();
UserPrincipalLookupService
service
=
fileSystem
.
getUserPrincipalLookupService
();
UserPrincipal
groupPrincipal
=
service
.
lookupPrincipalByName
(
Integer
.
toString
(
uid
));
return
groupPrincipal
.
getName
();
}
catch
(
IOException
ex
)
{
throw
new
IOExceptionUnchecked
(
ex
);
}
}
public
static
String
tryGetGroupNameForGid
(
int
gid
)
throws
IOExceptionUnchecked
{
try
{
FileSystem
fileSystem
=
FileSystems
.
getDefault
();
UserPrincipalLookupService
service
=
fileSystem
.
getUserPrincipalLookupService
();
GroupPrincipal
groupPrincipal
=
service
.
lookupPrincipalByGroupName
(
Integer
.
toString
(
gid
));
return
groupPrincipal
.
getName
();
}
catch
(
IOException
ex
)
{
throw
new
IOExceptionUnchecked
(
ex
);
}
}
//
//
// File functions
// File functions
//
//
public
static
void
setOwner
(
String
pathAsString
,
int
uid
,
int
gid
)
throws
IOExceptionUnchecked
{
try
{
FileSystem
fileSystem
=
FileSystems
.
getDefault
();
UserPrincipalLookupService
service
=
fileSystem
.
getUserPrincipalLookupService
();
Path
path
=
Path
.
of
(
pathAsString
);
UserPrincipal
user
=
service
.
lookupPrincipalByName
(
Integer
.
toString
(
uid
));
Files
.
setOwner
(
path
,
user
);
UserPrincipal
group
=
service
.
lookupPrincipalByGroupName
(
Integer
.
toString
(
gid
));
Files
.
setOwner
(
path
,
group
);
}
catch
(
IOException
ex
)
{
throw
new
IOExceptionUnchecked
(
ex
);
}
}
public
static
boolean
isSymbolicLink
(
String
path
)
{
return
Files
.
isSymbolicLink
(
Path
.
of
(
path
));
}
private
static
Set
<
PosixFilePermission
>
allPermissionsMode
=
Set
.
of
(
PosixFilePermission
.
OWNER_READ
,
private
static
Set
<
PosixFilePermission
>
allPermissionsMode
=
Set
.
of
(
PosixFilePermission
.
OWNER_READ
,
PosixFilePermission
.
OWNER_WRITE
,
PosixFilePermission
.
OWNER_WRITE
,
PosixFilePermission
.
OWNER_EXECUTE
,
PosixFilePermission
.
OWNER_EXECUTE
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment