Exemplo n.º 1
0
        public static Morphs Populate(Pogo pogo, PathName dataDir)
        {
            var morphs = new Morphs(pogo);

            foreach (var file in dataDir.EnumerateFiles())
            {
                if (file.Name.StartsWith("."))
                {
                    continue;
                }

                var recipe = Recipes.RecipeParser.Parse(file.Full);
                var morph  = new Morph(pogo, recipe);
                morphs.Add(morph);
            }

            return(morphs);
        }
Exemplo n.º 2
0
        public bool Extract(bool force)
        {
            var archivePath = Pogo.ArchivePath(this.uri);
            var extractPath = Pogo.SourcePath(this.uri);

            if (!archivePath.ExistsFile())
            {
                throw PathNameErrors.FileNotFoundException(archivePath);
            }
            if (extractPath.ExistsDirectory())
            {
                if (!force)
                {
                    return(true);
                }
                Terminal.Write("clean ", extractPath.Name, ": ");
                PathNameTools.RemoveDirectory(extractPath);
                Terminal.ClearLine();
            }
            if (extractPath.ExistsFile())
            {
                throw PathNameErrors.EntityExistsButIsNotDirectory(extractPath);
            }
            PathName extractPathTmp = extractPath.Full + ".tmp";

            if (extractPathTmp.ExistsDirectory())
            {
                Terminal.Write("clean ", extractPathTmp.Name, ": ");
                PathNameTools.RemoveDirectory(extractPathTmp);
                Terminal.ClearLine();
            }
            if (extractPathTmp.ExistsFile())
            {
                throw PathNameErrors.EntityExistsButIsNotDirectory(extractPathTmp);
            }

            extractPathTmp.CreateDirectory();

            Terminal.Write("extract ", archivePath.Name, ": ");

            var xtract = Bash.TarExtract(archivePath, extractPathTmp);

            Terminal.ClearLine();

            var dirs  = extractPathTmp.EnumerateDirectories().ToList();
            var files = extractPathTmp.EnumerateFiles().ToList();

            if (dirs.Count == 1 && files.Count == 0)
            {
                dirs.First().MoveDirectory(extractPath);
                extractPathTmp.DeleteDirectory();
            }
            else
            {
                extractPathTmp.MoveDirectory(extractPath);
            }

            Terminal.WriteLine("extract ", xtract.Ok ? "OK: " : "FAIL: ", archivePath.Name);

            return(xtract.Ok);
        }