mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
15.52.2007 4c484ff6ea57ce79c5072a830e6536ac41c820c3
opendj-sdk/opends/src/server/org/opends/server/tools/WaitForFileDelete.java
@@ -124,6 +124,7 @@
    IntegerArgument timeout        = null;
    StringArgument  logFilePath    = null;
    StringArgument  targetFilePath = null;
    StringArgument  outputFilePath = null;
    String toolDescription = getMessage(MSGID_WAIT4DEL_TOOL_DESCRIPTION);
    ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
@@ -144,6 +145,13 @@
      argParser.addArgument(logFilePath);
      outputFilePath = new StringArgument("outputfile", 'o', "outputFile",
                                        false, false,
                                        true, "{path}", null, null,
                                        MSGID_WAIT4DEL_DESCRIPTION_OUTPUT_FILE);
      argParser.addArgument(outputFilePath);
      timeout = new IntegerArgument("timeout", 't', "timeout", true, false,
                                    true, "{seconds}", 60, null, true, 0, false,
                                    0, MSGID_WAIT4DEL_DESCRIPTION_TIMEOUT);
@@ -222,6 +230,35 @@
    }
    // If an output file was specified and we could open the log file, open it
    // and append data to it.
    RandomAccessFile outputFile = null;
    long outputFileOffset = 0L;
    if (logFile != null)
    {
      if (outputFilePath.isPresent())
      {
        try
        {
          File f = new File(outputFilePath.getValue());
          if (f.exists())
          {
            outputFile = new RandomAccessFile(f, "rw");
            outputFileOffset = outputFile.length();
            outputFile.seek(outputFileOffset);
          }
        }
        catch (Exception e)
        {
          int    msgID   = MSGID_WAIT4DEL_CANNOT_OPEN_OUTPUT_FILE;
          String message = getMessage(msgID, outputFilePath.getValue(),
                                    String.valueOf(e));
          System.err.println(wrapText(message, MAX_LINE_WIDTH));
          outputFile = null;
        }
      }
    }
    // Figure out when to stop waiting.
    long stopWaitingTime;
    try
@@ -257,8 +294,18 @@
            int bytesRead = logFile.read(logBuffer);
            if (bytesRead > 0)
            {
              System.out.write(logBuffer, 0, bytesRead);
              System.out.flush();
              if (outputFile == null)
              {
                System.out.write(logBuffer, 0, bytesRead);
                System.out.flush();
              }
              else
              {
                // Write on the file.
                // TODO
                outputFile.write(logBuffer, 0, bytesRead);
              }
              logFileOffset += bytesRead;
            }
          }
@@ -283,6 +330,14 @@
      }
    }
    if (outputFile != null)
    {
      try
      {
        outputFile.close();
      }
      catch (Throwable t) {}
    }
    if (targetFile.exists())
    {