MuntashirAkon/AppManager · error · BackupException
Could not cache
Error message
Could not cache
What it means
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.
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java:421
Path masterKeyFile = KeyStoreUtils.getMasterKey(mUserId);
// Master key exists, so take its checksum to verify it during the restore
mChecksum.add(MASTER_KEY, DigestUtils.getHexDigest(mMetadata.info.checksumAlgo,
masterKeyFile.getContentAsString().getBytes()));
} catch (FileNotFoundException ignore) {
}
// Store the KeyStore files
Path cachePath = Paths.get(FileUtils.getCachePath());
List<String> cachedKeyStoreFileNames = new ArrayList<>();
List<String> keyStoreFilters = new ArrayList<>();
for (String keyStoreFileName : KeyStoreUtils.getKeyStoreFiles(mApplicationInfo.uid, mUserId)) {
try {
String newFileName = Utils.replaceOnce(keyStoreFileName, String.valueOf(mApplicationInfo.uid),
String.valueOf(KEYSTORE_PLACEHOLDER));
IoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(newFileName, null));
cachedKeyStoreFileNames.add(newFileName);
keyStoreFilters.add(Pattern.quote(newFileName));
} catch (Throwable e) {
throw new BackupException("Could not cache " + keyStoreFileName, e);
}
}
if (cachedKeyStoreFileNames.isEmpty()) {
throw new BackupException("There were some KeyStore items but they couldn't be cached before taking a backup.");
}
String keyStorePrefix = KEYSTORE_PREFIX + getExt(mMetadata.info.tarType);
Path[] backedUpKeyStoreFiles;
try {
backedUpKeyStoreFiles = TarUtils.create(mMetadata.info.tarType, cachePath, mBackupItem.getUnencryptedBackupPath(), keyStorePrefix,
keyStoreFilters.toArray(new String[0]), null, null, false)
.toArray(new Path[0]);
} catch (Throwable th) {
throw new BackupException("Could not backup KeyStore item.", th);
}
// Remove cache
for (String name : cachedKeyStoreFileNames) {
try {
cachePath.findFile(name).delete();View on GitHub (pinned to 0152f468fc)
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
Example fix
// before
IoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(newFileName, null));
// after
VirtualFile src = keyStorePath.findFile(keyStoreFileName);
if (src == null) { Log.w(TAG, "Skipping missing keystore file " + keyStoreFileName); continue; }
IoUtils.copy(src, cachePath.findOrCreateFile(newFileName, null)); Defensive patterns
Strategy: try-catch
Validate before calling
if (keyStorePath.findFile(keyStoreFileName) == null) {
Log.w(TAG, "keystore file missing: " + keyStoreFileName);
return; // skip
}
if (cachePath.getFreeSpace() < keyStorePath.findFile(keyStoreFileName).getSize()) { /* free space */ } Type guard
static boolean canCache(VirtualFile src, VirtualPath cacheDir) {
return src != null && src.exists() && cacheDir != null && cacheDir.canWrite();
} Try / catch
try {
IoUtils.copy(src, dst);
} catch (Throwable e) {
throw new BackupException("Could not cache " + name, e);
} Prevention
- Skip-and-log missing keystore files instead of hard fail
- Monitor cache partition free space
- Keep uid-in-filename assumptions documented
When it happens
Trigger: IoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(...)) throws for a specific keystore file — source missing or cache file cannot be created/written.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Could not backup KeyStore item.
- Could not cache APK file
- Could not cache the APK file
- Could not get backup files.
- Could not retrieve metadata from backup.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/3191a0e5b383d3fc.
Report an issue: GitHub.