Beispiel #1
0
        /// <summary>
        /// Returns the nupkg URI. This will be different for Symbols packages.
        /// </summary>
        public Uri GetNupkgUri(SleetContext context)
        {
            if (IsSymbolsPackage)
            {
                return(context.Source.Get(SymbolsIndexUtility.GetSymbolsNupkgPath(Identity)).EntityUri);
            }

            return(FlatContainer.GetNupkgPath(context, Identity));
        }
Beispiel #2
0
        private async Task AddAssemblyAsync(PackageFile assembly, PackageInput packageInput)
        {
            var file = _context.Source.Get(SymbolsIndexUtility.GetAssemblyFilePath(assembly.FileName, assembly.Hash));

            if (await file.Exists(_context.Log, _context.Token) == false)
            {
                // Write assembly
                await file.Write(assembly.Stream, _context.Log, _context.Token);
            }
        }
Beispiel #3
0
        private async Task AddAssemblyAsync(PackageFile assembly, PackageInput packageInput)
        {
            var file = _context.Source.Get(SymbolsIndexUtility.GetAssemblyFilePath(assembly.FileName, assembly.Hash));

            if (await file.Exists(_context.Log, _context.Token) == false)
            {
                // Write assembly
                using (var stream = await packageInput.GetEntryStreamWithLockAsync(assembly.ZipEntry))
                {
                    await file.Write(stream, _context.Log, _context.Token);
                }
            }
        }
Beispiel #4
0
        public async Task RemoveSymbolsPackageAsync(PackageIdentity package)
        {
            if (await PackageIndex.SymbolsExists(package))
            {
                var toDelete = new List <ISleetFile>();

                // Remove nupkg
                var packagePath = SymbolsIndexUtility.GetSymbolsNupkgPath(package);
                toDelete.Add(_context.Source.Get(packagePath));

                // Remove details page
                var detailsPath = SymbolsIndexUtility.GetSymbolsPackageDetailsPath(package);
                toDelete.Add(_context.Source.Get(detailsPath));

                // Remove package->assembly index
                // Indexes are auto removed when empty
                var packageToAssemblyIndex = GetPackageToAssetIndex(package);
                var assets = await packageToAssemblyIndex.GetSymbolsAssetsAsync();

                foreach (var asset in assets)
                {
                    // Remove package entry from assets
                    var assetIndex = GetAssemblyToPackageIndex(asset.PackageIndex);
                    await assetIndex.RemoveSymbolsPackageAsync(package);

                    // Remove assemblies
                    if (await assetIndex.IsEmpty())
                    {
                        // If the no other packages are referencing the file then remove the assembly.
                        var assetFile = _context.Source.Get(asset.Asset);
                        toDelete.Add(assetFile);
                    }
                }

                // Remove asset from parent index
                await packageToAssemblyIndex.RemoveSymbolsAssetsAsync(assets);

                // Remove from index
                await PackageIndex.RemoveSymbolsPackageAsync(package);

                foreach (var file in toDelete)
                {
                    file.Delete(_context.Log, _context.Token);
                }
            }
        }
Beispiel #5
0
        // Copy the symbols nupkg to the symbols folder and create a catalog details page for it.
        private async Task AddSymbolsNupkgToFeed(PackageInput package)
        {
            // Write .nupkg to feed
            var packagePath = SymbolsIndexUtility.GetSymbolsNupkgPath(package.Identity);
            var packageFile = _context.Source.Get(packagePath);

            await packageFile.Write(File.OpenRead(package.PackagePath), _context.Log, _context.Token);

            // Write catalog entry to the symbols folder for the package
            var detailsPath = SymbolsIndexUtility.GetSymbolsPackageDetailsPath(package.Identity);
            var detailsFile = _context.Source.Get(detailsPath);

            var commitId = Guid.NewGuid();

            var detailsJson = await CatalogUtility.CreatePackageDetailsWithExactUriAsync(package, detailsFile.EntityUri, packageFile.EntityUri, commitId, writeFileList : false);

            await detailsFile.Write(detailsJson, _context.Log, _context.Token);
        }
