Removed redunent UTC/non-utc File/dire methods.

everything is in UTC now.
pull/6/head
Keivan Beigi 10 years ago
parent 9d8e4de7b4
commit ef1e290311

@ -43,7 +43,7 @@ namespace NzbDrone.Api.Logs
{
Id = i + 1,
Filename = filename,
LastWriteTime = _diskProvider.FileGetLastWriteUtc(file),
LastWriteTime = _diskProvider.FileGetLastWrite(file),
ContentsUrl = String.Format("{0}/api/{1}/{2}", _configFileProvider.UrlBase, Resource, filename),
DownloadUrl = String.Format("{0}/{1}/{2}", _configFileProvider.UrlBase, DownloadUrlRoot, filename)
});

@ -10,12 +10,6 @@ namespace NzbDrone.Common.Test.DiskProviderTests
{
public class DiskProviderFixtureBase<TSubject> : TestBase<TSubject> where TSubject : class, IDiskProvider
{
[SetUp]
public void Setup()
{
}
public DirectoryInfo GetFilledTempFolder()
{
var tempFolder = GetTempFilePath();
@ -98,7 +92,7 @@ namespace NzbDrone.Common.Test.DiskProviderTests
var source = GetFilledTempFolder();
var destination = new DirectoryInfo(GetTempFilePath());
Subject.CopyFolder(source.FullName, destination.FullName);
//Delete Random File
destination.GetFiles("*.*", SearchOption.AllDirectories).First().Delete();
@ -172,7 +166,7 @@ namespace NzbDrone.Common.Test.DiskProviderTests
public void empty_folder_should_return_folder_modified_date()
{
var tempfolder = new DirectoryInfo(TempFolder);
Subject.FolderGetLastWriteUtc(TempFolder).Should().Be(tempfolder.LastWriteTimeUtc);
Subject.FolderGetLastWrite(TempFolder).Should().Be(tempfolder.LastWriteTimeUtc);
}
[Test]
@ -183,14 +177,14 @@ namespace NzbDrone.Common.Test.DiskProviderTests
Directory.CreateDirectory(testDir);
Subject.FolderSetLastWriteTimeUtc(TempFolder, DateTime.UtcNow.AddMinutes(-5));
Subject.FolderSetLastWriteTime(TempFolder, DateTime.UtcNow.AddMinutes(-5));
TestLogger.Info("Path is: {0}", testFile);
Subject.WriteAllText(testFile, "Test");
Subject.FolderGetLastWriteUtc(TempFolder).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-1));
Subject.FolderGetLastWriteUtc(TempFolder).Should().BeBefore(DateTime.UtcNow.AddMinutes(1));
Subject.FolderGetLastWrite(TempFolder).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-1));
Subject.FolderGetLastWrite(TempFolder).Should().BeBefore(DateTime.UtcNow.AddMinutes(1));
}
[Test]
@ -234,11 +228,24 @@ namespace NzbDrone.Common.Test.DiskProviderTests
Subject.InheritFolderPermissions(testFile);
}
[Test]
public void should_be_set_last_file_write()
{
var testFile = GetTempFilePath();
Subject.WriteAllText(testFile, new Guid().ToString());
var lastWriteTime = new DateTime(2012, 1, 2);
Subject.FileSetLastWriteTime(testFile, lastWriteTime);
Subject.FileGetLastWrite(testFile).Should().Be(lastWriteTime);
}
[Test]
[Explicit]
public void check_last_write()
{
Console.WriteLine(Subject.FolderGetLastWriteUtc(GetFilledTempFolder().FullName));
Console.WriteLine(Subject.FolderGetLastWrite(GetFilledTempFolder().FullName));
Console.WriteLine(GetFilledTempFolder().LastWriteTimeUtc);
}

