@SuppressWarnings("squid:S3776")
  public static void moveNewTsFile(
      TsFileResource oldTsFileResource, List<TsFileResource> newTsFileResources)
      throws IOException {
    // delete old mods
    oldTsFileResource.removeModFile();

    File newPartitionDir =
        new File(
            oldTsFileResource.getTsFile().getParent()
                + File.separator
                + oldTsFileResource.getTimePartition());
    if (newTsFileResources.isEmpty()) { // if the oldTsFile has no mods, it should not be deleted.
      if (oldTsFileResource.isDeleted()) {
        oldTsFileResource.remove();
      }
      Files.delete(newPartitionDir.toPath());
      return;
    }
    FSFactory fsFactory = FSFactoryProducer.getFSFactory();
    File oldTsFile = oldTsFileResource.getTsFile();
    boolean isOldFileExisted = oldTsFile.exists();
    if (isOldFileExisted) {
      Files.delete(oldTsFile.toPath());
    }
    for (TsFileResource newTsFileResource : newTsFileResources) {
      newPartitionDir =
          new File(
              oldTsFileResource.getTsFile().getParent()
                  + File.separator
                  + newTsFileResource.getTimePartition());
      // if old TsFile has been deleted by other threads, then delete its new TsFile.
      if (!isOldFileExisted) {
        newTsFileResource.remove();
      } else {
        File newTsFile = newTsFileResource.getTsFile();

        // move TsFile
        fsFactory.moveFile(newTsFile, oldTsFile);

        // move .resource File
        newTsFileResource.setFile(fsFactory.getFile(oldTsFile.getParent(), newTsFile.getName()));
        newTsFileResource.setStatus(TsFileResourceStatus.NORMAL);
        try {
          newTsFileResource.serialize();
        } catch (IOException e) {
          e.printStackTrace();
        }
        File tmpResourceFile =
            fsFactory.getFile(
                newPartitionDir, newTsFile.getName() + TsFileResource.RESOURCE_SUFFIX);
        if (tmpResourceFile.exists()) {
          Files.delete(tmpResourceFile.toPath());
        }
      }
      // if the newPartition folder is empty, then it will be deleted
      if (newPartitionDir.exists()) {
        Files.delete(newPartitionDir.toPath());
      }
    }
  }
This method is used to move a new TsFile and its corresponding resource file to the correct
folder.

@param oldTsFileResource
@param newTsFileResources if the old TsFile has not any deletions or all the data in which has
    been deleted or its modFile does not exist, then this size will be 0.
@throws IOException if io errors occurred
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/settle/TsFileAndModSettleTool.java