hdfs-protolib/src/main/java/com/streamsets/pipeline/stage/destination/hdfs/writer/RecordWriterManager.java
public int handleAlreadyExistingFiles() throws StageException, IOException {
    int result = 0;

    String globPath = dirPathTemplate;

    final String staticExpReg = "\\$\\{(sdc:|pipeline:|runtime:)[a-zA-Z0-9\\(\\)]*\\}";
    Pattern pattern = Pattern.compile(staticExpReg);
    Matcher matcher = pattern.matcher(globPath);
    ELEval eval = context.createELEval("dirPathTemplate");
    ELVars vars = context.createELVars();

    while (matcher.find()) {
      String expressionString = eval.eval(vars, matcher.group(), String.class);
      globPath = globPath.replace(matcher.group(), expressionString);
    }

    final String expReg = "\\$\\{[^}]*\\}";
    pattern = Pattern.compile(expReg);
    matcher = pattern.matcher(globPath);
    while (matcher.find()) {
      globPath = globPath.replace(matcher.group(), "*");
    }
    globPath = globPath.replaceAll("\\*+", "*");
    globPath = globPath + "/" + TMP_FILE_PREFIX + uniquePrefix + "*";

    LOG.info("Created the following glob path for file recovery: {}", globPath);
    FileStatus[] fileStatuses = fs.globStatus(new Path(globPath));
    for (FileStatus fileStatus : fileStatuses) {
      fsHelper.handleAlreadyExistingFile(fs, fileStatus.getPath());
      result++;
    }

    return result;
  }
public int handleAlreadyExistingFiles() throws StageException, IOException {
    int result = 0;

    String globPath = dirPathTemplate;

    final String staticExpReg = "\\$\\{(sdc:|pipeline:|runtime:)[a-zA-Z0-9\\(\\)]*\\}";
    Pattern pattern = Pattern.compile(staticExpReg);
    Matcher matcher = pattern.matcher(globPath);
    ELEval eval = context.createELEval("dirPathTemplate");
    ELVars vars = context.createELVars();

    while (matcher.find()) {
      String expressionString = eval.eval(vars, matcher.group(), String.class);
      globPath = globPath.replace(matcher.group(), expressionString);
    }

    final String expReg = "\\$\\{[^}]*\\}";
    pattern = Pattern.compile(expReg);
    matcher = pattern.matcher(globPath);
    while (matcher.find()) {
      globPath = globPath.replace(matcher.group(), "*");
    }
    globPath = globPath.replaceAll("\\*+", "*");
    globPath = globPath + "/" + TMP_FILE_PREFIX + uniquePrefix + "*";

    LOG.info("Created the following glob path for file recovery: {}", globPath);
    FileStatus[] fileStatuses = fs.globStatus(new Path(globPath));
    for (FileStatus fileStatus : fileStatuses) {
      fsHelper.handleAlreadyExistingFile(fs, fileStatus.getPath());
      result++;
    }

    return result;
  }
rename all _tmp_ files under directory path (dirPathTemplate)
return the number of _tmp_ files