Beispiel #6
0
        public AssetIndexFile GetPackageToAssetIndex(PackageIdentity package)
        {
            var path = SymbolsIndexUtility.GetPackageToAssemblyIndexPath(package);

            return(new AssetIndexFile(_context, path, package));
        }
Beispiel #7
0
        /// <summary>
        /// Symbols symbols nupkg file.
        /// </summary>
        public ISleetFile GetSymbolsNupkgFile(PackageIdentity package)
        {
            var path = SymbolsIndexUtility.GetSymbolsNupkgPath(package);

            return(_context.Source.Get(path));
        }
Beispiel #8
0
        private async Task <List <PackageFile> > GetAssembliesAsync(PackageInput packageInput)
        {
            var result = new List <PackageFile>();
            var seen   = new HashSet <ISleetFile>();

            var assemblyFiles = await packageInput.RunWithLockAsync(p => Task.FromResult(p.Zip.Entries
                                                                                         .Where(e => e.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
                                                                                         .ToList()));

            var pdbFiles = await packageInput.RunWithLockAsync(p => Task.FromResult(p.Zip.Entries
                                                                                    .Where(e => e.FullName.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase))
                                                                                    .ToList()));

            foreach (var assembly in assemblyFiles)
            {
                string          assemblyHash = null;
                string          pdbHash      = null;
                ZipArchiveEntry pdbEntry     = null;
                var             valid        = false;

                try
                {
                    using (var stream = await packageInput.GetEntryStreamWithLockAsync(assembly))
                        using (var reader = new PEReader(stream))
                        {
                            assemblyHash = SymbolsUtility.GetSymbolHashFromAssembly(reader);
                            pdbHash      = SymbolsUtility.GetPDBHashFromAssembly(reader);
                        }

                    var assemblyWithoutExt = SleetLib.PathUtility.GetFullPathWithoutExtension(assembly.FullName);

                    pdbEntry = pdbFiles.FirstOrDefault(e =>
                                                       StringComparer.OrdinalIgnoreCase.Equals(
                                                           SleetLib.PathUtility.GetFullPathWithoutExtension(e.FullName), assemblyWithoutExt));

                    valid = true;
                }
                catch
                {
                    // Ignore bad assemblies
                    var message = LogMessage.Create(LogLevel.Warning, $"Unable add symbols for {assembly.FullName}, this file will not be present in the symbol server.");
                    await _context.Log.LogAsync(message);
                }

                if (valid)
                {
                    // Add .dll
                    var fileInfo  = new FileInfo(assembly.FullName);
                    var dllFile   = _context.Source.Get(SymbolsIndexUtility.GetAssemblyFilePath(fileInfo.Name, assemblyHash));
                    var indexFile = _context.Source.Get(SymbolsIndexUtility.GetAssemblyToPackageIndexPath(fileInfo.Name, assemblyHash));

                    // Avoid duplicates
                    if (seen.Add(dllFile))
                    {
                        result.Add(new PackageFile(fileInfo.Name, assemblyHash, assembly, dllFile, indexFile));
                    }

                    // Add .pdb
                    if (pdbEntry != null)
                    {
                        var pdbFileInfo  = new FileInfo(pdbEntry.FullName);
                        var pdbFile      = _context.Source.Get(SymbolsIndexUtility.GetAssemblyFilePath(pdbFileInfo.Name, pdbHash));
                        var pdbIndexFile = _context.Source.Get(SymbolsIndexUtility.GetAssemblyToPackageIndexPath(pdbFileInfo.Name, pdbHash));

                        // Avoid duplicates
                        if (seen.Add(pdbFile))
                        {
                            result.Add(new PackageFile(pdbFileInfo.Name, pdbHash, pdbEntry, pdbFile, pdbIndexFile));
                        }
                    }
                }
            }

            return(result);
        }