{"record":{"id":"3191a0e5b383d3fc","repo":"MuntashirAkon/AppManager","slug":"could-not-cache","errorCode":null,"errorMessage":"Could not cache ","messagePattern":"Could not cache ","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java","lineNumber":421,"sourceCode":"            Path masterKeyFile = KeyStoreUtils.getMasterKey(mUserId);\n            // Master key exists, so take its checksum to verify it during the restore\n            mChecksum.add(MASTER_KEY, DigestUtils.getHexDigest(mMetadata.info.checksumAlgo,\n                    masterKeyFile.getContentAsString().getBytes()));\n        } catch (FileNotFoundException ignore) {\n        }\n        // Store the KeyStore files\n        Path cachePath = Paths.get(FileUtils.getCachePath());\n        List<String> cachedKeyStoreFileNames = new ArrayList<>();\n        List<String> keyStoreFilters = new ArrayList<>();\n        for (String keyStoreFileName : KeyStoreUtils.getKeyStoreFiles(mApplicationInfo.uid, mUserId)) {\n            try {\n                String newFileName = Utils.replaceOnce(keyStoreFileName, String.valueOf(mApplicationInfo.uid),\n                        String.valueOf(KEYSTORE_PLACEHOLDER));\n                IoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(newFileName, null));\n                cachedKeyStoreFileNames.add(newFileName);\n                keyStoreFilters.add(Pattern.quote(newFileName));\n            } catch (Throwable e) {\n                throw new BackupException(\"Could not cache \" + keyStoreFileName, e);\n            }\n        }\n        if (cachedKeyStoreFileNames.isEmpty()) {\n            throw new BackupException(\"There were some KeyStore items but they couldn't be cached before taking a backup.\");\n        }\n        String keyStorePrefix = KEYSTORE_PREFIX + getExt(mMetadata.info.tarType);\n        Path[] backedUpKeyStoreFiles;\n        try {\n            backedUpKeyStoreFiles = TarUtils.create(mMetadata.info.tarType, cachePath, mBackupItem.getUnencryptedBackupPath(), keyStorePrefix,\n                            keyStoreFilters.toArray(new String[0]), null, null, false)\n                    .toArray(new Path[0]);\n        } catch (Throwable th) {\n            throw new BackupException(\"Could not backup KeyStore item.\", th);\n        }\n        // Remove cache\n        for (String name : cachedKeyStoreFileNames) {\n            try {\n                cachePath.findFile(name).delete();","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java#L403-L439","documentation":"Before backing up KeyStore files, backupKeyStore() copies each keystore file into a cache directory under a placeholder-based name. If copying a particular file fails, this BackupException naming the file is thrown with the cause attached.","triggerScenarios":"IoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(...)) throws for a specific keystore file — source missing or cache file cannot be created/written.","commonSituations":"Keystore path listing changed between listing and copy; cache partition full; filename no longer contains the uid so replaceOnce produced an unexpected name; permission issues in /data/misc/keystore.","solutions":["Check the cause to see if it is a read error (source) or write error (cache)","Confirm the keystore source file still exists before copying","Free space in the cache directory","Ensure the keystore filename contains the expected uid for KEYSTORE_PLACEHOLDER replacement"],"exampleFix":"// before\nIoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(newFileName, null));\n// after\nVirtualFile src = keyStorePath.findFile(keyStoreFileName);\nif (src == null) { Log.w(TAG, \"Skipping missing keystore file \" + keyStoreFileName); continue; }\nIoUtils.copy(src, cachePath.findOrCreateFile(newFileName, null));","handlingStrategy":"try-catch","validationCode":"if (keyStorePath.findFile(keyStoreFileName) == null) {\n    Log.w(TAG, \"keystore file missing: \" + keyStoreFileName);\n    return; // skip\n}\nif (cachePath.getFreeSpace() < keyStorePath.findFile(keyStoreFileName).getSize()) { /* free space */ }","typeGuard":"static boolean canCache(VirtualFile src, VirtualPath cacheDir) {\n    return src != null && src.exists() && cacheDir != null && cacheDir.canWrite();\n}","tryCatchPattern":"try {\n    IoUtils.copy(src, dst);\n} catch (Throwable e) {\n    throw new BackupException(\"Could not cache \" + name, e);\n}","preventionTips":["Skip-and-log missing keystore files instead of hard fail","Monitor cache partition free space","Keep uid-in-filename assumptions documented"],"tags":["backup","keystore","io","cache"],"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-14T16:17:12.679Z"}