{"record":{"id":"25134f9e7b3f9315","repo":"apache/hadoop","slug":"har-copyfromlocalfile-not-allowed","errorCode":null,"errorMessage":"Har: copyfromlocalfile not allowed","messagePattern":"Har: copyfromlocalfile not allowed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java","lineNumber":833,"sourceCode":"  public void setWorkingDirectory(Path newDir) {\n    //does nothing.\n  }\n  \n  /**\n   * not implemented.\n   */\n  @Override\n  public boolean mkdirs(Path f, FsPermission permission) throws IOException {\n    throw new IOException(\"Har: mkdirs not allowed\");\n  }\n  \n  /**\n   * not implemented.\n   */\n  @Override\n  public void copyFromLocalFile(boolean delSrc, boolean overwrite,\n      Path src, Path dst) throws IOException {\n    throw new IOException(\"Har: copyfromlocalfile not allowed\");\n  }\n\n  @Override\n  public void copyFromLocalFile(boolean delSrc, boolean overwrite,\n      Path[] srcs, Path dst) throws IOException {\n    throw new IOException(\"Har: copyfromlocalfile not allowed\");\n  }\n\n  /**\n   * copies the file in the har filesystem to a local file.\n   */\n  @Override\n  public void copyToLocalFile(boolean delSrc, Path src, Path dst) \n    throws IOException {\n    FileUtil.copy(this, src, getLocal(getConf()), dst, false, getConf());\n  }\n  \n  /**","sourceCodeStart":815,"sourceCodeEnd":851,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java#L815-L851","documentation":"The single-source copyFromLocalFile(boolean, boolean, Path, Path) override throws 'Har: copyfromlocalfile not allowed': uploading into a har would create new content, which the immutable archive forbids. Reads out of a har are supported (copyToLocalFile works), but writes in are not.","triggerScenarios":"fs.copyFromLocalFile(delSrc, overwrite, localSrc, harDst) with a har:// destination, directly or via FileUtil/FileSystem shell-style upload helpers.","commonSituations":"Ingestion scripts that push local files to a 'storage' URI later changed to har://; operators trying to add one file to an existing archive by uploading it in place.","solutions":["Upload to the underlying HDFS first (fs.copyFromLocalFile(..., hdfsDst)), then rebuild or create the archive with `hadoop archive`","Update the script configuration so upload targets never use the har scheme","For one-off additions: copy the archive's source tree, add the file, re-run `hadoop archive`"],"exampleFix":"// before\nfs.copyFromLocalFile(false, false, new Path(\"/tmp/f.dat\"), new Path(\"har://hdfs-nn:8020/a/data.har/f.dat\"));\n\n// after\nhdfs.copyFromLocalFile(false, false, new Path(\"/tmp/f.dat\"), new Path(\"/a/data/f.dat\"));\n// then: hadoop archive -archiveName data.har -p /a/data /a","handlingStrategy":"validation","validationCode":"if (\"har\".equals(dst.toUri().getScheme())) {\n  throw new UnsupportedOperationException(\"upload into har is not supported; upload to HDFS then run hadoop archive\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep upload target configs on hdfs:// and treat har:// as read-only publication","Add a scheme guard in shared upload utilities so all copyFromLocalFile variants are covered"],"tags":["hadoop","har-filesystem","read-only","copy-from-local","upload"],"backgroundTag":"read-only-filesystem-write","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}