Gracefully handle ENOTSUP in ConfigFileManager.chattr0 (#523)
The `chattr0` method, which attempts to clear special file attributes (like 'i' for immutable) using `ioctl`, can fail with an `ErrnoException` and the error code `ENOTSUP` (Operation not supported) on certain filesystems or Android environments (e.g., noted on a Android 11 device). When `ioctl` fails with `ENOTSUP`, it means the underlying filesystem does not support the operation of setting/clearing these attributes. In this case, we can safely assume the file/directory is not immutable via this mechanism and treat the operation as a successful non-action. This commit updates `chattr0` to catch `ErrnoException` specifically and return `true` if the error is `OsConstants.ENOTSUP`, preventing unexpected failures in config file management.
This commit is contained in:
parent
047ad98c65
commit
3540f14481
|
|
@ -193,9 +193,18 @@ public class ConfigFileManager {
|
||||||
public static boolean chattr0(Path path) {
|
public static boolean chattr0(Path path) {
|
||||||
try {
|
try {
|
||||||
var dir = Os.open(path.toString(), OsConstants.O_RDONLY, 0);
|
var dir = Os.open(path.toString(), OsConstants.O_RDONLY, 0);
|
||||||
|
// Clear all special file attributes on the directory
|
||||||
HiddenApiBridge.Os_ioctlInt(dir, Process.is64Bit() ? 0x40086602 : 0x40046602, 0);
|
HiddenApiBridge.Os_ioctlInt(dir, Process.is64Bit() ? 0x40086602 : 0x40046602, 0);
|
||||||
Os.close(dir);
|
Os.close(dir);
|
||||||
return true;
|
return true;
|
||||||
|
} catch (ErrnoException e) {
|
||||||
|
// If the operation is not supported (ENOTSUP), it means the filesystem doesn't support attributes.
|
||||||
|
// We can assume the file is not immutable and proceed.
|
||||||
|
if (e.errno == OsConstants.ENOTSUP) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Log.d(TAG, "chattr 0", e);
|
||||||
|
return false;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.d(TAG, "chattr 0", e);
|
Log.d(TAG, "chattr 0", e);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue