internal static new IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, FileBasicInfo info, IFileService fileService)
        {
            if ((info.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == 0) throw new ArgumentOutOfRangeException(nameof(info));

            var directoryInfo = new DirectoryInformation(fileService);
            directoryInfo.PopulateData(originalPath, fileHandle, info);
            return directoryInfo;
        }
        internal static new IFileSystemInformation Create(FindResult findResult, string directory, IFileService fileService)
        {
            if ((findResult.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == 0) throw new ArgumentOutOfRangeException(nameof(findResult));

            var directoryInfo = new DirectoryInformation(fileService);
            directoryInfo.PopulateData(findResult, directory);
            return directoryInfo;
        }
Example #3
0
        internal static new IFileSystemInformation Create(NativeMethods.FileManagement.FindResult findResult, IFileService fileService)
        {
            if ((findResult.Attributes & System.IO.FileAttributes.Directory) == 0) throw new ArgumentOutOfRangeException(nameof(findResult));

            var directoryInfo = new DirectoryInformation(fileService);
            directoryInfo.PopulateData(findResult);
            return directoryInfo;
        }
Example #4
0
        internal static new IFileSystemInformation Create(string path, System.IO.FileAttributes attributes, IFileService fileService)
        {
            if ((attributes & System.IO.FileAttributes.Directory) == 0) throw new ArgumentOutOfRangeException(nameof(attributes));

            var directoryInfo = new DirectoryInformation(fileService);
            directoryInfo.PopulateData(path, attributes);
            return directoryInfo;
        }
Example #5
0
        internal static new IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info, IFileService fileService)
        {
            if ((info.dwFileAttributes & System.IO.FileAttributes.Directory) == 0) throw new ArgumentOutOfRangeException(nameof(info));

            var directoryInfo = new DirectoryInformation(fileService);
            directoryInfo.PopulateData(originalPath, fileHandle, info);
            return directoryInfo;
        }
Example #6
0
        internal static new IFileSystemInformation Create(string path, System.IO.FileAttributes attributes, IFileService fileService)
        {
            if (!attributes.HasFlag(System.IO.FileAttributes.Directory)) throw new ArgumentOutOfRangeException(nameof(attributes));

            var info = new DirectoryInformation(fileService);
            info.PopulateData(path, attributes);
            info.fromAttributes = true;

            return info;
        }
 internal static IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, FileBasicInformation info, IFileService fileService)
 {
     if ((info.FileAttributes & FileAttributes.Directory) != 0)
     {
         return(DirectoryInformation.Create(originalPath, fileHandle, info, fileService));
     }
     else
     {
         return(FileInformation.Create(originalPath, fileHandle, info, fileService));
     }
 }
 internal static IFileSystemInformation Create(ref RawFindData findData, IFileService fileService)
 {
     if ((findData.FileAttributes & FileAttributes.Directory) != 0)
     {
         return(DirectoryInformation.Create(ref findData, fileService));
     }
     else
     {
         return(FileInformation.Create(ref findData, fileService));
     }
 }
Example #9
0
 internal static IFileSystemInformation Create(NativeMethods.FileManagement.FindResult findResult, IFileService fileService)
 {
     if ((findResult.Attributes & System.IO.FileAttributes.Directory) != 0)
     {
         return(DirectoryInformation.Create(findResult, fileService));
     }
     else
     {
         return(FileInformation.Create(findResult, fileService));
     }
 }
Example #10
0
 internal static IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info, IFileService fileService)
 {
     if ((info.dwFileAttributes & System.IO.FileAttributes.Directory) != 0)
     {
         return(DirectoryInformation.Create(originalPath, fileHandle, info, fileService));
     }
     else
     {
         return(FileInformation.Create(originalPath, fileHandle, info, fileService));
     }
 }
Example #11
0
        new static internal IFileSystemInformation Create(string path, System.IO.FileAttributes attributes, IFileService fileService)
        {
            if ((attributes & System.IO.FileAttributes.Directory) == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(attributes));
            }

            var directoryInfo = new DirectoryInformation(fileService);

            directoryInfo.PopulateData(path, attributes);
            return(directoryInfo);
        }
Example #12
0
        new static internal IFileSystemInformation Create(ref RawFindData findData, IFileService fileService)
        {
            if ((findData.FileAttributes & FileAttributes.Directory) == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(findData));
            }

            var directoryInfo = new DirectoryInformation(fileService);

            directoryInfo.PopulateData(ref findData);
            return(directoryInfo);
        }
Example #13
0
        new internal static IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, FileBasicInformation info, IFileService fileService)
        {
            if ((info.FileAttributes & FileAttributes.Directory) == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(info));
            }

            var directoryInfo = new DirectoryInformation(fileService);

            directoryInfo.PopulateData(originalPath, fileHandle, info);
            return(directoryInfo);
        }
 internal static IFileSystemInformation Create(string path, System.IO.FileAttributes attributes, IFileService fileService)
 {
     if (attributes.HasFlag(System.IO.FileAttributes.Directory))
     {
         return(DirectoryInformation.Create(path, attributes, fileService));
     }
     else
     {
         // Should only be using attributes for root directories
         throw new InvalidOperationException();
     }
 }
