{"record":{"id":"c9ff28e342103fec","repo":"iBotPeaches/Apktool","slug":"error-copying-file","errorCode":null,"errorMessage":"Error copying file: ","messagePattern":"Error copying file: ","errorType":"exception","errorClass":"DirectoryException","httpStatus":null,"severity":"error","filePath":"brut.j.dir/src/main/java/brut/directory/Directory.java","lineNumber":254,"sourceCode":"    public void copyToDir(Directory out, String fileName) throws DirectoryException {\n        copyToDir(fileName, out, fileName);\n    }\n\n    public void copyToDir(Directory out, String... fileNames) throws DirectoryException {\n        for (String fileName : fileNames) {\n            copyToDir(out, fileName);\n        }\n    }\n\n    public void copyToDir(String inFileName, Directory out, String outFileName) throws DirectoryException {\n        try {\n            if (containsDir(inFileName)) {\n                getDir(inFileName).copyToDir(out.createDir(outFileName));\n            } else {\n                BrutIO.copyAndClose(getFileInput(inFileName), out.getFileOutput(outFileName));\n            }\n        } catch (IOException ex) {\n            throw new DirectoryException(\"Error copying file: \" + inFileName, ex);\n        }\n    }\n\n    public void copyToDir(File out) throws DirectoryException {\n        for (String fileName : getFiles(true)) {\n            copyToDir(out, fileName);\n        }\n    }\n\n    public void copyToDir(File out, String fileName) throws DirectoryException {\n        copyToDir(fileName, out, fileName);\n    }\n\n    public void copyToDir(File out, String... fileNames) throws DirectoryException {\n        for (String fileName : fileNames) {\n            copyToDir(out, fileName);\n        }\n    }","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.j.dir/src/main/java/brut/directory/Directory.java#L236-L272","documentation":"Directory.copyToDir(inFileName, out, outFileName) copies one entry between Directory implementations (e.g. ZIP to filesystem) via streams; an IOException during the stream copy is wrapped in this DirectoryException naming the entry. It fires when the copy itself fails, not when the source is missing (missing sources take the containsDir/getFileInput paths).","triggerScenarios":"Copying a decoded resource/file entry into an output Directory whose target cannot be written (unwritable path, closed ZIP being written incorrectly, disk full) or whose source stream breaks mid-copy.","commonSituations":"Repackaging APKs in pipelines where the output zip stream was closed early, target dirs deleted mid-run, or filesystem quota exceeded during apktool b.","solutions":["Check the named entry's target path: parent directory exists, writable, enough free space","Verify the source archive is intact (`unzip -t`) so its stream does not break mid-read","Do not close or reuse the output Directory/stream while a bulk copyToDir loop is running","Retry after fixing the environment; a persistent failure on one entry usually means a corrupt source entry"],"exampleFix":"// before\nzipDir.copyToDir(inName, outDir, outName); // outDir parent missing -> Error copying file\n\n// after\nFile parent = outDir.getDir().toFile();\nif (!parent.exists() && !parent.mkdirs()) {\n    throw new IOException(\"Cannot create output dir: \" + parent);\n}\nzipDir.copyToDir(inName, outDir, outName);","handlingStrategy":"try-catch","validationCode":"// Ensure target side is writable and source entry exists before copying\nif (!out.containsDir(parentOf(outFileName)) && !canCreate) { /* pre-create */ }\n// simplest: verify output Directory is open and its backing location writable\nif (!new java.io.File(outLocation).canWrite()) throw new IOException(\"Output not writable\");","typeGuard":null,"tryCatchPattern":"try {\n    dir.copyToDir(inName, outDir, outName);\n} catch (DirectoryException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error copying file\")) {\n        // e.getMessage() names the entry; log it and continue with remaining entries or abort transactionally\n    } else { throw e; }\n}","preventionTips":["Keep output directories opened and writable for the whole copy loop","Never close the destination stream/zip mid-copyToDir","Check disk space before bulk extraction"],"tags":["apktool","io","copy","directory"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}