public void removeUnusedTorrents()

in server/src/main/java/jetbrains/buildServer/torrent/UnusedTorrentFilesRemoverImpl.java [42:70]


  public void removeUnusedTorrents(@NotNull List<BuildArtifact> artifacts, @NotNull Path torrentsDir) {
    Collection<Path> torrentsForRemoving = new ArrayList<>();
    Set<String> expectedTorrentPathsForArtifacts = artifacts
            .stream()
            .map(it -> it.getRelativePath() + TorrentUtil.TORRENT_FILE_SUFFIX)
            .collect(Collectors.toSet());
    try {
      myFileWalker.walkFileTree(torrentsDir, new SimpleFileVisitor<Path>() {
        public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
          Path relativePath = torrentsDir.relativize(path);
          final String systemIndependentPath = FileUtil.toSystemIndependentName(relativePath.toString());
          if (expectedTorrentPathsForArtifacts.contains(systemIndependentPath)) {
            return FileVisitResult.CONTINUE;
          }
          torrentsForRemoving.add(path);
          return FileVisitResult.CONTINUE;
        }
      });
    } catch (IOException e) {
      LOG.warnAndDebugDetails("failed walk torrent files tree for removing useless torrents", e);
    }
    torrentsForRemoving.forEach(path -> {
      try {
        myFileRemover.remove(path);
      } catch (IOException e) {
        LOG.warnAndDebugDetails("unable to remove unused torrent file " + path, e);
      }
    });
  }