I want to obtain linux file permissions without parsing ls -l. Since I will be using RootTools, I see it has a Permissions class, but how should I obtain permission data of a File into that object?
Asked
Active
Viewed 419 times
2 Answers
1
If you can't modify source use reflection:
private Permissions RootToolsInternalMethods_getPermissions(String line)
{
try
{
RootTools rootTools = new RootTools();
Method method = rootTools.getClass().getDeclaredMethod("getInternals");
method.setAccessible(true);
RootToolsInternalMethods rootToolsInternalMethods = (RootToolsInternalMethods)method.invoke(rootTools);
return rootToolsInternalMethods.getPermissions(line);
}
catch (Exception ignore) {}
return null;
}

Alex
- 11
- 2
-
This is also a good idea, but you need to be careful not to forget this when updating RootTools, if it changes. – Yaroslav Mytkalyk Nov 02 '16 at 10:15
0
RootToolsInternalMethods have getPermissions(String) method, but they can only be accessed in RootTools class
From RootTools source
private static final RootToolsInternalMethods getInternals() {
if (rim == null) {
RootToolsInternalMethods.getInstance();
return rim;
} else {
return rim;
}
}
Seems like I have to modify RootTools source and get the permissions from ls -l output
getInternals().getPermissions("ls -l output line");

Yaroslav Mytkalyk
- 16,950
- 10
- 72
- 99