示例#1
0
        private string[] GetDirectoriesOutsideSparse(string rootPath, HashSet <string> sparseFolders)
        {
            PhysicalFileSystem fileSystem         = new PhysicalFileSystem();
            Queue <string>     foldersToEnumerate = new Queue <string>();

            foldersToEnumerate.Enqueue(rootPath);

            List <string> foldersOutsideSparse = new List <string>();

            while (foldersToEnumerate.Count > 0)
            {
                string folderToEnumerate = foldersToEnumerate.Dequeue();
                foreach (string directory in fileSystem.EnumerateDirectories(folderToEnumerate))
                {
                    string enlistmentRootRelativeFolderPath = GVFSDatabase.NormalizePath(directory.Substring(rootPath.Length));
                    if (sparseFolders.Any(x => x.StartsWith(enlistmentRootRelativeFolderPath + Path.DirectorySeparatorChar, GVFSPlatform.Instance.Constants.PathComparison)))
                    {
                        foldersToEnumerate.Enqueue(directory);
                    }
                    else if (!sparseFolders.Contains(enlistmentRootRelativeFolderPath))
                    {
                        foldersOutsideSparse.Add(enlistmentRootRelativeFolderPath);
                    }
                }
            }

            return(foldersOutsideSparse.ToArray());
        }
        private static IEnumerable <string> GetFolderPlaceholdersFromDisk(ITracer tracer, PhysicalFileSystem fileSystem, string path)
        {
            if (!fileSystem.IsSymLink(path))
            {
                foreach (string directory in fileSystem.EnumerateDirectories(path))
                {
                    if (!directory.EndsWith(Path.DirectorySeparatorChar + GVFSConstants.DotGit.Root))
                    {
                        OnDiskFileState fileState = OnDiskFileState.Full;
                        if (Utils.TryGetOnDiskFileState(directory, out fileState))
                        {
                            if (IsPlaceholder(fileState))
                            {
                                yield return(directory);
                            }

                            // Recurse into placeholders and full folders skipping the tombstones
                            if (!IsTombstone(fileState))
                            {
                                foreach (string placeholderPath in GetFolderPlaceholdersFromDisk(tracer, fileSystem, directory))
                                {
                                    yield return(placeholderPath);
                                }
                            }
                        }
                        else
                        {
                            // May cause valid folder placeholders not to be written
                            // to the placeholder database so we want to error out.
                            throw new InvalidDataException($"Error getting on disk file state for {directory}");
                        }
                    }
                }
            }
        }
