peteraritchie / LongPath

drop-in library to support long paths in .NET
GNU Lesser General Public License v3.0
112 stars 43 forks source link

Error: Trying to create a parent directory, which exists but the current user has no permissions. #94

Closed panos-konstantellos closed 1 year ago

panos-konstantellos commented 1 year ago

Given the already existing path D:/git/projects/repo_name/source/project_name/uploads/ with the following permissions:

and executing the Pri.LongPath.Directory.CreateDirectory("D:\git\projects\repo_name\Source\project_name\Uploads\folder_to_create\"); in an app hosted in IIS, running as the IIS_POOL_USER the pathComponents list contains folders that do exist but the IIS_POOL_USER has no permissions. image image

In the following code: https://github.com/peteraritchie/LongPath/blob/6133dc9ca935127e1663fef27a52717e4174db3d/Pri.LongPath/Directory.cs#L840-L867

I propose that lines 847 & 848 should be altered like this:


                    if (Exists(subPath))
                    {
                        break; // If a subfolder exists then there's no need to check for parent folders
                    }
                    else
                    {
                        pathComponents.Add(Path.NormalizeLongPath(subPath));
                    }
peteraritchie commented 1 year ago

Good find, and thanks for the included PR!