{"record":{"id":"673ddcc21bec8e1b","repo":"pentaho/pentaho-kettle","slug":"destination-directory-already-contains-a-diectory-with","errorCode":null,"errorMessage":"Destination directory already contains a diectory with requested name","messagePattern":"Destination directory already contains a diectory with requested name","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDirectoryDelegate.java","lineNumber":228,"sourceCode":"   */\n  public synchronized void renameDirectory( ObjectId id_directory, ObjectId id_directory_parent, String newName ) throws KettleException {\n    if ( id_directory.equals( id_directory_parent ) ) {\n      // Make sure the directory cannot become its own parent\n      throw new KettleException( \"Failed to copy directory into itself\" );\n    } else {\n      // Make sure the directory does not become a descendant of itself\n      RepositoryDirectory rd = new RepositoryDirectory();\n      loadRepositoryDirectory( rd, id_directory );\n      if ( rd.findDirectory( id_directory_parent ) != null ) {\n        // The parent directory is a child of this directory. Do not proceed\n        throw new KettleException( \"Directory cannot become a child to itself\" );\n      } else {\n        // Check for duplication\n        RepositoryDirectory newParent = new RepositoryDirectory();\n        loadRepositoryDirectory( newParent, id_directory_parent );\n        RepositoryDirectory child = newParent.findChild( newName == null ? rd.getName() : newName );\n        if ( child != null ) {\n          throw new KettleException( \"Destination directory already contains a diectory with requested name\" );\n        }\n      }\n    }\n\n    if ( id_directory_parent != null || newName != null ) {\n      RowMetaAndData r = new RowMetaAndData();\n\n      String sql = \"UPDATE \" + quoteTable( KettleDatabaseRepository.TABLE_R_DIRECTORY ) + \" SET \";\n      boolean additionalParameter = false;\n\n      if ( newName != null ) {\n        additionalParameter = true;\n        sql += quote( KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME ) + \" = ?\";\n        r.addValue( new ValueMetaString(\n          KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME ), newName );\n      }\n      if ( id_directory_parent != null ) {\n        // Add a parameter separator if the first parm was added","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryDirectoryDelegate.java#L210-L246","documentation":"Thrown by renameDirectory when the destination parent already contains a child directory whose name matches the requested new name (or the current name when newName is null). The delegate loads the new parent and calls findChild(name) to enforce unique directory names within a parent. Thrown before any database write, so nothing is modified. (Note the message contains a typo: 'diectory'.)","triggerScenarios":"repository.renameRepositoryDirectory(id, newParent, newName) where newParent already has a child named newName; or a pure rename where a sibling of the same name exists (newName null, rd.getName() already present in parent).","commonSituations":"Re-running a migration/import script that already created the target folder on a previous run; two users renaming/creating the same folder concurrently; case-sensitivity assumptions when the DB compare is case-sensitive.","solutions":["Check the destination for an existing child with the target name and rename/skip first: newParent.findChild(name)","Pick a unique newName (append a timestamp or counter) when a sibling conflict exists","Guard scripts with idempotency checks before creating/renaming directories","Handle the exception and surface a user-friendly 'name already in use' message"],"exampleFix":"// before\nrepo.renameRepositoryDirectory( dirId, newParent, \"Archive\" ); // fails if Archive exists\n// after\nif ( newParent.findChild( \"Archive\" ) == null ) {\n  repo.renameRepositoryDirectory( dirId, newParent, \"Archive\" );\n} else {\n  repo.renameRepositoryDirectory( dirId, newParent, \"Archive-\" + System.currentTimeMillis() );\n}","handlingStrategy":"validation","validationCode":"RepositoryDirectoryInterface dest = repo.findDirectory( \"/destination\" );\nString target = newName != null ? newName : existingDir.getName();\nif ( dest.findChild( target ) != null ) {\n  // choose a unique name or abort before calling the API\n}","typeGuard":null,"tryCatchPattern":"try {\n  repo.renameRepositoryDirectory( id, newParent, newName );\n} catch ( KettleException e ) {\n  if ( e.getMessage() != null && e.getMessage().contains( \"already contains\" ) ) {\n    // surface 'name already in use' and prompt for a different name\n  }\n}","preventionTips":["Check findChild(targetName) on the destination before renaming","Make bulk scripts idempotent: skip or rename on conflict","Anticipate concurrent users creating the same folder name","Use unique suffixes (timestamp/counter) for generated names"],"tags":["validation","name-conflict","directory-rename"],"backgroundTag":"file-already-exists","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}