Exemple #1
0
        public void TestListPaths()
        {
            var normalFile     = new ManifestNormalFile("123", new DateTime(), 10, "normal");
            var dir1           = new ManifestDirectory("/dir1");
            var executableFile = new ManifestExecutableFile("123", new DateTime(), 10, "executable");
            var dir2           = new ManifestDirectory("/dir2");
            var symlink        = new ManifestSymlink("123", 10, "symlink");
            var manifest       = new Manifest(ManifestFormat.Sha256New, normalFile, dir1, executableFile, dir2, symlink);

            manifest.ListPaths().Should().Equal(
                new KeyValuePair <string, ManifestNode>("normal", normalFile),
                new KeyValuePair <string, ManifestNode>("dir1", dir1),
                new KeyValuePair <string, ManifestNode>(Path.Combine("dir1", "executable"), executableFile),
                new KeyValuePair <string, ManifestNode>("dir2", dir2),
                new KeyValuePair <string, ManifestNode>(Path.Combine("dir2", "symlink"), symlink));
        }
Exemple #2
0
        public static Manifest Load([NotNull] Stream stream, [NotNull] ManifestFormat format)
        {
            #region Sanity checks
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            #endregion

            var nodes = new List <ManifestNode>();

            var reader = new StreamReader(stream);
            while (!reader.EndOfStream)
            {
                // Parse each line as a node
                string line = reader.ReadLine() ?? "";
                if (line.StartsWith("F"))
                {
                    nodes.Add(ManifestNormalFile.FromString(line));
                }
                else if (line.StartsWith("X"))
                {
                    nodes.Add(ManifestExecutableFile.FromString(line));
                }
                else if (line.StartsWith("S"))
                {
                    nodes.Add(ManifestSymlink.FromString(line));
                }
                else if (line.StartsWith("D"))
                {
                    nodes.Add(format.ReadDirectoryNodeFromEntry(line));
                }
                else
                {
                    throw new FormatException(Resources.InvalidLinesInManifest);
                }
            }

            return(new Manifest(format, nodes));
        }