Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to recurisly delete folder #270

Open
Jimmy062006 opened this issue Jan 27, 2023 · 7 comments
Open

Unable to recurisly delete folder #270

Jimmy062006 opened this issue Jan 27, 2023 · 7 comments

Comments

@Jimmy062006
Copy link

Jimmy062006 commented Jan 27, 2023

The below code seems to generate a folder not empty Exception but I'm unsure why.

Would you have any idea's for me to try.

try
{
    var info = vhdbNtfs.GetDirectoryInfo("AppData\\Local");
    if (info != null)
    {
        var dirs = info.GetDirectories();
        foreach (var dir in dirs)
        {
            dir.Delete(true);
        }
    }
}
catch(Exception ex)
{
    var error = ex;
}

Unable to delete non-empty directory

My understanding is that Delete(true) should recursively delete all folders/files.

@LTRData
Copy link

LTRData commented Jan 27, 2023

Yes that is how it is supposed to work. There seems to be something strange happening when you try to delete that directory and I can replicate the same issue here as well for that directory. I'll take a look and see what I can find.

@Jimmy062006
Copy link
Author

I may have tracked it down to no permissions to delete certain things in the folder.

However this is a new lib to me so I just want to check that my thought train might be correct for it.

I guess its forced to obey the NTFS permission flags ? My guess is it's really getting an access denied but that is not caught ?

@LTRData
Copy link

LTRData commented Jan 27, 2023

No, it has nothing to do with permissions. Permissions are entirely ignored by this library. It rather seems to be related to some index cache bugs somewhere.

@LTRData
Copy link

LTRData commented Jan 27, 2023

No, sorry. You were right. I see now that DiscDirectoryInfo.Delete(recursive: true) fails to find hidden files and delete them, which causes this error. This behavior can be changed by setting HideHiddenFiles = false and HideSystemFiles = false on the NtfsFileSystem.NtfsOptions object. However, I still consider this a bug because those settings are ment to affect things like file/directory enumerations, a recursive directory delete operation should ignore these settings.

@Jimmy062006
Copy link
Author

OK, so until that is patched I could just set HideHiddenFiles = false and HideSystemFiles = false for the folders that I am about to delete?

@LTRData
Copy link

LTRData commented Jan 27, 2023

Yes. That seems to work.

@Jimmy062006
Copy link
Author

I can confirm that resolves my issue but will leave this open for you to deal with :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants