Exemplo n.º 1
0
  /**
   * This method of FileSystem remove file and dir both from file system and from DataBase
   *
   * @param user VomsGridUser
   * @param stori StoRI
   * @param recursive boolean
   * @return TReturnStatus
   */
  private TReturnStatus manageAuthorizedRMDIR(LocalFile directory, boolean recursive) {

    TReturnStatus returnStatus;

    if ((directory.exists()) && (directory.isDirectory())) {
      if (recursive) {

        log.debug("{}: Recursive deletion will remove directory and contents.", SRM_COMMAND);

        if (!deleteDirectoryContent(directory)) {
          return CommandHelper.buildStatus(
              TStatusCode.SRM_FAILURE, "Unable to delete some files within directory.");
        }
      }

      if (!removeFile(directory)) {
        returnStatus =
            CommandHelper.buildStatus(
                TStatusCode.SRM_NON_EMPTY_DIRECTORY, "Directory is not empty");
      } else {
        returnStatus =
            CommandHelper.buildStatus(TStatusCode.SRM_SUCCESS, "Directory removed with success!");
      }
    } else {
      log.debug("{}: request with invalid directory specified!", SRM_COMMAND);
      if (!directory.exists()) {
        returnStatus =
            CommandHelper.buildStatus(TStatusCode.SRM_INVALID_PATH, "Directory does not exists");
      } else {
        returnStatus = CommandHelper.buildStatus(TStatusCode.SRM_INVALID_PATH, "Not a directory");
      }
    }
    return returnStatus;
  }
Exemplo n.º 2
0
  /** Recursive function for deleteAll */
  private boolean deleteDirectoryContent(LocalFile directory) {

    boolean result = true;
    if (directory.exists()) {
      if (directory.isDirectory()) {
        LocalFile[] list = directory.listFiles();
        if (list.length > 0) {
          for (LocalFile element : list) {
            result = result && deleteDirectoryContent(element);
            if (element.exists()) {
              result = result && removeFile(element);
            }
          }
        } else {
          // The directory is empty and it is deleted by the if in the
          // for loop above
        }
      } else {
        result = removeFile(directory);
      }
    }
    return result;
  }
Exemplo n.º 3
0
  private boolean removeFile(LocalFile file) {

    boolean result = false;
    LocalFile[] list;
    if (file.exists()) {
      if (file.isDirectory()) {
        list = file.listFiles();
        if (list.length > 0) {
          result = false;

          log.info("{} : Unable to delete non-empty directory {}", SRM_COMMAND, file);

        } else {
          result = file.delete();
        }
      } else {
        result = file.delete();
      }
    } else {
      result = false;
      log.debug("{}: file {} does not exist", SRM_COMMAND, file);
    }
    return result;
  }