Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Fixes #474: Method Directory.EnumerateAlternateDataStreams should thr…
Browse files Browse the repository at this point in the history
…ow DirectoryNotFoundException.

Fixes #476: Method Directory.GetChangeTime should throw DirectoryNotFoundException.
  • Loading branch information
Yomodo committed Jul 12, 2018
1 parent 51c6c50 commit 4ea2011
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static partial class Directory
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams(string path)
{
return File.EnumerateAlternateDataStreamsCore(null, path, PathFormat.RelativePath);
return File.EnumerateAlternateDataStreamsCore(null, true, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified directory.</summary>
Expand All @@ -42,7 +42,7 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams(string path, PathFormat pathFormat)
{
return File.EnumerateAlternateDataStreamsCore(null, path, pathFormat);
return File.EnumerateAlternateDataStreamsCore(null, true, path, pathFormat);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified directory.</summary>
Expand All @@ -52,7 +52,7 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsTransacted(KernelTransaction transaction, string path)
{
return File.EnumerateAlternateDataStreamsCore(transaction, path, PathFormat.RelativePath);
return File.EnumerateAlternateDataStreamsCore(transaction, true, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified directory.</summary>
Expand All @@ -63,7 +63,7 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.EnumerateAlternateDataStreamsCore(transaction, path, pathFormat);
return File.EnumerateAlternateDataStreamsCore(transaction, true, path, pathFormat);
}
}
}
20 changes: 10 additions & 10 deletions AlphaFS/Filesystem/Directory Class/Directory.GetChangeTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static partial class Directory
[SecurityCritical]
public static DateTime GetChangeTime(string path)
{
return File.GetChangeTimeCore(null, null, path, false, PathFormat.RelativePath);
return File.GetChangeTimeCore(null, null, true, path, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time of the specified directory.</summary>
Expand All @@ -43,7 +43,7 @@ public static DateTime GetChangeTime(string path)
[SecurityCritical]
public static DateTime GetChangeTime(string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(null, null, path, false, pathFormat);
return File.GetChangeTimeCore(null, null, true, path, false, pathFormat);
}


Expand All @@ -54,7 +54,7 @@ public static DateTime GetChangeTime(string path, PathFormat pathFormat)
[SecurityCritical]
public static DateTime GetChangeTimeUtc(string path)
{
return File.GetChangeTimeCore(null, null, path, true, PathFormat.RelativePath);
return File.GetChangeTimeCore(null, null, true, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
Expand All @@ -64,7 +64,7 @@ public static DateTime GetChangeTimeUtc(string path)
[SecurityCritical]
public static DateTime GetChangeTimeUtc(string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(null, null, path, true, pathFormat);
return File.GetChangeTimeCore(null, null, true, path, true, pathFormat);
}


Expand All @@ -75,7 +75,7 @@ public static DateTime GetChangeTimeUtc(string path, PathFormat pathFormat)
[SecurityCritical]
public static DateTime GetChangeTime(SafeFileHandle safeFileHandle)
{
return File.GetChangeTimeCore(null, safeFileHandle, null, false, PathFormat.RelativePath);
return File.GetChangeTimeCore(null, safeFileHandle, true, null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
Expand All @@ -84,7 +84,7 @@ public static DateTime GetChangeTime(SafeFileHandle safeFileHandle)
[SecurityCritical]
public static DateTime GetChangeTimeUtc(SafeFileHandle safeFileHandle)
{
return File.GetChangeTimeCore(null, safeFileHandle, null, true, PathFormat.RelativePath);
return File.GetChangeTimeCore(null, safeFileHandle, true, null, true, PathFormat.RelativePath);
}

#region Transactional
Expand All @@ -96,7 +96,7 @@ public static DateTime GetChangeTimeUtc(SafeFileHandle safeFileHandle)
[SecurityCritical]
public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, string path)
{
return File.GetChangeTimeCore(transaction, null, path, false, PathFormat.RelativePath);
return File.GetChangeTimeCore(transaction, null, true, path, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time of the specified directory.</summary>
Expand All @@ -107,7 +107,7 @@ public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, st
[SecurityCritical]
public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(transaction, null, path, false, pathFormat);
return File.GetChangeTimeCore(transaction, null, true, path, false, pathFormat);
}


Expand All @@ -119,7 +119,7 @@ public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, st
[SecurityCritical]
public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction, string path)
{
return File.GetChangeTimeCore(transaction, null, path, true, PathFormat.RelativePath);
return File.GetChangeTimeCore(transaction, null, true, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
Expand All @@ -130,7 +130,7 @@ public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction,
[SecurityCritical]
public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(transaction, null, path, true, pathFormat);
return File.GetChangeTimeCore(transaction, null, true, path, true, pathFormat);
}

#endregion // Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed partial class DirectoryInfo
[SecurityCritical]
public IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams()
{
return File.EnumerateAlternateDataStreamsCore(Transaction, LongFullName, PathFormat.LongFullPath);
return File.EnumerateAlternateDataStreamsCore(Transaction, true, LongFullName, PathFormat.LongFullPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static partial class File
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams(string path)
{
return EnumerateAlternateDataStreamsCore(null, path, PathFormat.RelativePath);
return EnumerateAlternateDataStreamsCore(null, false, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified file.</summary>
Expand All @@ -43,7 +43,7 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams(string path, PathFormat pathFormat)
{
return EnumerateAlternateDataStreamsCore(null, path, pathFormat);
return EnumerateAlternateDataStreamsCore(null, false, path, pathFormat);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified file.</summary>
Expand All @@ -53,7 +53,7 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsTransacted(KernelTransaction transaction, string path)
{
return EnumerateAlternateDataStreamsCore(transaction, path, PathFormat.RelativePath);
return EnumerateAlternateDataStreamsCore(transaction, false, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified file.</summary>
Expand All @@ -64,7 +64,7 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return EnumerateAlternateDataStreamsCore(transaction, path, pathFormat);
return EnumerateAlternateDataStreamsCore(transaction, false, path, pathFormat);
}


Expand All @@ -74,10 +74,11 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified file or directory.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="isFolder">When <c>true</c> indicates the source is a directory; file otherwise.</param>
/// <param name="path">The path to the file or directory to enumerate streams of.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <returns>The streams of type :$DATA in the specified file or directory.</returns>
internal static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsCore(KernelTransaction transaction, string path, PathFormat pathFormat)
internal static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsCore(KernelTransaction transaction, bool isFolder, string path, PathFormat pathFormat)
{
using (var buffer = new SafeGlobalMemoryBufferHandle(Marshal.SizeOf(typeof(NativeMethods.WIN32_FIND_STREAM_DATA))))
{
Expand Down Expand Up @@ -116,7 +117,7 @@ internal static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStrea
if (lastError == Win32Errors.ERROR_HANDLE_EOF)
break;

NativeError.ThrowException(lastError, pathLp);
NativeError.ThrowException(lastError, isFolder, pathLp);
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions AlphaFS/Filesystem/File Class/File.GetChangeTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static partial class File
[SecurityCritical]
public static DateTime GetChangeTime(string path, PathFormat pathFormat)
{
return GetChangeTimeCore(null, null, path, false, pathFormat);
return GetChangeTimeCore(null, null, false, path, false, pathFormat);
}


Expand All @@ -53,7 +53,7 @@ public static DateTime GetChangeTime(string path, PathFormat pathFormat)
[SecurityCritical]
public static DateTime GetChangeTime(string path)
{
return GetChangeTimeCore(null, null, path, false, PathFormat.RelativePath);
return GetChangeTimeCore(null, null, false, path, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time of the specified file.</summary>
Expand All @@ -63,7 +63,7 @@ public static DateTime GetChangeTime(string path)
[SecurityCritical]
public static DateTime GetChangeTime(SafeFileHandle safeFileHandle)
{
return GetChangeTimeCore(null, safeFileHandle, null, false, PathFormat.LongFullPath);
return GetChangeTimeCore(null, safeFileHandle, false, null, false, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Gets the change date and time of the specified file.</summary>
Expand All @@ -75,7 +75,7 @@ public static DateTime GetChangeTime(SafeFileHandle safeFileHandle)
[SecurityCritical]
public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return GetChangeTimeCore(transaction, null, path, false, pathFormat);
return GetChangeTimeCore(transaction, null, false, path, false, pathFormat);
}

/// <summary>[AlphaFS] Gets the change date and time of the specified file.</summary>
Expand All @@ -86,7 +86,7 @@ public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, st
[SecurityCritical]
public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, string path)
{
return GetChangeTimeCore(transaction, null, path, false, PathFormat.RelativePath);
return GetChangeTimeCore(transaction, null, false, path, false, PathFormat.RelativePath);
}

#endregion // GetChangeTime
Expand All @@ -102,7 +102,7 @@ public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, st
[SecurityCritical]
public static DateTime GetChangeTimeUtc(string path, PathFormat pathFormat)
{
return GetChangeTimeCore(null, null, path, true, pathFormat);
return GetChangeTimeCore(null, null, false, path, true, pathFormat);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified file.</summary>
Expand All @@ -112,7 +112,7 @@ public static DateTime GetChangeTimeUtc(string path, PathFormat pathFormat)
[SecurityCritical]
public static DateTime GetChangeTimeUtc(string path)
{
return GetChangeTimeCore(null, null, path, true, PathFormat.RelativePath);
return GetChangeTimeCore(null, null, false, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified file.</summary>
Expand All @@ -122,7 +122,7 @@ public static DateTime GetChangeTimeUtc(string path)
[SecurityCritical]
public static DateTime GetChangeTimeUtc(SafeFileHandle safeFileHandle)
{
return GetChangeTimeCore(null, safeFileHandle, null, true, PathFormat.LongFullPath);
return GetChangeTimeCore(null, safeFileHandle, false, null, true, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified file.</summary>
Expand All @@ -134,7 +134,7 @@ public static DateTime GetChangeTimeUtc(SafeFileHandle safeFileHandle)
[SecurityCritical]
public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return GetChangeTimeCore(transaction, null, path, true, pathFormat);
return GetChangeTimeCore(transaction, null, false, path, true, pathFormat);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified file.</summary>
Expand All @@ -145,7 +145,7 @@ public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction,
[SecurityCritical]
public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction, string path)
{
return GetChangeTimeCore(transaction, null, path, true, PathFormat.RelativePath);
return GetChangeTimeCore(transaction, null, false, path, true, PathFormat.RelativePath);
}

#endregion // GetChangeTimeUtc
Expand All @@ -161,12 +161,13 @@ public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction,
/// <exception cref="PlatformNotSupportedException">The operating system is older than Windows Vista.</exception>
/// <param name="transaction">The transaction.</param>
/// <param name="safeFileHandle">An open handle to the file or directory from which to retrieve information.</param>
/// <param name="isFolder">Specifies that <paramref name="path"/> is a file or directory.</param>
/// <param name="path">The file or directory for which to obtain creation date and time information.</param>
/// <param name="getUtc"><c>true</c> gets the Coordinated Universal Time (UTC), <c>false</c> gets the local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Disposing is controlled.")]
[SecurityCritical]
internal static DateTime GetChangeTimeCore(KernelTransaction transaction, SafeFileHandle safeFileHandle, string path, bool getUtc, PathFormat pathFormat)
internal static DateTime GetChangeTimeCore(KernelTransaction transaction, SafeFileHandle safeFileHandle, bool isFolder, string path, bool getUtc, PathFormat pathFormat)
{
if (!NativeMethods.IsAtLeastWindowsVista)
throw new PlatformNotSupportedException(new Win32Exception((int) Win32Errors.ERROR_OLD_WIN_VERSION).Message);
Expand All @@ -180,7 +181,7 @@ internal static DateTime GetChangeTimeCore(KernelTransaction transaction, SafeFi

var pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars);

safeFileHandle = CreateFileCore(transaction, false, pathLp, ExtendedFileAttributes.BackupSemantics, null, FileMode.Open, FileSystemRights.ReadData, FileShare.ReadWrite, true, false, PathFormat.LongFullPath);
safeFileHandle = CreateFileCore(transaction, isFolder, pathLp, ExtendedFileAttributes.BackupSemantics, null, FileMode.Open, FileSystemRights.ReadData, FileShare.ReadWrite, true, false, PathFormat.LongFullPath);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ partial class FileInfo
[SecurityCritical]
public IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams()
{
return File.EnumerateAlternateDataStreamsCore(Transaction, LongFullName, PathFormat.LongFullPath);
return File.EnumerateAlternateDataStreamsCore(Transaction, false, LongFullName, PathFormat.LongFullPath);
}
}
}
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Changelog
=========

Version 2.2.4 (2018-XX-XX)
Version 2.2.4 (2018-07-12)
-------------

### Bugs Fixed

- Issue #468: Method `Directory.CopyTimestamps` should throw `DirectoryNotFoundException`.
- Issue #469: Method `Directory.GetFileIdInfo` should throw `DirectoryNotFoundException`.
- Issue #474: Method `Directory.EnumerateAlternateDataStreams` should throw `DirectoryNotFoundException`.
- Issue #476: Method `Directory.GetChangeTime` should throw `DirectoryNotFoundException`.


Version 2.2.3 (2018-06-14)
Expand Down

0 comments on commit 4ea2011

Please sign in to comment.