| | |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.protocols; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.nio.file.Files; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | |
| | | importConfig.setInvokeImportPlugins(false); |
| | | importConfig.setValidateSchema(true); |
| | | |
| | | String outputPath = inputPath + ".applied." + TimeThread.getGMTTime(); |
| | | if (new File(outputPath).exists()) |
| | | { |
| | | int i=2; |
| | | while (true) |
| | | { |
| | | if (! new File(outputPath + "." + i).exists()) |
| | | { |
| | | outputPath = outputPath + "." + i; |
| | | break; |
| | | } |
| | | |
| | | i++; |
| | | } |
| | | } |
| | | String outputPath = selectUnusedPath(inputPath + ".applied." + |
| | | TimeThread.getGMTTime()); |
| | | |
| | | LDIFExportConfig exportConfig = |
| | | new LDIFExportConfig(outputPath, ExistingFileBehavior.APPEND); |
| | |
| | | |
| | | if (errorEncountered || !fullyProcessed) |
| | | { |
| | | String renamedPath = inputPath + ".errors-encountered." + |
| | | TimeThread.getGMTTime(); |
| | | if (new File(renamedPath).exists()) |
| | | { |
| | | int i=2; |
| | | while (true) |
| | | { |
| | | if (! new File(renamedPath + "." + i).exists()) |
| | | { |
| | | renamedPath = renamedPath + "." + i; |
| | | } |
| | | |
| | | i++; |
| | | } |
| | | } |
| | | String renamedPath = selectUnusedPath(inputPath + ".errors-encountered." + |
| | | TimeThread.getGMTTime()); |
| | | |
| | | try |
| | | { |
| | |
| | | logger.trace("Renaming source file to " + renamedPath); |
| | | } |
| | | |
| | | ldifFile.renameTo(new File(renamedPath)); |
| | | renameFile(ldifFile, new File(renamedPath)); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | logger.trace("Deleting source file"); |
| | | } |
| | | |
| | | ldifFile.delete(); |
| | | Files.delete(ldifFile.toPath()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns the provided path if no file exists at it. Otherwise, appends |
| | | * ".2", ".3", ... to the provided path and returns the first resulting path |
| | | * at which no file exists. |
| | | * |
| | | * @param basePath The desired path for the file. |
| | | * |
| | | * @return The first path at which no file exists. |
| | | */ |
| | | static String selectUnusedPath(String basePath) |
| | | { |
| | | String path = basePath; |
| | | for (int i=2; new File(path).exists(); i++) |
| | | { |
| | | path = basePath + "." + i; |
| | | } |
| | | |
| | | return path; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void toString(StringBuilder buffer) |
| | | { |