{"record":{"id":"816b1d1d72bb1294","repo":"MuntashirAkon/AppManager","slug":"could-not-delete-the-selected-backups","errorCode":null,"errorMessage":"Could not delete the selected backups","messagePattern":"Could not delete the selected backups","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupManager.java","lineNumber":159,"sourceCode":"        } else {\n            backupItemList = new ArrayList<>(options.relativeDirs.length);\n            for (String relativeDir : options.relativeDirs) {\n                try {\n                    backupItemList.add(BackupItems.findBackupItem(relativeDir));\n                } catch (IOException e) {\n                    throw new BackupException(\"Could not get backup files.\", e);\n                }\n            }\n        }\n        for (BackupItems.BackupItem backupItem : backupItemList) {\n            BackupMetadataV5 metadata;\n            try {\n                metadata = backupItem.getMetadata();\n            } catch (IOException e) {\n                throw new BackupException(\"Could not retrieve metadata from backup.\", e);\n            }\n            if (!backupItem.isFrozen() && !backupItem.delete()) {\n                throw new BackupException(\"Could not delete the selected backups\");\n            }\n            BackupUtils.deleteBackupToDbAndBroadcast(ContextUtils.getContext(), metadata);\n        }\n    }\n\n    public void verify(@NonNull String relativeDir) throws BackupException {\n        BackupItems.BackupItem backupItem;\n        try {\n            backupItem = BackupItems.findBackupItem(relativeDir);\n        } catch (IOException e) {\n            throw new BackupException(\"Could not get backup files.\", e);\n        }\n        try (VerifyOp restoreOp = new VerifyOp(backupItem)) {\n            restoreOp.verify();\n        }\n    }\n\n    private static int calculateMaxProgress(@NonNull BackupFlags backupFlags) {","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupManager.java#L141-L177","documentation":"In deleteBackup(), once metadata is read, non-frozen backup items are deleted via backupItem.delete(); if that returns false the method throws BackupException('Could not delete the selected backups'). It means the filesystem refused the delete (returns false, not an exception), typically due to permissions or a frozen/read-only backup.","triggerScenarios":"deleteBackup() on an unfrozen BackupItem whose delete() returns false — e.g. files on read-only storage, root-owned files, or filesystem-level denial.","commonSituations":"Backups on a read-only mounted volume; SAF/storage-permission revocation after OS update; backup files owned by root after a root-shell operation; files locked by another process.","solutions":["Check mount state and re-mount storage read-write, then retry the delete.","Grant the app storage/All-files-access permission and retry.","If files are root-owned, delete them with a root shell or fix ownership first.","If the backup is intentionally frozen, unfreeze it or remove the frozen entry via the appropriate path (frozen items are skipped by this code)."],"exampleFix":"// before\nif (!backupItem.isFrozen() && !backupItem.delete()) {\n    throw new BackupException(\"Could not delete the selected backups\");\n}\n// after\nif (!backupItem.isFrozen()) {\n    if (!backupItem.delete()) {\n        Log.w(TAG, \"delete failed, is dir read-only? \" + backupItem.getDir());\n        // fallback: recursive delete via File API / root shell\n    }\n}","handlingStrategy":"try-catch","validationCode":"File d = new File(backupRoot, relDir);\nif (!d.canWrite()) {\n    throw new IllegalStateException(\"Backup dir not writable: \" + d);\n}","typeGuard":"boolean backupDeletable(String relDir) {\n    File d = new File(backupRoot, relDir);\n    return d.isDirectory() && d.canWrite();\n}","tryCatchPattern":"try {\n    manager.deleteBackup(options);\n} catch (BackupException e) {\n    if (e.getMessage().contains(\"Could not delete\")) {\n        // check storage permissions / read-only mount, then retry\n    }\n}","preventionTips":["Grant All-files-access/storage permission before delete ops","Ensure storage is mounted read-write","Avoid root-owned backups if deleting without root","Unfreeze frozen backups through the proper flow"],"tags":["android","backup","delete","permissions","filesystem"],"backgroundTag":"file-write-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}