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

Commit

Permalink
Merge branch '#441'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomodo committed Jun 1, 2018
2 parents 5ce5c3a + d1dcbd2 commit 5261395
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,23 @@ public void AlphaFS_Directory_GetFileSystemEntryInfo_LocalAndNetwork_Success()

private void AlphaFS_Directory_GetFileSystemEntryInfo(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folder = tempRoot.CreateDirectoryRandomizedAttributes();

var tempPath = Environment.SystemDirectory;
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

Console.WriteLine("Input Directory Path: [{0}]", tempPath);
var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(folder.FullName);

UnitTestConstants.Dump(fsei, -19);

var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath);

UnitTestConstants.Dump(fsei, -19);
Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));

Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Directory) != 0, "The Directory attribute is not found, but is expected.");

Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));

Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Directory) != 0, "The Directory attribute is not found, but is expected.");

Assert.AreEqual(tempPath, fsei.FullPath, "The paths are not equal, but are expected to be.");

Assert.AreEqual(folder.FullName, fsei.FullPath, "The paths are not equal, but are expected to be.");
}

Console.WriteLine();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,15 @@ public void AlphaFS_Directory_GetFileSystemEntryInfo_ThrowDirectoryNotFoundExcep

private void AlphaFS_Directory_GetFileSystemEntryInfo_ThrowDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(bool isNetwork)
{
var path = System.IO.Path.Combine(Environment.SystemDirectory, "notepad.exe");
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folder = tempRoot.CreateFileRandomizedAttributes();

if (!System.IO.File.Exists(path))
UnitTestAssert.InconclusiveBecauseFileNotFound(path);
Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

UnitTestAssert.ThrowsException<System.IO.DirectoryNotFoundException>(() => Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(folder.FullName));
}

UnitTestConstants.PrintUnitTestHeader(isNetwork);

var tempPath = path;
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);

Console.WriteLine("Input Directory Path: [{0}]", tempPath);

UnitTestAssert.ThrowsException<System.IO.DirectoryNotFoundException>(() => Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath));

Console.WriteLine();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,23 @@ public void AlphaFS_File_GetFileSystemEntryInfo_LocalAndNetwork_Success()

private void AlphaFS_File_GetFileSystemEntryInfo(bool isNetwork)
{
var path = System.IO.Path.Combine(Environment.SystemDirectory, "notepad.exe");
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var file = tempRoot.CreateFileRandomizedAttributes();

if (!System.IO.File.Exists(path))
UnitTestAssert.InconclusiveBecauseFileNotFound(path);
Console.WriteLine("Input File Path: [{0}]", file.FullName);

var fsei = Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(file.FullName);

UnitTestConstants.PrintUnitTestHeader(isNetwork);
UnitTestConstants.Dump(fsei, -19);

var tempPath = path;
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));

Console.WriteLine("Input File Path: [{0}]", tempPath);
Assert.IsTrue(fsei.Attributes != System.IO.FileAttributes.Directory, "The directory attribute is found, but is not expected.");

Assert.AreEqual(file.FullName, fsei.FullPath, "The paths are not equal, but are expected to be.");
}

var fsei = Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(tempPath);
UnitTestConstants.Dump(fsei, -19);

Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));
Assert.IsTrue(fsei.Attributes != System.IO.FileAttributes.Directory, "The directory attribute is found, but is not expected.");
Assert.AreEqual(tempPath, fsei.FullPath, "The paths are not equal, but are expected to be.");

Console.WriteLine();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ public void AlphaFS_File_GetFileSystemEntryInfo_ThrowFileNotFoundException_Direc

private void AlphaFS_File_GetFileSystemEntryInfo_ThrowFileNotFoundException_DirectoryExistsWithSameNameAsFile(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folder = tempRoot.CreateDirectoryRandomizedAttributes();

var tempPath = Environment.SystemDirectory;
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);

Console.WriteLine("Input File Path: [{0}]", tempPath);
Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

UnitTestAssert.ThrowsException<System.IO.FileNotFoundException>(() => Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(tempPath));
UnitTestAssert.ThrowsException<System.IO.FileNotFoundException>(() => Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(folder.FullName));
}

Console.WriteLine();
}
Expand Down
18 changes: 10 additions & 8 deletions AlphaFS/Filesystem/FindFileSystemEntryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ private SafeFindFileHandle FindFirstFile(string pathLp, out NativeMethods.WIN32_
ThrowPossibleException((uint) lastError, pathLp);
}

// When the handle is null and we are still here, it means the ErrorHandler is active, preventing the Exception from being thrown.
//// When the handle is null and we are still here, it means the ErrorHandler is active, preventing the Exception from being thrown.

if (null != handle)
VerifyInstanceType(win32FindData);
//if (null != handle)
// VerifyInstanceType(win32FindData);
}


Expand All @@ -313,8 +313,6 @@ private FileSystemEntryInfo NewFilesystemEntry(string pathLp, string fileName, N
var fullPath = (IsRelativePath ? pathLp.Replace(RelativeAbsolutePrefix, string.Empty) : pathLp) + fileName;

return new FileSystemEntryInfo(win32FindData) {FullPath = fullPath};

//return new FileSystemEntryInfo(win32FindData) {FullPath = (IsRelativePath ? OriginalInputPath + Path.DirectorySeparator : pathLp) + fileName};
}


Expand Down Expand Up @@ -546,12 +544,16 @@ public T Get<T>()
if (!IsDirectory)
{
using (var handle = FindFirstFile(InputPath, out win32FindData))
{
if (null != handle)
VerifyInstanceType(win32FindData);

return null == handle
else
return (T) (object) null;

? (T) (object) null

: NewFileSystemEntryType<T>((win32FindData.dwFileAttributes & FileAttributes.Directory) != 0, null, null, InputPath, win32FindData);
return NewFileSystemEntryType<T>((win32FindData.dwFileAttributes & FileAttributes.Directory) != 0, null, null, InputPath, win32FindData);
}

}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Version 2.2.2 (2018-XX-XX)
- Issue #436: `Directory.GetFiles()` with relative path (Thx stellarbear)
- Issue #437: Fixed `PathTooLongException` for boundary case of directory name length in `Path.NormalizePath` (Thx okrushelnitsky)
- Issue #444: Exception when moving or renaming a folder after updating from 2.1.3 to 2.2.1 (Thx mlaily)
- Issue #441: `InvalidOperationException` on `Directory.EnumerateFileSystemEntries()`

### Improvements

Expand Down

0 comments on commit 5261395

Please sign in to comment.