Example #15
0
        new static internal IFileSystemInformation Create(NativeMethods.FileManagement.FindResult findResult, IFileService fileService)
        {
            if ((findResult.Attributes & System.IO.FileAttributes.Directory) == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(findResult));
            }

            var directoryInfo = new DirectoryInformation(fileService);

            directoryInfo.PopulateData(findResult);
            return(directoryInfo);
        }
Example #16
0
        new internal static IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info, IFileService fileService)
        {
            if ((info.dwFileAttributes & System.IO.FileAttributes.Directory) == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(info));
            }

            var directoryInfo = new DirectoryInformation(fileService);

            directoryInfo.PopulateData(originalPath, fileHandle, info);
            return(directoryInfo);
        }
Example #17
0
        private void DeleteDirectoryRecursive(string path)
        {
            var info = Storage.TryGetFileInfo(path);

            if (!info.HasValue)
            {
                // Nothing found
                WindowsError.ERROR_PATH_NOT_FOUND.GetException(path);
            }

            if ((info.Value.FileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
            {
                // Not a directory, a file
                throw WindowsError.ERROR_FILE_EXISTS.GetException(path);
            }

            //if (attributes.HasFlag(FileAttributes.ReadOnly))
            //{
            //    // Make it writable
            //    NativeMethods.FileManagement.SetFileAttributes(path, attributes & ~FileAttributes.ReadOnly);
            //}

            if ((info.Value.FileAttributes & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
            {
                // Remove the subdirectories and files
                // Reparse points are simply disconnected, they don't need to be emptied.
                foreach (var file in DirectoryInformation.EnumerateChildrenInternal(
                             directory: path,
                             childType: ChildType.File,
                             searchPattern: "*",
                             searchOption: System.IO.SearchOption.TopDirectoryOnly,
                             excludeAttributes: 0,
                             fileService: this))
                {
                    DeleteFile(file.Path);
                }

                foreach (var directory in DirectoryInformation.EnumerateChildrenInternal(
                             directory: path,
                             childType: ChildType.Directory,
                             searchPattern: "*",
                             searchOption: System.IO.SearchOption.TopDirectoryOnly,
                             excludeAttributes: 0,
                             fileService: this))
                {
                    DeleteDirectoryRecursive(directory.Path);
                }
            }

            // We've either emptied or we're a reparse point, delete the directory
            Storage.RemoveDirectory(path);
        }
Example #18
0
        internal static IEnumerable <IFileSystemInformation> EnumerateChildrenInternal(
            string directory,
            ChildType childType,
            string searchPattern,
            System.IO.SearchOption searchOption,
            System.IO.FileAttributes excludeAttributes,
            IFileService fileService)
        {
            var firstFile = NativeMethods.FileManagement.FindFirstFile(Paths.Combine(directory, searchPattern));
            var findInfo  = firstFile;

            if (firstFile != null)
            {
                // Look for specified file/directories
                do
                {
                    bool isDirectory = findInfo.Attributes.HasFlag(System.IO.FileAttributes.Directory);

                    if ((findInfo.Attributes & excludeAttributes) == 0 &&
                        findInfo.FileName != "." &&
                        findInfo.FileName != ".." &&
                        ((isDirectory && childType == ChildType.Directory) ||
                         (!isDirectory && childType == ChildType.File)))
                    {
                        yield return(FileSystemInformation.Create(findInfo, fileService));
                    }

                    findInfo = NativeMethods.FileManagement.FindNextFile(firstFile);
                } while (findInfo != null);

                firstFile.FindHandle.Close();
            }

            if (searchOption != System.IO.SearchOption.AllDirectories)
            {
                yield break;
            }

            // Need to recurse to find additional matches
            firstFile = NativeMethods.FileManagement.FindFirstFile(Paths.Combine(directory, "*"), directoriesOnly: true);
            if (firstFile == null)
            {
                yield break;
            }
            findInfo = firstFile;

            do
            {
                if ((findInfo.Attributes & excludeAttributes) == 0 &&
                    findInfo.Attributes.HasFlag(System.IO.FileAttributes.Directory) &&
                    findInfo.FileName != "." &&
                    findInfo.FileName != "..")
                {
                    IFileSystemInformation childDirectory = DirectoryInformation.Create(findInfo, fileService);
                    foreach (var child in EnumerateChildrenInternal(childDirectory.Path, childType, searchPattern, searchOption, excludeAttributes, fileService))
                    {
                        yield return(child);
                    }
                }
                findInfo = NativeMethods.FileManagement.FindNextFile(firstFile);
            } while (findInfo != null);

            firstFile.FindHandle.Close();
        }