示例#3
0
        public void TestDirectoryExceptions()
        {
            var fs = new PhysicalFileSystem();

            // Try to create a folder on an unauthorized location
            fs.CreateDirectory("/");
            Assert.Throws <UnauthorizedAccessException>(() => fs.CreateDirectory("/mnt2"));
            Assert.Throws <UnauthorizedAccessException>(() => fs.CreateDirectory("/mnt"));
            Assert.Throws <UnauthorizedAccessException>(() => fs.CreateDirectory("/mnt/yoyo"));
            Assert.Throws <UnauthorizedAccessException>(() => fs.CreateDirectory("/mnt/c"));

            var drives = fs.EnumerateDirectories("/mnt").ToList();

            Assert.True(drives.Count > 0);

            Assert.Throws <UnauthorizedAccessException>(() => fs.MoveDirectory("/", drives[0] / "ShouldNotHappen"));
            Assert.Throws <UnauthorizedAccessException>(() => fs.MoveDirectory("/mnt", drives[0] / "ShouldNotHappen"));
            Assert.Throws <DirectoryNotFoundException>(() => fs.MoveDirectory("/mnt2", drives[0] / "ShouldNotHappen"));

            Assert.Throws <UnauthorizedAccessException>(() => fs.MoveDirectory(drives[0] / "ShouldNotHappen", "/"));
            Assert.Throws <UnauthorizedAccessException>(() => fs.MoveDirectory(drives[0] / "ShouldNotHappen", "/mnt"));
            Assert.Throws <DirectoryNotFoundException>(() => fs.MoveDirectory(drives[0] / "ShouldNotHappen", "/mnt2"));

            Assert.Throws <UnauthorizedAccessException>(() => fs.DeleteDirectory("/", false));
            Assert.Throws <UnauthorizedAccessException>(() => fs.DeleteDirectory("/mnt", false));
            Assert.Throws <DirectoryNotFoundException>(() => fs.DeleteDirectory("/mnt2", false));
            Assert.Throws <DirectoryNotFoundException>(() => fs.DeleteDirectory("/mnt/yoyo", false));
        }
        private static IEnumerable <string> GetFolderPlaceholdersFromDisk(ITracer tracer, PhysicalFileSystem fileSystem, string path)
        {
            foreach (string directory in fileSystem.EnumerateDirectories(path))
            {
                if (!directory.EndsWith(GVFSConstants.PathSeparatorString + GVFSConstants.DotGit.Root))
                {
                    OnDiskFileState fileState = OnDiskFileState.Full;
                    HResult         result    = Utils.GetOnDiskFileState(directory, ref fileState);
                    if (result == HResult.Ok)
                    {
                        if (IsPlaceholder(fileState))
                        {
                            yield return(directory);
                        }

                        // Recurse into placeholders and full folders skipping the tombstones
                        if (!IsTombstone(fileState))
                        {
                            foreach (string placeholderPath in GetFolderPlaceholdersFromDisk(tracer, fileSystem, directory))
                            {
                                yield return(placeholderPath);
                            }
                        }
                    }
                    else if (result != HResult.FileNotFound)
                    {
                        // FileNotFound is returned for tombstones when the filter is attached to the volume so we want to
                        // just skip those folders.  Any other HResults may cause valid folder placeholders not to be written
                        // to the placeholder database so we want to error out on those.
                        throw new InvalidDataException($"Error getting on disk file state. HResult = {result} for {directory}");
                    }
                }
            }
        }
示例#5
0
        public void TestDirectorySpecial()
        {
            var fs = new PhysicalFileSystem();

            // CreateDirectory
            Assert.True(fs.DirectoryExists("/"));
            if (IsWindows)
            {
                var directories = fs.EnumerateDirectories("/").ToList();
                Assert.Equal(new List <UPath>()
                {
                    "/mnt"
                }, directories);

                var drives = fs.EnumerateDirectories("/mnt").ToList();
                Assert.True(drives.Count > 0);

                var allDrives  = DriveInfo.GetDrives().Select(d => d.Name[0].ToString().ToLowerInvariant()).ToList();
                var driveNames = drives.Select(d => d.GetName()).ToList();
                Assert.Equal(allDrives, driveNames);

                Assert.True(fs.DirectoryExists("/"));
                Assert.True(fs.DirectoryExists("/mnt"));
                Assert.True(fs.DirectoryExists(drives[0]));

                var files = fs.EnumerateFiles("/").ToList();
                Assert.True(files.Count == 0);

                files = fs.EnumerateFiles("/mnt").ToList();
                Assert.True(files.Count == 0);

                var paths = fs.EnumeratePaths("/").ToList();
                Assert.Equal(new List <UPath>()
                {
                    "/mnt"
                }, paths);
            }
        }
示例#6
0
        public void TestEnumerate()
        {
            var fs   = new PhysicalFileSystem();
            var path = fs.ConvertPathFromInternal(SystemPath);

            var files         = fs.EnumerateFiles(path).Select(p => fs.ConvertPathToInternal(p)).ToList();
            var expectedfiles = Directory.EnumerateFiles(SystemPath).ToList();

            Assert.Equal(expectedfiles, files);

            var dirs         = fs.EnumerateDirectories(path / "../../..").Select(p => fs.ConvertPathToInternal(p)).ToList();
            var expecteddirs = Directory.EnumerateDirectories(Path.GetFullPath(Path.Combine(SystemPath, "..\\..\\.."))).ToList();

            Assert.Equal(expecteddirs, dirs);

            var paths         = fs.EnumeratePaths(path / "../..").Select(p => fs.ConvertPathToInternal(p)).ToList();
            var expectedPaths = Directory.EnumerateFileSystemEntries(Path.GetFullPath(Path.Combine(SystemPath, "..\\.."))).ToList();

            Assert.Equal(expectedPaths, paths);
        }