Example #1
0
        public PackageManager()
        {
            var csharp = Configuration.CSharpPackageDirectory;
            var python = Configuration.PythonPackageDirectory;

            Directory.CreateDirectory(csharp);
            Directory.CreateDirectory(python);

            _log.Info("Fetching package registry...");

            var json     = GitHub.GetString(Configuration.PackageRegistryUri);
            var manifest = JArray.Parse(json);

            Registry = manifest.Select(x => new Package((JObject)x)).ToDictionary(x => x.Name);

            void CheckReferredPackages(bool dependencies)
            {
                foreach (var pkg in Registry.Values)
                {
                    foreach (var name in dependencies ? pkg.Dependencies : pkg.Conflicts)
                    {
                        if (!Registry.ContainsKey(name))
                        {
                            _log.Warning("Package {0} has {1} package {2} which does not exist; ignoring",
                                         pkg.Name, dependencies ? "dependency" : "conflicting", name);
                        }
                    }
                }
            }

            CheckReferredPackages(true);
            CheckReferredPackages(false);

            _log.Info("Reading local package manifests...");

            void AddLocalPackages(PackageKind kind)
            {
                foreach (var dir in Directory.EnumerateDirectories(
                             kind == PackageKind.CSharp ? csharp : python))
                {
                    if (!File.Exists(Path.Combine(dir, ManifestFileName)))
                    {
                        continue;
                    }

                    var pkg = new LocalPackage(kind, Path.GetFileName(dir));

                    _locals.Add(pkg.Name, pkg);
                }
            }

            AddLocalPackages(PackageKind.CSharp);
            AddLocalPackages(PackageKind.Python);
        }
Example #2
0
        public void Uninstall(LocalPackage package, bool everything)
        {
            File.Delete(package.ManifestFilePath);

            var dirs = new HashSet <string>();

            foreach (var file in package.Files)
            {
                var path = Path.Combine(package.Path, file);

                File.Delete(path);

                _log.Info("Removed {0}", path);

                var dir = Path.GetDirectoryName(path);

                if (dir != string.Empty)
                {
                    dirs.Add(dir);
                }
            }

            DirectoryInfo info;

            foreach (var dir in dirs)
            {
                if ((info = new DirectoryInfo(dir)).Exists && !info.EnumerateFileSystemInfos().Any())
                {
                    Directory.Delete(dir, true);
                }
            }

            _locals.Remove(package.Name);

            if (everything)
            {
                Directory.Delete(package.Path, true);
            }
        }
Example #3
0
 public void Update(LocalPackage local, Package latest)
 {
     Uninstall(local, false);
     Install(latest);
 }
Example #4
0
        public PackageManager()
        {
            var pkgs = Configuration.PackageDirectory;

            Directory.CreateDirectory(pkgs);

            _log.Info("Fetching package registry...");

            var registry = JArray.Parse(GitHub.GetString(Configuration.PackageRegistryUri))
                           .Select(x => new Package((JObject)x)).ToDictionary(x => x.Name);

            foreach (var pkg in registry.Values.ToArray())
            {
                var abs = Path.GetFullPath(pkg.Path);
                var bad = false;

                void CheckReferredPackages(bool dependencies)
                {
                    foreach (var name in dependencies ? pkg.Dependencies : pkg.Conflicts)
                    {
                        if (!registry.ContainsKey(name))
                        {
                            _log.Warning("Package {0} has {1} package {2} which does not exist; ignoring package",
                                         pkg.Name, dependencies ? "dependency" : "conflicting", name);
                            bad = true;
                        }
                    }
                }

                CheckReferredPackages(true);
                CheckReferredPackages(false);

                foreach (var file in pkg.Files)
                {
                    var loc = Path.GetFullPath(Path.Combine(abs, file));

                    if (!loc.StartsWith(abs + Path.DirectorySeparatorChar) &&
                        !loc.StartsWith(abs + Path.AltDirectorySeparatorChar))
                    {
                        _log.Warning("Package {0} has file path {1} which is illegal; ignoring package",
                                     pkg.Name, file);
                        bad = true;
                    }

                    if (loc == Path.Combine(abs, PackageFileName) ||
                        loc == Path.Combine(abs, ManifestFileName) ||
                        loc == Path.Combine(abs, ConfigurationFileName))
                    {
                        _log.Warning("Package {0} has file path {1} which is for internal use; ignoring package",
                                     pkg.Name, file);
                        bad = true;
                    }
                }

                if (bad)
                {
                    registry.Remove(pkg.Name);
                }
            }

            Registry = registry;

            _log.Info("Reading local package manifests...");

            foreach (var dir in Directory.EnumerateDirectories(pkgs))
            {
                if (!File.Exists(Path.Combine(dir, ManifestFileName)))
                {
                    continue;
                }

                var pkg = new LocalPackage(Path.GetFileName(dir));

                _locals.Add(pkg.Name, pkg);
            }
        }