Fixed LastWriteTime

This commit is contained in:
Mark McDowall 2013-09-28 15:25:22 -07:00
parent 82d4933152
commit 88afc19716
2 changed files with 20 additions and 13 deletions

View File

@ -39,7 +39,7 @@ namespace NzbDrone.Common
string GetPathRoot(string path);
void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType);
bool IsParent(string parentPath, string childPath);
void SetFolderAccessTime(string path, DateTime time){
void SetFolderWriteTime(string path, DateTime time);
FileAttributes GetFileAttributes(string path);
void EmptyFolder(string path);
}
@ -442,6 +442,10 @@ namespace NzbDrone.Common
return false;
}
public void SetFolderWriteTime(string path, DateTime time)
{
Directory.SetLastWriteTimeUtc(path, time);
}
private static void RemoveReadOnly(string path)
{
@ -452,10 +456,6 @@ namespace NzbDrone.Common
}
}
private void SetFolderAccessTime(string path, DateTime time){
Directory.SetLastWriteTimeUtc(path,time);
}
public FileAttributes GetFileAttributes(string path)
{
return File.GetAttributes(path);

View File

@ -42,9 +42,7 @@ namespace NzbDrone.Core.MediaFiles
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
var newFileName = _buildFileNames.BuildFilename(episodes, series, episodeFile);
var filePath = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
MoveFile(episodeFile, filePath);
_diskProvider.SetFolderAccessTime( Path.GetDirectoryName(filePath), episodeFile.DateAdded);
_diskProvider.SetFolderAccessTime( series.Path, episodeFile.DateAdded);
MoveFile(episodeFile, series, filePath);
return filePath;
}
@ -53,14 +51,12 @@ namespace NzbDrone.Core.MediaFiles
{
var newFileName = _buildFileNames.BuildFilename(localEpisode.Episodes, localEpisode.Series, episodeFile);
var filePath = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
MoveFile(episodeFile, filePath);
_diskProvider.SetFolderAccessTime( Path.GetDirectoryName(filePath), episodeFile.DateAdded);
_diskProvider.SetFolderAccessTime( localEpisode.Series.Path, episodeFile.DateAdded);
MoveFile(episodeFile, localEpisode.Series, filePath);
return filePath;
}
private void MoveFile(EpisodeFile episodeFile, string destinationFilename)
private void MoveFile(EpisodeFile episodeFile, Series series, string destinationFilename)
{
if (!_diskProvider.FileExists(episodeFile.Path))
{
@ -77,6 +73,17 @@ namespace NzbDrone.Core.MediaFiles
_logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, destinationFilename);
_diskProvider.MoveFile(episodeFile.Path, destinationFilename);
_logger.Trace("Setting last write time on series folder: {0}", series.Path);
_diskProvider.SetFolderWriteTime(series.Path, episodeFile.DateAdded);
if (series.SeasonFolder)
{
var seasonFolder = Path.GetDirectoryName(episodeFile.Path);
_logger.Trace("Setting last write time on season folder: {0}", seasonFolder);
_diskProvider.SetFolderWriteTime(seasonFolder, episodeFile.DateAdded);
}
//Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important.
try
{