Esempio n. 1
0
        public string Sha256(SnapRelease snapRelease, [NotNull] IPackageCoreReader packageCoreReader, [NotNull] ISnapPack snapPack)
        {
            if (snapRelease == null)
            {
                throw new ArgumentNullException(nameof(snapRelease));
            }
            if (packageCoreReader == null)
            {
                throw new ArgumentNullException(nameof(packageCoreReader));
            }
            if (snapPack == null)
            {
                throw new ArgumentNullException(nameof(snapPack));
            }

            var packageArchiveFiles = packageCoreReader.GetFiles();

            var checksumFiles = GetChecksumFilesForSnapRelease(snapRelease);

            var inputStreams = checksumFiles
                               .Select(checksum => (checksum, targetPath: packageArchiveFiles.SingleOrDefault(targetPath => checksum.NuspecTargetPath == targetPath)))
                               .Select(x =>
            {
                var(checksum, packageArchiveReaderTargetPath) = x;
                if (packageArchiveReaderTargetPath == null)
                {
                    throw new FileNotFoundException($"Unable to find file in nupkg: {snapRelease.Filename}.", checksum.NuspecTargetPath);
                }
                return(checksum, packageCoreReader.GetStream(packageArchiveReaderTargetPath));
            });

            return(Sha256(inputStreams));
        }
        public static string GetNuspecFile(this IPackageCoreReader packageReader)
        {
            // Find all nuspec files in the root folder of the zip.
            var nuspecEntries = packageReader.GetFiles()
                                .Select(f => f.TrimStart('/').Replace('/', Path.DirectorySeparatorChar))
                                .Where(f => f.EndsWith(PackagingCoreConstants.NuspecExtension, StringComparison.OrdinalIgnoreCase))
                                .Where(f => string.Equals(f, Path.GetFileName(f), StringComparison.OrdinalIgnoreCase))
                                .ToArray();

            if (nuspecEntries.Length == 0)
            {
                throw new PackagingException(Strings.MissingNuspec);
            }
            else if (nuspecEntries.Length > 1)
            {
                throw new PackagingException(Strings.MultipleNuspecFiles);
            }

            return(nuspecEntries[0]);
        }
Esempio n. 3
0
        public static Manifest GetManifest(this IPackageCoreReader packageReader)
        {
            using (var stream = packageReader.GetNuspec())
            {
                var manifest = Manifest.ReadFrom(stream, true);
                manifest.Files.AddRange(packageReader.GetFiles()
                                        // Skip the auto-added stuff
                                        .Where(file =>
                                               file != "[Content_Types].xml" &&
                                               file != "_rels/.rels" &&
                                               !file.EndsWith(".nuspec") &&
                                               !file.EndsWith(".psmdcp"))
                                        .Select(file => new ManifestFile
                {
                    // Can't replicate the Source path as it was originally before adding
                    // to the package, so leave it null to avoid false promises in tests.
                    //Source = file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar),
                    Target = file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
                }));

                return(manifest);
            }
        }
 public static IEnumerable <string> GetPackageFiles(this IPackageCoreReader packageReader, PackageSaveMode packageSaveMode)
 {
     return(packageReader.GetFiles().Where(file => PackageHelper.IsPackageFile(file, packageSaveMode)));
 }
Esempio n. 5
0
 public IEnumerable <string> GetFiles() => _reader.GetFiles();