Fix module prefs (#1813)

This commit is contained in:
南宫雪珊 2022-04-06 01:12:50 +08:00 committed by GitHub
parent be722b2e2e
commit be1bbf7b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 10 deletions

View File

@ -242,10 +242,10 @@ public class ConfigManager {
miscPath = string;
}
try {
Path p = Paths.get(miscPath);
Path prefs = Paths.get(miscPath + "/prefs");
var perms = PosixFilePermissions.fromString("rwx--x--x");
Files.createDirectories(p, PosixFilePermissions.asFileAttribute(perms));
walkFileTree(p, true, f -> SELinux.setFileContext(f.toString(), "u:object_r:magisk_file:s0"));
Files.createDirectories(prefs, PosixFilePermissions.asFileAttribute(perms));
walkFileTree(prefs, f -> SELinux.setFileContext(f.toString(), "u:object_r:magisk_file:s0"));
} catch (IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
}
@ -975,14 +975,11 @@ public class ConfigManager {
return module != null && module.appId == uid % PER_USER_RANGE;
}
private void walkFileTree(Path rootDir, boolean skipRoot, Consumer<Path> action) throws IOException {
private void walkFileTree(Path rootDir, Consumer<Path> action) throws IOException {
if (Files.notExists(rootDir)) return;
Files.walkFileTree(rootDir, new SimpleFileVisitor<>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
if (skipRoot && dir.equals(rootDir)) {
return FileVisitResult.CONTINUE;
}
action.accept(dir);
return FileVisitResult.CONTINUE;
}
@ -999,10 +996,11 @@ public class ConfigManager {
if (packageName == null) return;
var path = Paths.get(getPrefsPath(packageName, uid));
try {
Files.createDirectories(path);
walkFileTree(path, false, p -> {
var perms = PosixFilePermissions.fromString("rwx--x--x");
Files.createDirectories(path, PosixFilePermissions.asFileAttribute(perms));
walkFileTree(path, p -> {
try {
Os.chown(p.toString(), uid, 1000);
Os.chown(p.toString(), uid, uid);
} catch (ErrnoException e) {
Log.e(TAG, Log.getStackTraceString(e));
}