Esempio n. 1
0
        public void RemoveTag(string packageId, string tag)
        {
            string manifestPath = Path.Combine(_settings.PackagePath, packageId, "manifest.json");
            if (!File.Exists(manifestPath))
                throw new PackageNotFoundException(packageId);

            string targetPath = Path.Combine(_settings.TagsPath, Obfuscator.Cloak(tag), packageId);
            if (File.Exists(targetPath))
                File.Delete(targetPath);

            // flush in-memory tags
            _packageListCache.Clear();
        }
Esempio n. 2
0
        /// <summary>
        /// Gets packages with tags from the tag index.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public IEnumerable<string> GetPackageIdsWithTags(string[] tags)
        {
            IEnumerable<string> matches = new List<string>();

            foreach (string tag in tags) {
                string tagDirectory = Path.Combine(_settings.TagsPath, Obfuscator.Cloak(tag));
                if (!Directory.Exists(tagDirectory))
                    throw new TagNotFoundException();

                string[] files = Directory.GetFiles(tagDirectory);
                matches = matches.Union(files.Select(r => Path.GetFileName(r)));
            }

            return matches;
        }
Esempio n. 3
0
        public void AddTag(string packageId, string tag)
        {
            string manifestPath = Path.Combine(_settings.PackagePath, packageId, "manifest.json");
            if (!File.Exists(manifestPath))
                throw new PackageNotFoundException(packageId);

            // write tag to fs
            string targetFolder = Path.Combine(_settings.TagsPath, Obfuscator.Cloak(tag));
            Directory.CreateDirectory(targetFolder);
            
            string targetPath = Path.Combine(targetFolder, packageId);
            if (!File.Exists(targetPath))
                File.WriteAllText(targetPath, string.Empty);

            // flush in-memory tags
            _packageListCache.Clear();
        }
Esempio n. 4
0
 /// <summary>
 /// Returns uniform string from Path+Hash
 /// </summary>
 /// <param name="path"></param>
 /// <param name="hash"></param>
 /// <returns></returns>
 public static string Cloak(string path, string hash)
 {
     return(Obfuscator.Cloak($"{path}::{hash}"));
 }