Beispiel #1
0
        public void GetDirectoryRoot_WithRelativePath_ReturnsCurrentDirRoot()
        {
            var originalDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(@"C:\Windows\");
            var root = Directory.GetDirectoryRoot(@"\Windows");

            Assert.That(root, Is.EqualTo(@"C:\"));
            Directory.SetCurrentDirectory(originalDir);
        }
Beispiel #2
0
        public void GetFullPath_GetDirectoryRoot_Behave_Like_SystemIO()
        {
            // BUG in AlphaFS. Path.FullGetPath()
            // BUG in AlphaFS. Path.GetDirectoryRoot()
            // if G: is G:\Test then it returns G:
            // if G: is G:\ then it returns G:
            // Where as System.IO.Path
            // if G: is G:\Test then it returns G:\Test
            // if G: is G:\ then it returns G:\

            var originalDir = Directory.GetCurrentDirectory();

            Console.WriteLine($"0 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}");
            Console.WriteLine();

            var alphaFP = Path.GetFullPath(@"C:");
            var ioFP    = System.IO.Path.GetFullPath(@"C:");

            Console.WriteLine($"0 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {alphaFP}");
            Console.WriteLine($"0 System.IO.Path.GetFullPath(@\"C:\") {ioFP}");
            Console.WriteLine();
            Assert.That(alphaFP, Is.EqualTo(ioFP));

            Console.WriteLine(
                $"0 Alphaleonis.Win32.Filesystem.Directory.GetDirectoryRoot(@\"C:\") {Directory.GetDirectoryRoot(@"C:")}");
            Console.WriteLine(
                $"0 System.IO.Directory.GetDirectoryRoot(@\"C:\") {System.IO.Directory.GetDirectoryRoot(@"C:")}");
            Console.WriteLine();
            Assert.That(Directory.GetDirectoryRoot(@"C:"), Is.EqualTo(System.IO.Directory.GetDirectoryRoot(@"C:")));

            Directory.SetCurrentDirectory(@"C:\Windows\");
            Console.WriteLine($"1 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}");
            Console.WriteLine($"1 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {Path.GetFullPath(@"C:")}");
            Console.WriteLine($"1 System.IO.Path.GetFullPath(@\"C:\") {System.IO.Path.GetFullPath(@"C:")}");
            Console.WriteLine();
            Assert.That(Path.GetFullPath(@"C:"), Is.EqualTo(System.IO.Path.GetFullPath(@"C:")));

            Directory.SetCurrentDirectory(@"C:\");
            Console.WriteLine($"2 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}");
            Console.WriteLine($"2 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {Path.GetFullPath(@"C:")}");
            Console.WriteLine($"2 System.IO.Path.GetFullPath(@\"C:\") {System.IO.Path.GetFullPath(@"C:")}");
            Console.WriteLine();
            Assert.That(Path.GetFullPath(@"C:"), Is.EqualTo(System.IO.Path.GetFullPath(@"C:")));

            Directory.SetCurrentDirectory(originalDir);
            Console.WriteLine($"3 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}");
            Console.WriteLine($"3 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {Path.GetFullPath(@"C:")}");
            Console.WriteLine($"3 System.IO.Path.GetFullPath(@\"C:\") {System.IO.Path.GetFullPath(@"C:")}");
            Console.WriteLine();
            Assert.That(Path.GetFullPath(@"C:"), Is.EqualTo(System.IO.Path.GetFullPath(@"C:")));
        }
Beispiel #3
0
        public async Task <int> RecommendQueueSize()
        {
            const ulong GB = (1024 * 1024 * 1024);
            // Most of the heavy lifting is done on the scratch disk, so we'll use the value from that disk
            var memory = Utils.GetMemoryStatus();
            // Assume roughly 2GB of ram needed to extract each 7zip archive, and then leave 2GB for the OS
            var based_on_memory = (memory.ullTotalPhys - (2 * GB)) / (2 * GB);
            var scratch_size    = await RecommendQueueSize(Directory.GetCurrentDirectory());

            var result = Math.Min((int)based_on_memory, (int)scratch_size);

            Utils.Log($"Recommending a queue size of {result} based on disk performance, number of cores, and {((long)memory.ullTotalPhys).ToFileSizeString()} of system RAM");
            return(result);
        }
Beispiel #4
0
        public void Dispose()
        {
            var exts = new [] { ".md", ".exe" };

            Utils.DeleteDirectory(Path.Combine(WorkingDirectory, ID));
            Profiles.Do(p =>
            {
                foreach (var ext in exts)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), p + ext);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            });
        }
Beispiel #5
0
        public async ValueTask DisposeAsync()
        {
            var exts = new[] { ".md", ".exe" };
            await WorkingDirectory.Combine(ID).DeleteDirectory();

            Profiles.Do(p =>
            {
                foreach (var ext in exts)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), p + ext);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            });
        }
Beispiel #6
0
 public TestUtils()
 {
     RNG = new Random();
     ID  = RandomName();
     WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "tmp_data");
 }