public override bool Execute()
        {
            Log.LogMessage(MessageImportance.Normal, "Creating SquashFS file: '{0}'", FileName.ItemSpec);

            try
            {
                SquashFileSystemBuilder builder = new SquashFileSystemBuilder();

                foreach (var sourceFile in SourceFiles)
                {
                    if (this.RemoveRoot != null)
                    {
                        string location = (sourceFile.GetMetadata("FullPath")).Replace(this.RemoveRoot.GetMetadata("FullPath"), string.Empty);
                        builder.AddFile(location, sourceFile.GetMetadata("FullPath"));
                    }
                    else
                    {
                        builder.AddFile(sourceFile.GetMetadata("Directory") + sourceFile.GetMetadata("FileName") + sourceFile.GetMetadata("Extension"), sourceFile.GetMetadata("FullPath"));
                    }
                }

                builder.Build(FileName.ItemSpec);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true, true, null);
                return false;
            }

            return !Log.HasLoggedErrors;
        }
        public void BlockData()
        {
            byte[] testData = new byte[(512 * 1024) + 21];
            for (int i = 0; i < testData.Length; ++i)
            {
                testData[i] = (byte)(i % 33);
            }

            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();
            builder.AddFile(@"file", new MemoryStream(testData));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            using (Stream fs = reader.OpenFile("file", FileMode.Open))
            {
                byte[] buffer = new byte[(512 * 1024) + 1024];
                int numRead = fs.Read(buffer, 0, buffer.Length);

                Assert.AreEqual(testData.Length, numRead);
                for (int i = 0; i < testData.Length; ++i)
                {
                    Assert.AreEqual(testData[i], buffer[i], "Data differs at index " + i);
                }
            }
        }
示例#3
0
        public void BlockData()
        {
            byte[] testData = new byte[(512 * 1024) + 21];
            for (int i = 0; i < testData.Length; ++i)
            {
                testData[i] = (byte)(i % 33);
            }

            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();

            builder.AddFile(@"file", new MemoryStream(testData));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            using (Stream fs = reader.OpenFile("file", FileMode.Open))
            {
                byte[] buffer  = new byte[(512 * 1024) + 1024];
                int    numRead = fs.Read(buffer, 0, buffer.Length);

                Assert.AreEqual(testData.Length, numRead);
                for (int i = 0; i < testData.Length; ++i)
                {
                    Assert.AreEqual(testData[i], buffer[i], "Data differs at index " + i);
                }
            }
        }
        public void Detect()
        {
            MemoryStream ms = new MemoryStream(new byte[1000]);
            Assert.IsFalse(SquashFileSystemReader.Detect(ms));

            ms = new MemoryStream(new byte[10]);
            Assert.IsFalse(SquashFileSystemReader.Detect(ms));

            MemoryStream emptyFs = new MemoryStream();
            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();
            builder.Build(emptyFs);
            Assert.IsTrue(SquashFileSystemReader.Detect(emptyFs));
        }
        public void CreateDirs()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();
            builder.AddFile(@"\adir\anotherdir\file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);
            Assert.IsTrue(reader.DirectoryExists(@"adir"));
            Assert.IsTrue(reader.DirectoryExists(@"adir\anotherdir"));
            Assert.IsTrue(reader.FileExists(@"adir\anotherdir\file"));
        }
        public void Detect()
        {
            MemoryStream ms = new MemoryStream(new byte[1000]);

            Assert.IsFalse(SquashFileSystemReader.Detect(ms));

            ms = new MemoryStream(new byte[10]);
            Assert.IsFalse(SquashFileSystemReader.Detect(ms));

            MemoryStream            emptyFs = new MemoryStream();
            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();

            builder.Build(emptyFs);
            Assert.IsTrue(SquashFileSystemReader.Detect(emptyFs));
        }
示例#7
0
        public void CreateDirs()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();

            builder.AddFile(@"\adir\anotherdir\file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            Assert.IsTrue(reader.DirectoryExists(@"adir"));
            Assert.IsTrue(reader.DirectoryExists(@"adir\anotherdir"));
            Assert.IsTrue(reader.FileExists(@"adir\anotherdir\file"));
        }
示例#8
0
        public void SingleFile()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();

            builder.AddFile("file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            Assert.AreEqual(1, reader.GetFileSystemEntries("\\").Length);
            Assert.AreEqual(4, reader.GetFileLength("file"));
            Assert.IsTrue(reader.FileExists("file"));
            Assert.IsFalse(reader.DirectoryExists("file"));
            Assert.IsFalse(reader.FileExists("otherfile"));
        }
示例#9
0
        public void FragmentData()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();

            builder.AddFile(@"file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            using (Stream fs = reader.OpenFile("file", FileMode.Open))
            {
                byte[] buffer  = new byte[100];
                int    numRead = fs.Read(buffer, 0, 100);

                Assert.AreEqual(4, numRead);
                Assert.AreEqual(1, buffer[0]);
                Assert.AreEqual(2, buffer[1]);
                Assert.AreEqual(3, buffer[2]);
                Assert.AreEqual(4, buffer[3]);
            }
        }
示例#10
0
        public void Defaults()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();

            builder.AddFile(@"file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.AddDirectory(@"dir");

            builder.DefaultUser                 = 1000;
            builder.DefaultGroup                = 1234;
            builder.DefaultFilePermissions      = UnixFilePermissions.OwnerAll;
            builder.DefaultDirectoryPermissions = UnixFilePermissions.GroupAll;

            builder.AddFile("file2", new MemoryStream());
            builder.AddDirectory("dir2");

            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            Assert.AreEqual(0, reader.GetUnixFileInfo("file").UserId);
            Assert.AreEqual(0, reader.GetUnixFileInfo("file").GroupId);
            Assert.AreEqual(UnixFilePermissions.OwnerRead | UnixFilePermissions.OwnerWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupWrite, reader.GetUnixFileInfo("file").Permissions);

            Assert.AreEqual(0, reader.GetUnixFileInfo("dir").UserId);
            Assert.AreEqual(0, reader.GetUnixFileInfo("dir").GroupId);
            Assert.AreEqual(UnixFilePermissions.OwnerAll | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupExecute | UnixFilePermissions.OthersRead | UnixFilePermissions.OthersExecute, reader.GetUnixFileInfo("dir").Permissions);

            Assert.AreEqual(1000, reader.GetUnixFileInfo("file2").UserId);
            Assert.AreEqual(1234, reader.GetUnixFileInfo("file2").GroupId);
            Assert.AreEqual(UnixFilePermissions.OwnerAll, reader.GetUnixFileInfo("file2").Permissions);

            Assert.AreEqual(1000, reader.GetUnixFileInfo("dir2").UserId);
            Assert.AreEqual(1234, reader.GetUnixFileInfo("dir2").GroupId);
            Assert.AreEqual(UnixFilePermissions.GroupAll, reader.GetUnixFileInfo("dir2").Permissions);
        }
        public void Defaults()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();
            builder.AddFile(@"file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.AddDirectory(@"dir");

            builder.DefaultUser = 1000;
            builder.DefaultGroup = 1234;
            builder.DefaultFilePermissions = UnixFilePermissions.OwnerAll;
            builder.DefaultDirectoryPermissions = UnixFilePermissions.GroupAll;

            builder.AddFile("file2", new MemoryStream());
            builder.AddDirectory("dir2");

            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            Assert.AreEqual(0, reader.GetUnixFileInfo("file").UserId);
            Assert.AreEqual(0, reader.GetUnixFileInfo("file").GroupId);
            Assert.AreEqual(UnixFilePermissions.OwnerRead | UnixFilePermissions.OwnerWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupWrite, reader.GetUnixFileInfo("file").Permissions);

            Assert.AreEqual(0, reader.GetUnixFileInfo("dir").UserId);
            Assert.AreEqual(0, reader.GetUnixFileInfo("dir").GroupId);
            Assert.AreEqual(UnixFilePermissions.OwnerAll | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupExecute | UnixFilePermissions.OthersRead | UnixFilePermissions.OthersExecute, reader.GetUnixFileInfo("dir").Permissions);

            Assert.AreEqual(1000, reader.GetUnixFileInfo("file2").UserId);
            Assert.AreEqual(1234, reader.GetUnixFileInfo("file2").GroupId);
            Assert.AreEqual(UnixFilePermissions.OwnerAll, reader.GetUnixFileInfo("file2").Permissions);

            Assert.AreEqual(1000, reader.GetUnixFileInfo("dir2").UserId);
            Assert.AreEqual(1234, reader.GetUnixFileInfo("dir2").GroupId);
            Assert.AreEqual(UnixFilePermissions.GroupAll, reader.GetUnixFileInfo("dir2").Permissions);
        }
        public void SingleFile()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();
            builder.AddFile("file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);
            Assert.AreEqual(1, reader.GetFileSystemEntries("\\").Length);
            Assert.AreEqual(4, reader.GetFileLength("file"));
            Assert.IsTrue(reader.FileExists("file"));
            Assert.IsFalse(reader.DirectoryExists("file"));
            Assert.IsFalse(reader.FileExists("otherfile"));
        }
        public void FragmentData()
        {
            MemoryStream fsImage = new MemoryStream();

            SquashFileSystemBuilder builder = new SquashFileSystemBuilder();
            builder.AddFile(@"file", new MemoryStream(new byte[] { 1, 2, 3, 4 }));
            builder.Build(fsImage);

            SquashFileSystemReader reader = new SquashFileSystemReader(fsImage);

            using (Stream fs = reader.OpenFile("file", FileMode.Open))
            {
                byte[] buffer = new byte[100];
                int numRead = fs.Read(buffer, 0, 100);

                Assert.AreEqual(4, numRead);
                Assert.AreEqual(1, buffer[0]);
                Assert.AreEqual(2, buffer[1]);
                Assert.AreEqual(3, buffer[2]);
                Assert.AreEqual(4, buffer[3]);
            }
        }