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