Exemple #1
0
  /**
   * Updates a given folder with the content of the update file
   *
   * @param forPath
   * @param exclusions list of files we don't want to remove from the given folder
   * @return
   * @throws IOException
   */
  private void applyUpdateFor(String forPath, String[] exclusions) throws UpdateException {

    Boolean success;
    try {
      // First lets remove the "old" code in order to unzip the update on that folder
      File updatedFolder = new File(distributionHome + File.separator + forPath);
      if (exclusions != null) {
        success = UpdateUtil.deleteDirectory(updatedFolder, exclusions);
      } else {
        success = UpdateUtil.deleteDirectory(updatedFolder);
      }
      if (success) {
        logger.debug("Removed outdated folder: " + updatedFolder.getAbsolutePath());
      } else {
        if (exclusions == null) {
          logger.error("Error removing outdated folder: " + updatedFolder.getAbsolutePath());
        } else {
          // If we have exclusions is normal to have a false success because the folder could not be
          // removed as it have excluded files on it
          logger.debug("Removed outdated files in folder: " + updatedFolder.getAbsolutePath());
        }
      }

      // Now we need to unzip the content of the update file into the given folder, we just removed
      // it, so lets create it again....
      if (!updatedFolder.exists()) {
        success = updatedFolder.mkdirs();
        if (success) {
          logger.debug("Created folder: " + updatedFolder.getAbsolutePath());
        } else {
          logger.error("Error creating folder: " + updatedFolder.getAbsolutePath());
        }
      }
      success = UpdateUtil.unzipDirectory(updateFile, distributionHome, forPath, dryrun);
    } catch (IOException e) {
      String error = "Error unzipping update file on: " + forPath;
      if (!UpdateAgent.isDebug) {
        error += Messages.getString("UpdateAgent.text.use.verbose", UpdateAgent.logFile);
      }
      throw new UpdateException(error, UpdateException.ERROR);
    }

    if (!success) {
      String error = "Error unzipping update file on: " + forPath;
      if (!UpdateAgent.isDebug) {
        error += Messages.getString("UpdateAgent.text.use.verbose", UpdateAgent.logFile);
      }
      throw new UpdateException(error, UpdateException.ERROR);
    }
  }
Exemple #2
0
  /**
   * This method will be call it before the update process, actually this method will work as
   * preparation for the update, basically what it does to to back-up the current .dotserver/ code
   *
   * @throws IOException
   * @throws UpdateException
   */
  public void preUpdate() throws UpdateException {

    logger.info(Messages.getString("UpdateAgent.debug.start.backUp"));

    // Current format for the back-up folder
    SimpleDateFormat folderDateFormat = new SimpleDateFormat("yyyyMMdd");

    // This is the name of the folder where we are going to store the back-up
    String currentBackUpFolderName = folderDateFormat.format(new Date());
    // Complete back-up path
    String backUpPath =
        distributionHome
            + File.separator
            + UpdateAgent.FOLDER_HOME_BACK_UP
            + File.separator
            + currentBackUpFolderName;
    // .dotserver folder path
    String dotserverPath = distributionHome + File.separator + UpdateAgent.FOLDER_HOME_DOTSERVER;
    // .bin folder path
    String binPath = distributionHome + File.separator + UpdateAgent.FOLDER_HOME_BIN;
    // .plugins folder path
    String pluginsPath = distributionHome + File.separator + UpdateAgent.FOLDER_HOME_PLUGINS;

    try {

      // First we need to create the back up for the current project, for this we need to user hard
      // links, this back up could be huge
      FileUtil.copyDirectory(
          dotserverPath, backUpPath + File.separator + UpdateAgent.FOLDER_HOME_DOTSERVER, true);
      FileUtil.copyDirectory(
          pluginsPath, backUpPath + File.separator + UpdateAgent.FOLDER_HOME_PLUGINS, true);
      FileUtil.copyDirectory(
          binPath, backUpPath + File.separator + UpdateAgent.FOLDER_HOME_BIN, true);

    } catch (Exception e) {
      String error = Messages.getString("UpdateAgent.error.ant.prepare.back-up");
      if (!UpdateAgent.isDebug) {
        error += Messages.getString("UpdateAgent.text.use.verbose", UpdateAgent.logFile);
      }
      logger.error(error, e);
      throw new UpdateException(error, UpdateException.ERROR);
    }
  }