List of usage examples for java.nio.file Path equals
boolean equals(Object other);
From source file:org.tinymediamanager.core.movie.tasks.MovieUpdateDatasourceTask2.java
@Override public void doInBackground() { // check if there is at least one DS to update Utils.removeEmptyStringsFromList(dataSources); if (dataSources.isEmpty()) { LOGGER.info("no datasource to update"); MessageManager.instance.pushMessage( new Message(MessageLevel.ERROR, "update.datasource", "update.datasource.nonespecified")); return;/*from w ww .ja v a 2s . c om*/ } // get existing movie folders List<Path> existing = new ArrayList<>(); for (Movie movie : movieList.getMovies()) { existing.add(movie.getPathNIO()); } try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); List<Path> imageFiles = new ArrayList<>(); for (String ds : dataSources) { initThreadPool(3, "update"); setTaskName(BUNDLE.getString("update.datasource") + " '" + ds + "'"); publishState(); Path dsAsPath = Paths.get(ds); // first of all check if the DS is available; we can take the // Files.exist here: // if the DS exists (and we have access to read it): Files.exist = true if (!Files.exists(dsAsPath)) { // error - continue with next datasource MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, "update.datasource", "update.datasource.unavailable", new String[] { ds })); continue; } // just check datasource folder, parse NEW folders first List<Path> newMovieDirs = new ArrayList<>(); List<Path> existingMovieDirs = new ArrayList<>(); List<Path> rootList = listFilesAndDirs(dsAsPath); // when there is _nothing_ found in the ds root, it might be offline - // skip further processing; // not in Windows since that won't happen there if (rootList.isEmpty() && !Platform.isWindows()) { // error - continue with next datasource MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, "update.datasource", "update.datasource.unavailable", new String[] { ds })); continue; } List<Path> rootFiles = new ArrayList<>(); for (Path path : rootList) { if (Files.isDirectory(path)) { if (existing.contains(path)) { existingMovieDirs.add(path); } else { newMovieDirs.add(path); } } else { rootFiles.add(path); } } rootList.clear(); for (Path path : newMovieDirs) { searchAndParse(dsAsPath.toAbsolutePath(), path, Integer.MAX_VALUE); } for (Path path : existingMovieDirs) { searchAndParse(dsAsPath.toAbsolutePath(), path, Integer.MAX_VALUE); } if (rootFiles.size() > 0) { submitTask(new parseMultiMovieDirTask(dsAsPath.toAbsolutePath(), dsAsPath.toAbsolutePath(), rootFiles)); } waitForCompletionOrCancel(); newMovieDirs.clear(); existingMovieDirs.clear(); rootFiles.clear(); if (cancel) { break; } // cleanup cleanup(ds); // mediainfo gatherMediainfo(ds); if (cancel) { break; } // build image cache on import if (MovieModuleManager.MOVIE_SETTINGS.isBuildImageCacheOnImport()) { for (Movie movie : movieList.getMovies()) { if (!dsAsPath.equals(Paths.get(movie.getDataSource()))) { // check only movies matching datasource continue; } imageFiles.addAll(movie.getImagesToCache()); } } } // END datasource loop if (imageFiles.size() > 0) { ImageCacheTask task = new ImageCacheTask(imageFiles); TmmTaskManager.getInstance().addUnnamedTask(task); } if (MovieModuleManager.MOVIE_SETTINGS.getSyncTrakt()) { TmmTask task = new SyncTraktTvTask(true, true, false, false); TmmTaskManager.getInstance().addUnnamedTask(task); } stopWatch.stop(); LOGGER.info("Done updating datasource :) - took " + stopWatch); LOGGER.debug("FilesFound " + filesFound.size()); LOGGER.debug("moviesFound " + movieList.getMovieCount()); LOGGER.debug("PreDir " + preDir); LOGGER.debug("PostDir " + postDir); LOGGER.debug("VisFile " + visFile); LOGGER.debug("PreDir2 " + preDir2); LOGGER.debug("PostDir2 " + postDir2); LOGGER.debug("VisFile2 " + visFile2); } catch (Exception e) { LOGGER.error("Thread crashed", e); MessageManager.instance.pushMessage( new Message(MessageLevel.ERROR, "update.datasource", "message.update.threadcrashed")); } }