iBotPeaches/Apktool · warning · BrutException

Could not create tmp dir:

Error message

Could not create tmp dir: 

What it means

Thrown by OS.createTempDirectory when the placeholder temp file was deleted but tmp.mkdir() immediately returns false. mkdir() fails without throwing when a directory already exists at that path, a file was recreated there in the microsecond between delete and mkdir (file-watcher/AV race), or the parent is not writable. The absolute path of the failed directory is included in the message.

Source

Thrown at brut.j.util/src/main/java/brut/util/OS.java:186

            if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
                Log.w(TAG, "Stream collector did not terminate.");
            }
            return collector.get();
        } catch (IOException | InterruptedException ignored) {
            return null;
        }
    }

    public static File createTempDirectory() throws BrutException {
        try {
            File tmp = File.createTempFile("BRUT", null);
            tmp.deleteOnExit();

            if (!tmp.delete()) {
                throw new BrutException("Could not delete tmp file: " + tmp.getAbsolutePath());
            }
            if (!tmp.mkdir()) {
                throw new BrutException("Could not create tmp dir: " + tmp.getAbsolutePath());
            }

            return tmp;
        } catch (IOException ex) {
            throw new BrutException("Could not create tmp dir", ex);
        }
    }

    private static class StreamForwarder extends Thread {
        private final InputStream mIn;
        private final String mType;

        public StreamForwarder(InputStream in, String type) {
            mIn = in;
            mType = type;
        }

        @Override

View on GitHub (pinned to 79b63384d7)

Solutions

  1. Retry with a fresh call — createTempFile generates a new random name each attempt, so transient races usually clear
  2. Disable/exclude temp-dir scanning in AV, or relocate tmpdir with -Djava.io.tmpdir to a local path
  3. Check the parent directory state: Files.isWritable(Paths.get(System.getProperty("java.io.tmpdir")))
  4. Use Files.createTempDirectory("BRUT") in your own code — it is atomic and immune to this delete/mkdir race

Example fix

// before
File dir = OS.createTempDirectory(); // mkdir loses race with AV

// after
File dir;
try {
    dir = OS.createTempDirectory();
} catch (BrutException e) { // transient race: one retry with a new random name
    dir = OS.createTempDirectory();
}
Defensive patterns

Strategy: retry

Try / catch

try {
    return OS.createTempDirectory();
} catch (BrutException e) {
    if (e.getMessage().startsWith("Could not create tmp dir")) {
        return OS.createTempDirectory(); // new random name, race usually gone
    }
    throw e;
}

Prevention

When it happens

Trigger: OS.createTempDirectory() where the createTempFile/delete/mkdir sequence loses a race against antivirus recreating the deleted file, another process creating the same directory (predictable 'BRUT' prefix collisions), or the temp directory permissions being revoked mid-run.

Common situations: Antivirus that quarantines and re-materializes the deleted temp file; parallel apktool instances or threads hammering the same temp dir; tmpdir on a full or quota-limited filesystem; containers with a read-only tmpfs after a security policy change.

Related errors


AI-assisted analysis of iBotPeaches/Apktool@79b63384d7 (2026-08-14). Data as JSON: /api/errors/7d4ba090a942a2e2. Report an issue: GitHub.