@ -27,14 +27,14 @@ namespace NzbDrone.Common.Disk
public abstract long? GetTotalSize(string path);
public DateTime FolderGetCreationTimeUtc(string path)
public DateTime FolderGetCreationTime(string path)
{
CheckFolderExists(path);
return new DirectoryInfo(path).CreationTimeUtc;
}
public DateTime FolderGetLastWriteUtc(string path)
public DateTime FolderGetLastWrite(string path)
{
CheckFolderExists(path);
@ -45,28 +45,13 @@ namespace NzbDrone.Common.Disk
return new DirectoryInfo(path).LastWriteTimeUtc;
}
return dirFiles.Select(f => new FileInfo(f))
.Max(c => c.LastWriteTimeUtc);
}
public DateTime FileGetCreationTimeUtc(string path)
{
CheckFileExists(path);
return new FileInfo(path).CreationTimeUtc;
return dirFiles.Select(f => new FileInfo(f)).Max(c => c.LastWriteTimeUtc);
}
public DateTime FileGetLastWrite(string path)
{
CheckFileExists(path);
return new FileInfo(path).LastWriteTime;
}
public DateTime FileGetLastWriteUtc(string path)
{
CheckFileExists(path);
return new FileInfo(path).LastWriteTimeUtc;
}
@ -298,14 +283,7 @@ namespace NzbDrone.Common.Disk
File.WriteAllText(filename, contents);
}
public void FileSetLastWriteTimeUtc(string path, DateTime dateTime)
{
Ensure.That(path, () => path).IsValidPath();
File.SetLastWriteTimeUtc(path, dateTime);
}
public void FolderSetLastWriteTimeUtc(string path, DateTime dateTime)
public void FolderSetLastWriteTime(string path, DateTime dateTime)
{
Ensure.That(path, () => path).IsValidPath();
@ -319,20 +297,6 @@ namespace NzbDrone.Common.Disk
File.SetLastWriteTime(path, dateTime);
}
public void FileSetLastAccessTime(string path, DateTime dateTime)
{
Ensure.That(path, () => path).IsValidPath();
File.SetLastAccessTimeUtc(path, dateTime);
}
public void FileSetLastAccessTimeUtc(string path, DateTime dateTime)
{
Ensure.That(path, () => path).IsValidPath();
File.SetLastAccessTimeUtc(path, dateTime);
}
public bool IsFileLocked(string file)
{
try

@ -11,11 +11,9 @@ namespace NzbDrone.Common.Disk
void InheritFolderPermissions(string filename);
void SetPermissions(string path, string mask, string user, string group);
long? GetTotalSize(string path);
DateTime FolderGetCreationTimeUtc(string path);
DateTime FolderGetLastWriteUtc(string path);
DateTime FileGetCreationTimeUtc(string path);
DateTime FolderGetCreationTime(string path);
DateTime FolderGetLastWrite(string path);
DateTime FileGetLastWrite(string path);
DateTime FileGetLastWriteUtc(string path);
void EnsureFolder(string path);
bool FolderExists(string path);
bool FileExists(string path);
@ -33,10 +31,8 @@ namespace NzbDrone.Common.Disk
void DeleteFolder(string path, bool recursive);
string ReadAllText(string filePath);
void WriteAllText(string filename, string contents);
void FileSetLastWriteTimeUtc(string path, DateTime dateTime);
void FolderSetLastWriteTimeUtc(string path, DateTime dateTime);
void FolderSetLastWriteTime(string path, DateTime dateTime);
void FileSetLastWriteTime(string path, DateTime dateTime);
void FileSetLastAccessTime(string path, DateTime dateTime);
bool IsFileLocked(string path);
string GetPathRoot(string path);
string GetParentFolder(string path);

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
new MediaCover.MediaCover {CoverType = MediaCoverTypes.Banner}
};
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileGetLastWriteUtc(It.IsAny<string>()))
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileGetLastWrite(It.IsAny<string>()))
.Returns(new DateTime(1234));
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(It.IsAny<string>()))

@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
private void GivenLastWriteTimeUtc(DateTime time)
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FileGetLastWriteUtc(It.IsAny<string>()))
.Setup(s => s.FileGetLastWrite(It.IsAny<string>()))
.Returns(time);
}

@ -18,19 +18,19 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
private void WithExpired()
{
Mocker.GetMock<IDiskProvider>().Setup(s => s.FolderGetLastWriteUtc(It.IsAny<String>()))
Mocker.GetMock<IDiskProvider>().Setup(s => s.FolderGetLastWrite(It.IsAny<String>()))
.Returns(DateTime.UtcNow.AddDays(-10));
Mocker.GetMock<IDiskProvider>().Setup(s => s.FileGetLastWriteUtc(It.IsAny<String>()))
Mocker.GetMock<IDiskProvider>().Setup(s => s.FileGetLastWrite(It.IsAny<String>()))
.Returns(DateTime.UtcNow.AddDays(-10));
}
private void WithNonExpired()
{
Mocker.GetMock<IDiskProvider>().Setup(s => s.FolderGetLastWriteUtc(It.IsAny<String>()))
Mocker.GetMock<IDiskProvider>().Setup(s => s.FolderGetLastWrite(It.IsAny<String>()))
.Returns(DateTime.UtcNow.AddDays(-3));
Mocker.GetMock<IDiskProvider>().Setup(s => s.FileGetLastWriteUtc(It.IsAny<String>()))
Mocker.GetMock<IDiskProvider>().Setup(s => s.FileGetLastWrite(It.IsAny<String>()))
.Returns(DateTime.UtcNow.AddDays(-3));
}

