{"record":{"id":"0f9b65c7819fbec5","repo":"apache/cassandra","slug":"could-not-copy-file-s-to-s","errorCode":null,"errorMessage":"Could not copy file%s to %s","messagePattern":"Could not copy file(.+?) to (.+?)","errorType":"exception","errorClass":"FSWriteError","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/io/util/FileUtils.java","lineNumber":227,"sourceCode":"\n    public static void copyWithConfirm(String from, String to)\n    {\n        copyWithConfirm(new File(from), new File(to));\n    }\n\n    public static void copyWithConfirm(File from, File to)\n    {\n        assert from.exists();\n        if (logger.isTraceEnabled())\n            logger.trace(\"Copying {} to {}\", from.path(), to.path());\n\n        try\n        {\n            Files.copy(from.toPath(), to.toPath());\n        }\n        catch (IOException e)\n        {\n            throw new FSWriteError(e, \"Could not copy file\" + from + \" to \" + to);\n        }\n    }\n\n    public static void truncate(String path, long size)\n    {\n        File file = new File(path);\n        try (FileChannel channel = file.newReadWriteChannel())\n        {\n            channel.truncate(size);\n        }\n        catch (IOException e)\n        {\n            throw PathUtils.propagateUnchecked(e, file.toPath(), true);\n        }\n    }\n\n    public static void closeQuietly(Closeable c)\n    {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/FileUtils.java#L209-L245","documentation":"copyWithConfirm(String, String) throws FSWriteError wrapping an IOException from Files.copy, with message 'Could not copy fileX to Y'. It indicates the file copy failed at the OS level after source/destination decisions were made. FSWriteError is a fatal FS error in Cassandra, usually surfacing as JVM death of the affected node.","triggerScenarios":"Calling FileUtils.copyWithConfirm when Files.copy throws IOException — destination directory missing/unwritable, source unreadable, disk full, or cross-filesystem issues.","commonSituations":"Commitlog archive with a misconfigured or removed archive directory; permission changes on the archive dir; insufficient disk space during archival/copy operations.","solutions":["Verify both source and destination paths exist and are writable.","Free disk space or fix permissions on the destination directory.","Inspect the FSWriteError cause for the precise OS-level error."],"exampleFix":"// before\nFileUtils.copyWithConfirm(from, to);\n\n// after\nFile dest = new File(to);\nif (!dest.getParentFile().exists())\n    dest.getParentFile().mkdirs();\nFileUtils.copyWithConfirm(from, to);","handlingStrategy":"try-catch","validationCode":"if (!new File(to).getParentFile().exists()) new File(to).getParentFile().mkdirs(); if (new File(to).getParentFile().getFreeSpace() < new File(from).length()) throw new IllegalStateException(\"insufficient space\");","typeGuard":null,"tryCatchPattern":"try { FileUtils.copyWithConfirm(from, to); } catch (FSWriteError e) { /* check e.getCause(): permissions, ENOSPC, missing dir */ }","preventionTips":["Ensure destination directories exist and are writable before copying.","Monitor free disk space for archival targets.","Treat FSWriteError as fatal — verify paths/permissions before restart loops."],"tags":["io","file-copy","filesystem"],"backgroundTag":"file-write-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}