{"record":{"id":"b1c7661194613bd1","repo":"beemdevelopment/Aegis","slug":"unable-to-create-directory-s-b1c766","errorCode":null,"errorMessage":"Unable to create directory %s","messagePattern":"Unable to create directory (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/com/beemdevelopment/aegis/vault/VaultManager.java","lineNumber":170,"sourceCode":"\n            if (_prefs.isAndroidBackupsEnabled()) {\n                backedUp = true;\n                scheduleAndroidBackup();\n            }\n        }\n\n        if (!backedUp) {\n            _prefs.setIsBackupReminderNeeded(true);\n        }\n    }\n\n    public void scheduleBackup() throws VaultRepositoryException {\n        _prefs.setIsBackupReminderNeeded(false);\n\n        try {\n            File dir = new File(_context.getCacheDir(), \"backup\");\n            if (!dir.exists() && !dir.mkdir()) {\n                throw new IOException(String.format(\"Unable to create directory %s\", dir));\n            }\n\n            File tempFile = File.createTempFile(VaultBackupManager.FILENAME_PREFIX, \".json\", dir);\n            try (OutputStream outStream = new FileOutputStream(tempFile)) {\n                _repo.export(outStream);\n            }\n            BackupsVersioningStrategy strategy = _prefs.getBackupVersioningStrategy();\n            Uri uri = _prefs.getBackupsLocation();\n            int versionsToKeep = _prefs.getBackupsVersionCount();\n\n            _backups.scheduleBackup(tempFile, strategy, uri, versionsToKeep);\n        } catch (IOException e) {\n            throw new VaultRepositoryException(e);\n        }\n    }\n\n    public void scheduleAndroidBackup() {\n        _prefs.setIsBackupReminderNeeded(false);","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/beemdevelopment/Aegis/blob/d6f4e5925a97e4e91593f1542085eae03432a759/app/src/main/java/com/beemdevelopment/aegis/vault/VaultManager.java#L152-L188","documentation":"scheduleBackup stages the vault into <cacheDir>/backup before handing it to VaultBackupManager. If the directory does not exist and File.mkdir() fails, it throws an IOException('Unable to create directory %s'). mkdir() fails only when the parent is missing or a filesystem error occurs (permissions, disk full, I/O error).","triggerScenarios":"cacheDir/backup cannot be created: app cache storage unreadable/wiped concurrently, disk full, read-only filesystem, or a non-directory file named 'backup' already occupies the path (mkdir returns false for existing non-dir).","commonSituations":"Device storage full; OEM cache cleaners racing the backup; broken cache state after restore; tests/emulators with restricted storage.","solutions":["Check free space and clear app cache (or Settings > Storage) so cache writes succeed, then retry the backup","Use mkdirs() and tolerate 'already exists' instead of bare mkdir() so a stale file/race doesn't abort: if (!dir.exists() && !dir.isDirectory() && !dir.mkdirs()) throw ...","Restart the app to reinitialize a healthy cache directory if the cache dir is in a bad state","Investigate SELinux/ROM restrictions if mkdir consistently fails on this device profile"],"exampleFix":"// before\nFile dir = new File(_context.getCacheDir(), \"backup\");\nif (!dir.exists() && !dir.mkdir()) {\n    throw new IOException(String.format(\"Unable to create directory %s\", dir));\n}\n// after\nFile dir = new File(_context.getCacheDir(), \"backup\");\nif (!dir.isDirectory() && !dir.mkdirs()) {\n    throw new IOException(String.format(\"Unable to create directory %s\", dir));\n}","handlingStrategy":"try-catch","validationCode":"File dir = new File(context.getCacheDir(), \"backup\");\nif (!dir.isDirectory() && !dir.mkdirs()) {\n    Log.e(TAG, \"cannot create \" + dir + \"; free space: \" + dir.getUsableSpace());\n}","typeGuard":"boolean canStageBackup(Context ctx) {\n    File dir = new File(ctx.getCacheDir(), \"backup\");\n    return (dir.isDirectory() || dir.mkdirs()) && dir.getUsableSpace() > MIN_BACKUP_BYTES;\n}","tryCatchPattern":"try {\n    vaultManager.scheduleBackup();\n} catch (VaultRepositoryException e) {\n    if (e.getCause() instanceof IOException && e.getMessage().contains(\"Unable to create directory\")) {\n        notifyStorageProblem();\n    }\n}","preventionTips":["Check usable space before backup scheduling","Use mkdirs() and treat pre-existing dirs as success","Don't race cache cleaners with backup jobs (use WorkManager constraints)"],"tags":["android","filesystem","backup","cache"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"d6f4e5925a97e4e91593f1542085eae03432a759","analyzedAt":"2026-09-08T00:46:31.111Z","contentChangedAt":"2026-09-08T00:46:31.111Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}