public void moveFile_should_overwrite_existing_file() { var diskProvider = new DiskProvider(); diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); var targetPath = Path.Combine(BinFolderCopy.FullName, "file.move"); diskProvider.MoveFile(BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath); diskProvider.MoveFile(BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath); File.Exists(targetPath).Should().BeTrue(); }
public void moveFile_should_overwrite_existing_file() { var diskProvider = new DiskProvider(); diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); var targetPath = Path.Combine(BinFolderCopy.FullName, "file.move"); diskProvider.MoveFile(BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath); diskProvider.MoveFile(BinFolderCopy.GetFiles("*.pdb", SearchOption.AllDirectories).First().FullName, targetPath); File.Exists(targetPath).Should().BeTrue(); }
public void moveFile_should_not_move_overwrite_itself() { var diskProvider = new DiskProvider(); diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); var targetPath = BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName; diskProvider.MoveFile(targetPath, targetPath); File.Exists(targetPath).Should().BeTrue(); ExceptionVerification.ExpectedWarns(1); }
public void moveFile_should_not_move_overwrite_itself() { var diskProvider = new DiskProvider(); diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName); var targetPath = BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName; diskProvider.MoveFile(targetPath, targetPath); File.Exists(targetPath).Should().BeTrue(); ExceptionVerification.ExpectedWarns(1); }
public virtual void DeleteFile(string path) { logger.Trace("Attempting to send '{0}' to recycling bin", path); var recyclingBin = _configProvider.RecycleBin; if (String.IsNullOrWhiteSpace(recyclingBin)) { logger.Info("Recycling Bin has not been configured, deleting permanently. {0}", path); _diskProvider.DeleteFile(path); logger.Trace("File has been permanently deleted: {0}", path); } else { var destination = Path.Combine(recyclingBin, new FileInfo(path).Name); logger.Trace("Moving '{0}' to '{1}'", path, destination); _diskProvider.MoveFile(path, destination); _diskProvider.FileSetLastWriteTimeUtc(destination, DateTime.UtcNow); logger.Trace("File has been moved to the recycling bin: {0}", destination); } }
public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false) { if (episodeFile == null) { throw new ArgumentNullException("episodeFile"); } var series = _seriesProvider.GetSeries(episodeFile.SeriesId); var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId); string newFileName = _mediaFileProvider.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); //Only rename if existing and new filenames don't match if (DiskProvider.PathEquals(episodeFile.Path, newFile.FullName)) { Logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path); return(null); } if (!_diskProvider.FileExists(episodeFile.Path)) { Logger.Error("Episode file path does not exist, {0}", episodeFile.Path); return(null); } _diskProvider.CreateDirectory(newFile.DirectoryName); Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile.FullName); _diskProvider.MoveFile(episodeFile.Path, newFile.FullName); //Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important. try { _diskProvider.InheritFolderPermissions(newFile.FullName); } catch (UnauthorizedAccessException ex) { Logger.Debug("Unable to apply folder permissions to: ", newFile.FullName); Logger.TraceException(ex.Message, ex); } episodeFile.Path = newFile.FullName; _mediaFileProvider.Update(episodeFile); var parseResult = Parser.ParsePath(episodeFile.Path); parseResult.Series = series; parseResult.Quality = new QualityModel { Quality = episodeFile.Quality, Proper = episodeFile.Proper }; parseResult.Episodes = episodes; var message = _downloadProvider.GetDownloadTitle(parseResult); if (newDownload) { _externalNotificationProvider.OnDownload(message, series); foreach (var episode in episodes) { _signalRProvider.UpdateEpisodeStatus(episode.EpisodeId, EpisodeStatusType.Ready, parseResult.Quality); } } else { _externalNotificationProvider.OnRename(message, series); } return(episodeFile); }