@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path);
Mocker.GetMock<IDiskProvider>().Verify(v => v.FolderSetLastWriteTimeUtc(@"C:\Test\Recycle Bin\30 Rock".AsOsAgnostic(), It.IsAny<DateTime>()), Times.Once());
Mocker.GetMock<IDiskProvider>().Verify(v => v.FolderSetLastWriteTime(@"C:\Test\Recycle Bin\30 Rock".AsOsAgnostic(), It.IsAny<DateTime>()), Times.Once());
}
[Test]
@ -72,7 +72,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
Mocker.Resolve<RecycleBinProvider>().DeleteFolder(path);
Mocker.GetMock<IDiskProvider>().Verify(v => v.FileSetLastWriteTimeUtc(It.IsAny<String>(), It.IsAny<DateTime>()), Times.Exactly(3));
Mocker.GetMock<IDiskProvider>().Verify(v => v.FileSetLastWriteTime(It.IsAny<String>(), It.IsAny<DateTime>()), Times.Exactly(3));
}
}
}

@ -73,7 +73,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
Mocker.Resolve<RecycleBinProvider>().DeleteFile(path);
Mocker.GetMock<IDiskProvider>().Verify(v => v.FileSetLastWriteTimeUtc(@"C:\Test\Recycle Bin\S01E01.avi".AsOsAgnostic(), It.IsAny<DateTime>()), Times.Once());
Mocker.GetMock<IDiskProvider>().Verify(v => v.FileSetLastWriteTime(@"C:\Test\Recycle Bin\S01E01.avi".AsOsAgnostic(), It.IsAny<DateTime>()), Times.Once());
}
}
}

@ -86,7 +86,7 @@ namespace NzbDrone.Core.Backup
{
Path = Path.GetFileName(b),
Type = backupType,
Time = _diskProvider.FileGetLastWriteUtc(b)
Time = _diskProvider.FileGetLastWrite(b)
}));
}
}
@ -136,7 +136,7 @@ namespace NzbDrone.Core.Backup
foreach (var file in files)
{
var lastWriteTime = _diskProvider.FileGetLastWriteUtc(file);
var lastWriteTime = _diskProvider.FileGetLastWrite(file);
if (lastWriteTime.AddDays(28) < DateTime.UtcNow)
{

@ -182,7 +182,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
private String GetDownloadClientId(String filename)
{
return Definition.Name + "_" + Path.GetFileName(filename) + "_" + _diskProvider.FileGetLastWriteUtc(filename).Ticks;
return Definition.Name + "_" + Path.GetFileName(filename) + "_" + _diskProvider.FileGetLastWrite(filename).Ticks;
}
}
}

@ -69,7 +69,7 @@ namespace NzbDrone.Core.Download.Clients.UsenetBlackhole
var historyItem = new DownloadClientItem
{
DownloadClient = Definition.Name,
DownloadClientId = Definition.Name + "_" + Path.GetFileName(folder) + "_" + _diskProvider.FolderGetCreationTimeUtc(folder).Ticks,
DownloadClientId = Definition.Name + "_" + Path.GetFileName(folder) + "_" + _diskProvider.FolderGetCreationTime(folder).Ticks,
Title = title,
TotalSize = files.Select(_diskProvider.GetFileSize).Sum(),
@ -98,7 +98,7 @@ namespace NzbDrone.Core.Download.Clients.UsenetBlackhole
var historyItem = new DownloadClientItem
{
DownloadClient = Definition.Name,
DownloadClientId = Definition.Name + "_" + Path.GetFileName(videoFile) + "_" + _diskProvider.FileGetLastWriteUtc(videoFile).Ticks,
DownloadClientId = Definition.Name + "_" + Path.GetFileName(videoFile) + "_" + _diskProvider.FileGetLastWrite(videoFile).Ticks,
Title = title,
TotalSize = _diskProvider.GetFileSize(videoFile),

@ -67,7 +67,7 @@ namespace NzbDrone.Core.MediaCover
if (_diskProvider.FileExists(filePath))
{
var lastWrite = _diskProvider.FileGetLastWriteUtc(filePath);
var lastWrite = _diskProvider.FileGetLastWrite(filePath);
mediaCover.Url += "?lastWrite=" + lastWrite.Ticks;
}
}

@ -208,7 +208,7 @@ namespace NzbDrone.Core.MediaFiles
if (OsInfo.IsMono) return;
_logger.Debug("Setting last write time on series folder: {0}", path);
_diskProvider.FolderSetLastWriteTimeUtc(path, time);
_diskProvider.FolderSetLastWriteTime(path, time);
}
}
}

