{"record":{"id":"dcef6c5269e49985","repo":"MuntashirAkon/AppManager","slug":"could-not-backup-keystore-item","errorCode":null,"errorMessage":"Could not backup KeyStore item.","messagePattern":"Could not backup KeyStore item\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java","lineNumber":434,"sourceCode":"                        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();\n            } catch (FileNotFoundException ignore) {\n            }\n        }\n        try {\n            backedUpKeyStoreFiles = mBackupItem.encrypt(backedUpKeyStoreFiles);\n        } catch (IOException e) {\n            throw new BackupException(\"Failed to encrypt \" + Arrays.toString(backedUpKeyStoreFiles), e);\n        }\n        for (Path file : backedUpKeyStoreFiles) {\n            mChecksum.add(file.getName(), DigestUtils.getHexDigest(mMetadata.info.checksumAlgo, file));\n        }\n    }\n","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java#L416-L452","documentation":"After caching keystore files, backupKeyStore() creates a tar archive of them via TarUtils.create into the backup path. Any Throwable from archive creation is wrapped as this BackupException with the cause preserved.","triggerScenarios":"TarUtils.create(tarType, cachePath, backupPath, keyStorePrefix, filters, ...) throws — I/O error writing the tar, invalid tarType, or cache files vanished between caching and archiving.","commonSituations":"Cache files deleted prematurely; storage full on backup destination; unsupported tarType in metadata; encrypted-target directory not writable.","solutions":["Check chained cause for the tar/I/O failure","Confirm cache files still exist right before TarUtils.create","Verify mMetadata.info.tarType is a supported TAR_TYPES value","Check free space and write permission on the backup directory"],"exampleFix":"// before\nbackedUpKeyStoreFiles = TarUtils.create(...).toArray(new Path[0]);\n// after\ntry {\n    backedUpKeyStoreFiles = TarUtils.create(...).toArray(new Path[0]);\n} catch (Throwable th) {\n    throw new BackupException(\"Could not backup KeyStore item.\", th);\n} // caller: retry once after re-caching keystore files","handlingStrategy":"try-catch","validationCode":"if (!Arrays.stream(TarUtils.TAR_TYPES).anyMatch(t -> t.equals(mMetadata.info.tarType)))\n    throw new IllegalArgumentException(\"bad tarType\");\nif (cachePath.findFile(firstCached) == null) throw new IllegalStateException(\"cache files vanished\");","typeGuard":null,"tryCatchPattern":"try {\n    backedUpKeyStoreFiles = TarUtils.create(...).toArray(new Path[0]);\n} catch (Throwable th) {\n    Log.e(TAG, \"keystore tar failed\", th);\n    throw new BackupException(\"Could not backup KeyStore item.\", th);\n}","preventionTips":["Validate tarType from metadata before archiving","Do not clean cache between caching and archiving","Check destination free space"],"tags":["backup","keystore","tar","io"],"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"}