{"record":{"id":"cbf8051bc834bf81","repo":"stanfordnlp/CoreNLP","slug":"cp-omitting-directory-source","errorCode":null,"errorMessage":"cp: omitting directory: <source>","messagePattern":"cp: omitting directory: <source>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":1876,"sourceCode":"  }\n\n\n  /**\n   * <p>An implementation of cp, as close to the Unix command as possible.\n   * Both directories and files are valid for either the source or the target;\n   * if the target exists, the semantics of Unix cp are [intended to be] obeyed.</p>\n   *\n   * @param source The source file or directory.\n   * @param target The target to write this file or directory to.\n   * @param recursive If true, recursively copy directory contents\n   * @throws IOException If either the copy fails (standard IO Exception), or the command is invalid\n   *                     (e.g., copying a directory without the recursive flag)\n   */\n  public static void cp(File source, File target, boolean recursive) throws IOException {\n    // Error checks\n    if (source.isDirectory() && !recursive) {\n      // cp a b -- a is a directory\n      throw new IOException(\"cp: omitting directory: \" + source);\n    }\n    if (!target.getParentFile().exists()) {\n      // cp a b/c/d/e -- b/c/d doesn't exist\n      throw new IOException(\"cp: cannot copy to directory: \" + recursive + \" (parent doesn't exist)\");\n    }\n    if (!target.getParentFile().isDirectory()) {\n      // cp a b/c/d/e -- b/c/d is a regular file\n      throw new IOException(\"cp: cannot copy to directory: \" + recursive + \" (parent isn't a directory)\");\n    }\n    // Get true target\n    File trueTarget;\n    if (target.exists() && target.isDirectory()) {\n      trueTarget = new File(target.getPath() + File.separator + source.getName());\n    } else {\n      trueTarget = target;\n    }\n    // Copy\n    if (source.isFile()) {","sourceCodeStart":1858,"sourceCodeEnd":1894,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L1858-L1894","documentation":"IOUtils.cp(File, File, boolean recursive) throws this IOException when the source is a directory but recursive=false, mirroring cp(1)'s \"cp: omitting directory\" behavior. Plain (non-recursive) copy only supports files; pass recursive=true to copy directories.","triggerScenarios":"Calling IOUtils.cp(source, target, false) — or an overload defaulting to non-recursive — where source.isDirectory() is true.","commonSituations":"Copying a folder of model/dependency files with the no-recursive flag; a variable that is normally a file sometimes points to a directory; migrating scripts from cp -r semantics without updating the flag.","solutions":["Pass recursive=true to IOUtils.cp when the source may be a directory.","Pre-check source.isDirectory() and branch: use cp(..., true) for directories, cp(..., false) for files.","If the directory should never be copied here, validate inputs earlier and produce a clearer error."],"exampleFix":"// before\nIOUtils.cp(new File(modelDir), new File(destDir), false);\n// after\nFile src = new File(modelDir);\nIOUtils.cp(src, new File(destDir), src.isDirectory());","handlingStrategy":"validation","validationCode":"File src = new File(sourcePath);\nif (src.isDirectory() && !recursive)\n  throw new IllegalArgumentException(\"Source is a directory; pass recursive=true: \" + src);","typeGuard":null,"tryCatchPattern":"try {\n  IOUtils.cp(src, target, recursive);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"cp: omitting directory\")) {\n    IOUtils.cp(src, target, true); // retry with recursion\n  } else throw e;\n}","preventionTips":["Choose the recursive flag from src.isDirectory(), not from a hard-coded literal.","Document whether your copy helper expects files or directories."],"tags":["io","filesystem","copy","java"],"backgroundTag":"invalid-argument-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}