Ejemplo n.º 1
0
        public static void RemoveDirectory(string fullPath, bool recursive)
        {
            if (!recursive)
            {
                RemoveDirectoryInternal(fullPath, topLevel: true);
                return;
            }

            Interop.Kernel32.WIN32_FIND_DATA findData = default;
            // FindFirstFile($path) (used by GetFindData) fails with ACCESS_DENIED when user has no ListDirectory rights
            // but FindFirstFile($path/*") (used by RemoveDirectoryRecursive) works fine in such scenario.
            // So we ignore it here and let RemoveDirectoryRecursive throw if FindFirstFile($path/*") fails with ACCESS_DENIED.
            GetFindData(fullPath, isDirectory: true, ignoreAccessDenied: true, ref findData);
            if (IsNameSurrogateReparsePoint(ref findData))
            {
                // Don't recurse
                RemoveDirectoryInternal(fullPath, topLevel: true);
                return;
            }

            // We want extended syntax so we can delete "extended" subdirectories and files
            // (most notably ones with trailing whitespace or periods)
            fullPath = PathInternal.EnsureExtendedPrefix(fullPath);
            RemoveDirectoryRecursive(fullPath, ref findData, topLevel: true);
        }
Ejemplo n.º 2
0
        internal static bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
        {
            // We always want to add for CreateDirectory to get around the legacy 248 character limitation
            path = PathInternal.EnsureExtendedPrefix(path);

            return(CreateDirectoryPrivate(path, ref lpSecurityAttributes));
        }
    public void EnsureExtendedPrefixTest(string path, string expected)
    {
        StringBuilder sb = new StringBuilder(path);

        PathInternal.EnsureExtendedPrefix(sb);
        Assert.Equal(expected, sb.ToString());

        Assert.Equal(expected, PathInternal.EnsureExtendedPrefix(path));
    }
Ejemplo n.º 4
0
        internal static void CreateHardLink(string hardLinkFilePath, string targetFilePath)
        {
            string originalPath = hardLinkFilePath;

            hardLinkFilePath = PathInternal.EnsureExtendedPrefix(hardLinkFilePath);
            targetFilePath   = PathInternal.EnsureExtendedPrefix(targetFilePath);

            if (!CreateHardLinkPrivate(hardLinkFilePath, targetFilePath, IntPtr.Zero))
            {
                throw Win32Marshal.GetExceptionForLastWin32Error(originalPath);
            }
        }
Ejemplo n.º 5
0
        public static void GetFullPathName_Windows_RelativeRoot(string path, string expected)
        {
            StringBuilder sb     = new StringBuilder(256);
            int           result = global::Interop.mincore.GetFullPathName(path, sb.Capacity, sb);

            Assert.True(result > 0, "GetFullPathName should succeed");
            Assert.Equal(expected, sb.ToString());

            path   = PathInternal.EnsureExtendedPrefix(path);
            result = global::Interop.mincore.GetFullPathName(path, sb.Capacity, sb);
            Assert.True(result > 0, "GetFullPathName with extended syntax should succeed");
            Assert.Equal(PathInternal.EnsureExtendedPrefix(expected), sb.ToString());
        }
Ejemplo n.º 6
0
        public static void GetFullPathName_Windows_LongPathRoot()
        {
            // Long paths shouldn't recurse past the root
            string        path   = Path.Combine(@"C:\", new string('a', 255), new string('b', 255), "..", "..", "..");
            StringBuilder sb     = new StringBuilder(1024);
            int           result = global::Interop.mincore.GetFullPathName(path, sb.Capacity, sb);

            Assert.True(result > 0, "GetFullPathName should succeed");
            Assert.Equal(@"C:\", sb.ToString());

            path   = PathInternal.EnsureExtendedPrefix(path);
            result = global::Interop.mincore.GetFullPathName(path, sb.Capacity, sb);
            Assert.True(result > 0, "GetFullPathName should succeed");
            Assert.Equal(@"\\?\C:\", sb.ToString());
        }
Ejemplo n.º 7
0
        public static void RemoveDirectory(string fullPath, bool recursive)
        {
            if (!recursive)
            {
                RemoveDirectoryInternal(fullPath, topLevel: true);
                return;
            }

            Interop.Kernel32.WIN32_FIND_DATA findData = new Interop.Kernel32.WIN32_FIND_DATA();
            GetFindData(fullPath, ref findData);
            if (IsNameSurrogateReparsePoint(ref findData))
            {
                // Don't recurse
                RemoveDirectoryInternal(fullPath, topLevel: true);
                return;
            }

            // We want extended syntax so we can delete "extended" subdirectories and files
            // (most notably ones with trailing whitespace or periods)
            fullPath = PathInternal.EnsureExtendedPrefix(fullPath);
            RemoveDirectoryRecursive(fullPath, ref findData, topLevel: true);
        }
Ejemplo n.º 8
0
 public void EnsureExtendedPrefixTest(string path, string expected)
 {
     Assert.Equal(expected, PathInternal.EnsureExtendedPrefix(path));
 }