private PackageFromBuiltInFeedResource AttemptDeltaPush(string fileName, Stream contents, bool replaceExisting)
        {
            if (!repository.HasLink("PackageDeltaSignature"))
            {
                Logger.Info("Server does not support delta compression for package push");
                return(null);
            }

            if (!PackageIdentityParser.TryParsePackageIdAndVersion(Path.GetFileNameWithoutExtension(fileName), out var packageId, out var version))
            {
                Logger.Info("Could not determine the package ID and/or version based on the supplied filename");
                return(null);
            }

            PackageSignatureResource signatureResult;

            try
            {
                Logger.Info($"Requesting signature for delta compression from the server for upload of a package with id '{packageId}' and version '{version}'");
                signatureResult = repository.Client.Get <PackageSignatureResource>(repository.Link("PackageDeltaSignature"), new { packageId, version });
            }
            catch (OctopusResourceNotFoundException)
            {
                Logger.Info("No package with the same ID exists on the server");
                return(null);
            }

            using (var deltaTempFile = new TemporaryFile())
            {
                var shouldUpload = DeltaCompression.CreateDelta(contents, signatureResult, deltaTempFile.FileName);
                if (!shouldUpload)
                {
                    return(null);
                }

                using (var delta = File.OpenRead(deltaTempFile.FileName))
                {
                    var result = repository.Client.Post <FileUpload, PackageFromBuiltInFeedResource>(
                        repository.Link("PackageDeltaUpload"),
                        new FileUpload()
                    {
                        Contents = delta, FileName = Path.GetFileName(fileName)
                    },
                        new { replace = replaceExisting, packageId, signatureResult.BaseVersion });

                    Logger.Info($"Delta transfer completed");
                    return(result);
                }
            }
        }
Пример #2
0
        private async Task <PackageFromBuiltInFeedResource> VerifyTransfer(string fileName, Stream contents)
        {
            Logger.Info("Trying to find out whether the transfer worked");

            if (!PackageIdentityParser.TryParsePackageIdAndVersion(Path.GetFileNameWithoutExtension(fileName),
                                                                   out var packageId, out var version))
            {
                Logger.Info("Can't check whether the transfer actually worked");
                return(null);
            }

            var uploadedPackage = await TryFindPackage(packageId, version);

            return(PackageContentComparer.AreSame(uploadedPackage, contents, Logger) ? uploadedPackage : null);
        }
        private PackageFromBuiltInFeedResource AttemptDeltaPush(string fileName, Stream contents, OverwriteMode overwriteMode)
        {
            if (!repository.HasLink("PackageDeltaSignature"))
            {
                Logger.Info("Server does not support delta compression for package push");
                return(null);
            }

            if (!PackageIdentityParser.TryParsePackageIdAndVersion(Path.GetFileNameWithoutExtension(fileName), out var packageId, out var version))
            {
                Logger.Info("Could not determine the package ID and/or version based on the supplied filename");
                return(null);
            }

            PackageSignatureResource signatureResult;

            try
            {
                Logger.Info($"Requesting signature for delta compression from the server for upload of a package with id '{packageId}' and version '{version}'");
                signatureResult = repository.Client.Get <PackageSignatureResource>(repository.Link("PackageDeltaSignature"), new { packageId, version });
            }
            catch (OctopusResourceNotFoundException)
            {
                Logger.Info("No package with the same ID exists on the server");
                return(null);
            }

            using (var deltaTempFile = new TemporaryFile())
            {
                var shouldUpload = DeltaCompression.CreateDelta(contents, signatureResult, deltaTempFile.FileName);
                if (!shouldUpload)
                {
                    return(null);
                }

                using (var delta = File.OpenRead(deltaTempFile.FileName))
                {
                    var    link = repository.Link("PackageDeltaUpload");
                    object pathParameters;

                    // if the link contains overwriteMode then we're connected to a new server, if not use the old `replace` parameter
                    if (link.Contains(OverwriteModeLink.Link))
                    {
                        pathParameters = new { overwriteMode = overwriteMode, packageId, signatureResult.BaseVersion };
                    }
                    else
                    {
                        pathParameters = new { replace = overwriteMode.ConvertToLegacyReplaceFlag(Logger), packageId, signatureResult.BaseVersion };
                    }

                    var result = repository.Client.Post <FileUpload, PackageFromBuiltInFeedResource>(
                        link,
                        new FileUpload()
                    {
                        Contents = delta, FileName = Path.GetFileName(fileName)
                    },
                        pathParameters);

                    Logger.Info($"Delta transfer completed");
                    return(result);
                }
            }
        }