Пример #1
0
        public void Open_FileExists(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Create)) { s.WriteByte(1); }

            Assert.Throws <IOException>(() =>
            {
                using (Stream s = di.Open(FileMode.CreateNew))
                {
                }
            });
        }
Пример #2
0
        public static Stream OpenPsPath(SessionState session, string filePath, FileAccess access, FileShare share)
        {
            var items = session.InvokeProvider.Item.Get(filePath);

            if (items.Count == 1)
            {
                FileInfo itemAsFile = items[0].BaseObject as FileInfo;
                if (itemAsFile != null)
                {
                    return(itemAsFile.Open(FileMode.Open, access, share));
                }

                DiscFileInfo itemAsDiscFile = items[0].BaseObject as DiscFileInfo;
                if (itemAsDiscFile != null)
                {
                    return(itemAsDiscFile.Open(FileMode.Open, access));
                }

                throw new FileNotFoundException("Path is not a file", filePath);
            }
            else if (items.Count > 1)
            {
                throw new IOException(string.Format(CultureInfo.InvariantCulture, "PowerShell path {0} is ambiguous", filePath));
            }
            else
            {
                throw new FileNotFoundException("No such file", filePath);
            }
        }
Пример #3
0
        public void Open_FileNotFound()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Open)) { }
        }
Пример #4
0
        private void WriteFileToArchive(string entryName, DiscFileInfo file)
        {
            var tmptext = entryName.Substring(0, 1) + ":" + entryName.Substring(1);

            Console.WriteLine("Collecting File: {0}", tmptext);
            using (var stream = file.Open(FileMode.Open, FileAccess.Read))
            {
                WriteStreamToArchive(entryName, stream);
            }
        }
Пример #5
0
        public void Attributes_ChangeType(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo fi = fs.GetFileInfo("foo.txt");

            using (Stream s = fi.Open(FileMode.Create)) { }

            Assert.Throws <ArgumentException>(() => fi.Attributes = fi.Attributes | FileAttributes.Directory);
        }
Пример #6
0
        public void Open_Write_Fail(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Create, FileAccess.ReadWrite))
            {
                s.WriteByte(1);
            }

            using (Stream s = di.Open(FileMode.Open, FileAccess.Write))
            {
                Assert.True(s.CanWrite);
                Assert.False(s.CanRead);

                Assert.Throws <IOException>(() => s.ReadByte());
            }
        }
Пример #7
0
        public void Open_Read(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Create))
            {
                s.WriteByte(1);
            }

            using (Stream s = di.Open(FileMode.Open, FileAccess.Read))
            {
                Assert.False(s.CanWrite);
                Assert.True(s.CanRead);

                Assert.Equal(1, s.ReadByte());
            }
        }
Пример #8
0
        public void Open_DirExists(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            fs.CreateDirectory("FOO.TXT");

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            Assert.Throws <IOException>(() => di.Open(FileMode.Create));
        }
Пример #9
0
        public void Open_Read_Fail(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Create, FileAccess.Read))
            {
                Assert.Throws <IOException>(() => s.WriteByte(1));
            }
        }
Пример #10
0
        public void Open_FileNotFound(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            Assert.Throws <FileNotFoundException>(() =>
            {
                using (Stream s = di.Open(FileMode.Open))
                {
                }
            });
        }
Пример #11
0
        public void Exists(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo fi = fs.GetFileInfo("foo.txt");

            Assert.False(fi.Exists);

            using (Stream s = fi.Open(FileMode.Create)) { }
            Assert.True(fi.Exists);

            fs.CreateDirectory("dir.txt");
            Assert.False(fs.GetFileInfo("dir.txt").Exists);
        }
Пример #12
0
        public void Open_FileNotFound()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            Assert.Throws <FileNotFoundException>(() =>
            {
                using (Stream s = di.Open(FileMode.Open))
                {
                }
            });
        }
Пример #13
0
        public void Open_Read()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile("foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Open, FileAccess.Read))
            {
                Assert.IsFalse(s.CanWrite);
                Assert.IsTrue(s.CanRead);

                Assert.AreEqual(1, s.ReadByte());
            }
        }
Пример #14
0
        public void Attributes(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            DiscFileInfo fi = fs.GetFileInfo("foo.txt");

            using (Stream s = fi.Open(FileMode.Create)) { }

            // Check default attributes
            Assert.Equal(FileAttributes.Archive, fi.Attributes);

            // Check round-trip
            FileAttributes newAttrs = FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System;

            fi.Attributes = newAttrs;
            Assert.Equal(newAttrs, fi.Attributes);

            // And check persistence to disk
            Assert.Equal(newAttrs, fs.GetFileInfo("foo.txt").Attributes);
        }