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

Nicolas Capponi
11.04.2016 0c41b32e5c891f829aa6636bcf375c3e424e4c77
opendj-server-legacy/src/main/java/org/opends/server/util/StaticUtils.java
@@ -95,6 +95,8 @@
  /** Size of buffer used to copy/move/extract files. */
  public static final int BUFFER_SIZE = 8192;
  private static final String[] EXECUTABLE_FILES_SUFFIXES = { ".sh", ".bat", ".exe" };
  /**
   * Number of bytes in a Kibibyte.
   * <p>
@@ -2487,16 +2489,28 @@
  /**
   * Extracts the provided zip archive to the provided target directory.
   * <p>
   * Archive files ending by "sh" or beginning by "bin" are set as executable files.
   * A file is set to executable if one or more of the following three conditions apply:
   * <ul>
   *   <li>It ends with a suffix identified as executable file suffix (.sh, .bat, .exe)</li>
   *   <li>It is listed in the provided executableFiles</li>
   *   <li>It is included in a directory that is listed in the provided executableDirectories</li>
   * </ul>
   *
   * @param zipFile
   *            The zip file to extract.
   * @param targetDirectory
   *            The target directory for the content of the archive.
   * @param executableDirectories
   *            List of extracted directories which should have all their files set as executable.
   *            Each directory must be provided as a path relative to the target directory (e.g. "opendj/bin")
   * @param executableFiles
   *            List of individual files which should be set as executable.
   *            Each file must be provided as a path relative to the target directory (e.g. "opendj/setup")
   * @throws IOException
   *            If zip archive can't be read or target files can be written.
   */
  public static void extractZipArchive(File zipFile, File targetDirectory) throws IOException
  public static void extractZipArchive(File zipFile, File targetDirectory, List<String> executableDirectories,
      List<String> executableFiles) throws IOException
  {
    try (ZipInputStream zipStream = new ZipInputStream(new FileInputStream(zipFile)))
    {
@@ -2512,12 +2526,33 @@
        }
        extractFileFromZip(zipStream, targetFile);
        if (fileEntry.getName().endsWith("sh") || fileEntry.getName().startsWith("bin"))
        for (String suffix : EXECUTABLE_FILES_SUFFIXES)
        {
          targetFile.setExecutable(true);
          if (fileEntry.getName().toLowerCase().endsWith(suffix))
          {
            targetFile.setExecutable(true);
          }
        }
      }
    }
    for (String dir: executableDirectories)
    {
      File directory = new File(targetDirectory.getPath(), dir);
      for (File file: directory.listFiles())
      {
        if (file.isFile()) {
          file.setExecutable(true);
        }
      }
    }
    for (String name : executableFiles)
    {
      File file = new File(targetDirectory.getPath(), name);
      if (file.exists())
      {
        file.setExecutable(true);
      }
    }
  }
  /**