NationalSecurityAgency/ghidra · warning · IOException

Could not list files in temp directory: {tempDir.getAbsolute

Error message

Could not list files in temp directory: {tempDir.getAbsolutePath()}

What it means

Thrown by deleteTemporaryDirectory when tempDir.listFiles() returns null. File.listFiles() returns null when the path is not a directory or when an I/O error occurs during listing. Since deleteTemporaryDirectory already checked tempDir.exists(), the most likely cause is a permission issue preventing directory enumeration, or the path was removed by another process between the exists check and the listFiles call.

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java:1045

		if (dir.exists() == false) {
			if (dir.mkdir() == false) {
				throw new IOException("Unable to create temp directory: " + dir.getAbsolutePath());
			}
		}
		else if (dir.isDirectory() == false) {
			throw new IOException(dir.getAbsolutePath() + ": is not a directory");
		}
		dir = dir.getCanonicalFile();
		return dir;
	}

	private void deleteTemporaryDirectory(File tempDir) throws IOException {
		if (!tempDir.exists()) {
			return;
		}
		File[] listFiles = tempDir.listFiles();
		if (listFiles == null) {
			throw new IOException(
				"Could not list files in temp directory: " + tempDir.getAbsolutePath());
		}
		for (File listFile : listFiles) {
			if (!listFile.delete()) {
				throw new IOException(
					"Unable to delete temporary file: " + listFile.getAbsolutePath());
			}
		}
		if (!tempDir.delete()) {
			throw new IOException("Unable to delete temp directory: " + tempDir.getAbsolutePath());
		}
	}

	private class UpdateRepository extends IterateRepository {
		private File outdirectory;
		private String repo;
		private boolean overwrite;
		private DatabaseInformation info;

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Check directory permissions (read + execute on the directory) for the current user.
  2. Use try-catch around deleteTemporaryDirectory and log the path — in cleanup contexts, best-effort deletion is often acceptable.
  3. Ensure only one BSim process uses the same temp directory at a time.
  4. Run with appropriate user privileges matching the process that created the temp files.

Example fix

// before
File[] listFiles = tempDir.listFiles();
if (listFiles == null) {
    throw new IOException("Could not list files in temp directory: " + tempDir.getAbsolutePath());
}

// after — best-effort cleanup with fallback
File[] listFiles = tempDir.listFiles();
if (listFiles == null) {
    if (!tempDir.delete()) {
        Msg.warn(this, "Could not list or delete temp directory: " + tempDir.getAbsolutePath());
    }
    return;
}
Defensive patterns

Strategy: validation

Validate before calling

// Check directory readability before attempting to list files
if (tempDir == null || !tempDir.exists()) {
    return; // nothing to clean
}
if (!tempDir.isDirectory()) {
    throw new IllegalStateException("Not a directory: " + tempDir.getAbsolutePath());
}
if (!tempDir.canRead()) {
    // Cannot enumerate — skip cleanup with a warning
    return;
}

Type guard

public static boolean isListableDirectory(File dir) {
    return dir != null && dir.isDirectory() && dir.canRead();
}

Try / catch

// Cleanup is best-effort — wrap in try-catch and continue
try {
    deleteTemporaryDirectory(tempDir);
} catch (IOException e) {
    // Log and continue — leftover temp files are non-fatal
    Msg.warn(BulkSignatures.class, "Temp cleanup failed: " + e.getMessage());
}

Prevention

When it happens

Trigger: Calling deleteTemporaryDirectory on a path that exists but cannot be listed due to OS-level permission denial (no execute/read permission on the directory); a race condition where the directory is deleted by another process between the exists() and listFiles() calls; the path became a non-directory between checks.

Common situations: Running as a different user than the one that created the temp directory; SELinux or AppArmor blocking directory enumeration; a concurrent BSim run cleaning up the same temp directory; filesystem corruption on the temp volume.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/5d6789e7d30fc10f. Report an issue: GitHub.