Open LinkForce opened 5 years ago
I could not reproduce using this test:
private void AlphaFS_DirectoryInfoTest(bool isNetwork)
{
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folderSrc = tempRoot.CreateRecursiveTree(5);
var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folderSrc.FullName);
Console.WriteLine("Input Directory Path: [{0}]", dirInfo.FullName);
Assert.IsFalse(System.IO.File.Exists(dirInfo.FullName));
Assert.IsTrue(System.IO.Directory.Exists(dirInfo.FullName));
dirInfo.Delete(true);
Assert.IsFalse(System.IO.Directory.Exists(dirInfo.FullName));
}
}
=== TEST LOCAL ===
Input Directory Path: [C:\Users\jjangli\AppData\Local\Temp\AlphaFS.TempRoot.ëkg15ëw2\Directory.f4s5sxbn]
=== TEST NETWORK ===
Input Directory Path: [\\DESKTOP-0A2DGD2\C$\Users\jjangli\AppData\Local\Temp\AlphaFS.TempRoot.üëïüwdvü\Directory.íttúdjyt]
The exception should also mention the path to the file, could you verify it is indeed a file?
Yes, it is definitely a Directory, and the directory is created by AlphaFS itself. My code is something like this:
var dir = new DirectoryInfo("C:\\Path\\to\\Directory");
if (dir.Exists)
dir.Delete(true);
dir.Create();
//doing some work, creating subdirectories and files inside that folder and creating a zip
Console.WriteLine("Deletando arquivos Físicos");
dir.Delete(true);
I rolled back my application to the AlphaFS version I was using before, 2.0.1, and the code now works again just fine.
I can't provide the actual code because it is proprietary code but any tests that you may want me to make and provide info I can gladly do for you.
Ok, could you try the following, to see if it makes any difference:
var dir = new DirectoryInfo("C:\\Path\\to\\Directory", Alphaleonis.Win32.Filesystem.PathFormat::FullPath);`
dir.Refresh();
dir.Delete(true, true);
Alphaleonis.Win32.Filesystem.Directory.Delete(dir.FullName, true);
Alphaleonis.Win32.Filesystem.Directory.Delete(dir.FullName, true, true);
Just to be sure, is the path mentioned in the exception the same path passed to the DirectoryInfo constructor? ("C:\Path\to\Directory") or one of the created sub directories?
Also, does it happen every time, or occasionally?
Yes, it is the same path mentioned. And the exception happens every time.
I think it's solved. Could you try branch 490 to see if it fixes the issue?
I could reproduce this issue with the following steps:
PS D:\> (New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo('D:\AlphaFsTest')).EnumerateFileSystemInfos()
Directory: D:\AlphaFsTest
Mode Inherits LastWriteTime Size(M) Name
---- -------- ------------- ------- ----
True 20.04.2021 23:39 0 $New Text Document.txt
PS D:\> (New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo('D:\')).EnumerateFileSystemInfos()
Directory: D:\
Mode Inherits LastWriteTime Size(M) Name
---- -------- ------------- ------- ----
True 19.12.2020 22:45 <DIR> $RECYCLE.BIN
True 20.04.2021 23:41 <DIR> AlphaFsTest
True 20.04.2021 23:14 <DIR> AutomatedLab-VMs
True 27.11.2020 09:12 <DIR> AutomatedLab.OSS
PS D:\> Move-Item '.\AlphaFsTest\$New Text Document.txt' -Destination d:\
PS D:\> (New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo('D:\')).EnumerateFileSystemInfos()
An error occurred while enumerating through a collection: (3) The target directory is a file, not a directory: [D:].
At line:1 char:1
+ (New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo('D:\')).Enumer ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Alphaleonis.Win...FileSystemInfo]:<Enumerate>d__84`1) [], RuntimeException
+ FullyQualifiedErrorId : BadEnumeration
After moving the file '$New Text Document.txt' to the root of drive D, I was no longer be able to read its content.
I have discovered the bug when working on raandree/NTFSSecurity#46.
@Yomodo, are you planning to release a new version with fixes or is AlphaFS abandoned?
I think it's already solved. I was able to reproduce it with 2.2.0 but not with 2.2.6 (current latest)
Trying to delete a folder gives me the exception on the title. Using 2.2.6 version downloaded from nuget.
Stack trace: