Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Cake.Core/IO/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,47 @@ public Stream Open(FileMode fileMode, FileAccess fileAccess, FileShare fileShare
{
return _file.Open(fileMode, fileAccess, fileShare);
}

/// <inheritdoc/>
public IFile SetCreationTime(DateTime creationTime)
{
System.IO.File.SetCreationTime(Path.FullPath, creationTime);
return this;
}

/// <inheritdoc/>
public IFile SetCreationTimeUtc(DateTime creationTimeUtc)
{
System.IO.File.SetCreationTimeUtc(Path.FullPath, creationTimeUtc);
return this;
}

/// <inheritdoc/>
public IFile SetLastAccessTime(DateTime lastAccessTime)
{
System.IO.File.SetLastAccessTime(Path.FullPath, lastAccessTime);
return this;
}

/// <inheritdoc/>
public IFile SetLastAccessTimeUtc(DateTime lastAccessTimeUtc)
{
System.IO.File.SetLastAccessTimeUtc(Path.FullPath, lastAccessTimeUtc);
return this;
}

/// <inheritdoc/>
public IFile SetLastWriteTime(DateTime lastWriteTime)
{
System.IO.File.SetLastWriteTime(Path.FullPath, lastWriteTime);
return this;
}

/// <inheritdoc/>
public IFile SetLastWriteTimeUtc(DateTime lastWriteTimeUtc)
{
System.IO.File.SetLastWriteTimeUtc(Path.FullPath, lastWriteTimeUtc);
return this;
}
}
}
45 changes: 44 additions & 1 deletion src/Cake.Core/IO/IFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.IO;

namespace Cake.Core.IO
Expand Down Expand Up @@ -55,5 +56,47 @@ public interface IFile : IFileSystemInfo
/// <param name="fileShare">The file share.</param>
/// <returns>A <see cref="Stream"/> to the file.</returns>
Stream Open(FileMode fileMode, FileAccess fileAccess, FileShare fileShare);

/// <summary>
/// Sets the date and time that the file was created.
/// </summary>
/// <param name="creationTime">A <see cref="DateTime"/> containing the value to set for the creation date and time of path. This value is expressed in local time.</param>
/// <returns>A <see cref="IFile"/> instance representing the specified path.</returns>
IFile SetCreationTime(DateTime creationTime) => this;

/// <summary>
/// Sets the date and time, in Coordinated Universal Time (UTC), that the file was created.
/// </summary>
/// <param name="creationTimeUtc">A <see cref="DateTime"/> containing the value to set for the creation date and time of path. This value is expressed in UTC time.</param>
/// <returns>A <see cref="IFile"/> instance representing the specified path.</returns>
IFile SetCreationTimeUtc(DateTime creationTimeUtc) => this;

/// <summary>
/// Sets the date and time that the specified file or directory was last accessed.
/// </summary>
/// <param name="lastAccessTime">A <see cref="DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in local time.</param>
/// <returns>A <see cref="IFile"/> instance representing the specified path.</returns>
IFile SetLastAccessTime(DateTime lastAccessTime) => this;

/// <summary>
/// Sets the date and time, in Coordinated Universal Time (UTC), that the specified file or directory was last accessed.
/// </summary>
/// <param name="lastAccessTimeUtc">A <see cref="DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in local time.</param>
/// <returns>A <see cref="IFile"/> instance representing the specified path.</returns>
IFile SetLastAccessTimeUtc(DateTime lastAccessTimeUtc) => this;

/// <summary>
/// Sets the date and time that the specified file or directory was last written to.
/// </summary>
/// <param name="lastWriteTime">A <see cref="DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in local time.</param>
/// <returns>A <see cref="IFile"/> instance representing the specified path.</returns>
IFile SetLastWriteTime(DateTime lastWriteTime) => this;

/// <summary>
/// Sets the date and time, in Coordinated Universal Time (UTC), that the specified file or directory was last written to.
/// </summary>
/// <param name="lastWriteTimeUtc">A <see cref="DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in local time.</param>
/// <returns>A <see cref="IFile"/> instance representing the specified path.</returns>
IFile SetLastWriteTimeUtc(DateTime lastWriteTimeUtc) => this;
}
}
}
38 changes: 37 additions & 1 deletion src/Cake.Testing/FakeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,41 @@ private long GetPosition(FileMode fileMode, out bool fileWasCreated)
}
throw new NotSupportedException();
}

/// <inheritdoc/>
public IFile SetCreationTime(DateTime creationTime)
{
return this;
}

/// <inheritdoc/>
public IFile SetCreationTimeUtc(DateTime creationTimeUtc)
{
return this;
}

/// <inheritdoc/>
public IFile SetLastAccessTime(DateTime lastAccessTime)
{
return this;
}

/// <inheritdoc/>
public IFile SetLastAccessTimeUtc(DateTime lastAccessTimeUtc)
{
return this;
}

/// <inheritdoc/>
public IFile SetLastWriteTime(DateTime lastWriteTime)
{
return this;
}

/// <inheritdoc/>
public IFile SetLastWriteTimeUtc(DateTime lastWriteTimeUtc)
{
return this;
}
}
}
}