public List cleanupBrokenFiles()

in common/src/main/java/jetbrains/buildServer/torrent/seeder/TorrentFilesDB.java [63:100]


  public List<File> cleanupBrokenFiles() {
    List<File> brokenTorrentFiles = new ArrayList<File>();

    Map<FileInfo, File> toRemove = new HashMap<FileInfo, File>();

    Map<FileInfo, FileInfo> cacheCopy;
    synchronized (myFile2TorrentMap) {
      final Map<FileInfo, FileInfo> cache = myFile2TorrentMap.get();
      cacheCopy = new HashMap<FileInfo, FileInfo>(cache);
    }

    for (Map.Entry<FileInfo, FileInfo> entry : cacheCopy.entrySet()) {
      final FileInfo torrentInfo = cacheCopy.get(entry.getKey());

      File srcFile = entry.getKey().getFile();
      File torrentFile = torrentInfo != null ? torrentInfo.getFile() : null;

      if (torrentFile == null || !srcFile.isFile() || !torrentFile.isFile()) {
        toRemove.put(entry.getKey(), torrentFile);
        brokenTorrentFiles.add(torrentFile);
      }
    }

    synchronized (myFile2TorrentMap) {
      final Map<FileInfo, FileInfo> cache = myFile2TorrentMap.get();
      if (!toRemove.isEmpty()) {
        myIsDBChanged = true;
      }
      cache.keySet().removeAll(toRemove.keySet());
    }


    for (Map.Entry<FileInfo, File> e: toRemove.entrySet()) {
      notifyOnRemove(new AbstractMap.SimpleEntry<File, File>(e.getKey().getFile(), e.getValue()));
    }

    return brokenTorrentFiles;
  }