@ -45,7 +45,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
return false;
}
if (_diskProvider.FileGetLastWriteUtc(localEpisode.Path) > DateTime.UtcNow.AddMinutes(-5))
if (_diskProvider.FileGetLastWrite(localEpisode.Path) > DateTime.UtcNow.AddMinutes(-5))
{
_logger.Debug("{0} appears to be unpacking still", localEpisode.Path);
return false;

@ -54,13 +54,13 @@ namespace NzbDrone.Core.MediaFiles
_diskProvider.MoveFolder(path, destination);
logger.Debug("Setting last accessed: {0}", path);
_diskProvider.FolderSetLastWriteTimeUtc(destination, DateTime.UtcNow);
_diskProvider.FolderSetLastWriteTime(destination, DateTime.UtcNow);
foreach (var file in _diskProvider.GetFiles(destination, SearchOption.AllDirectories))
{
if (OsInfo.IsWindows)
{
//TODO: Better fix than this for non-Windows?
_diskProvider.FileSetLastWriteTimeUtc(file, DateTime.UtcNow);
_diskProvider.FileSetLastWriteTime(file, DateTime.UtcNow);
}
}
@ -111,7 +111,7 @@ namespace NzbDrone.Core.MediaFiles
//TODO: Better fix than this for non-Windows?
if (OsInfo.IsWindows)
{
_diskProvider.FileSetLastWriteTimeUtc(destination, DateTime.UtcNow);
_diskProvider.FileSetLastWriteTime(destination, DateTime.UtcNow);
}
logger.Debug("File has been moved to the recycling bin: {0}", destination);
@ -153,7 +153,7 @@ namespace NzbDrone.Core.MediaFiles
foreach (var folder in _diskProvider.GetDirectories(_configService.RecycleBin))
{
if (_diskProvider.FolderGetLastWriteUtc(folder).AddDays(7) > DateTime.UtcNow)
if (_diskProvider.FolderGetLastWrite(folder).AddDays(7) > DateTime.UtcNow)
{
logger.Debug("Folder hasn't expired yet, skipping: {0}", folder);
continue;
@ -164,7 +164,7 @@ namespace NzbDrone.Core.MediaFiles
foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.TopDirectoryOnly))
{
if (_diskProvider.FileGetLastWriteUtc(file).AddDays(7) > DateTime.UtcNow)
if (_diskProvider.FileGetLastWrite(file).AddDays(7) > DateTime.UtcNow)
{
logger.Debug("File hasn't expired yet, skipping: {0}", file);
continue;

@ -121,7 +121,7 @@ namespace NzbDrone.Core.MediaFiles
if (DateTime.TryParse(fileDate + ' ' + fileTime, out airDate))
{
// avoiding false +ve checks and set date skewing by not using UTC (Windows)
DateTime oldDateTime = _diskProvider.FileGetLastWriteUtc(filePath);
DateTime oldDateTime = _diskProvider.FileGetLastWrite(filePath);
if (!DateTime.Equals(airDate, oldDateTime))
{
@ -150,7 +150,7 @@ namespace NzbDrone.Core.MediaFiles
private bool ChangeFileDateToUtcAirDate(string filePath, DateTime airDateUtc)
{
DateTime oldLastWrite = _diskProvider.FileGetLastWriteUtc(filePath);
DateTime oldLastWrite = _diskProvider.FileGetLastWrite(filePath);
if (!DateTime.Equals(airDateUtc, oldLastWrite))
{

Loading…
Cancel
Save