Beispiel #1
0
        public StoredPackage GetPackage(PackageMetadata metadata)
        {
            var name = GetNameOfPackage(metadata);
            fileSystem.EnsureDirectoryExists(rootDirectory);

            var files = fileSystem.EnumerateFilesRecursively(rootDirectory, name + ".nupkg-*");

            foreach (var file in files)
            {
                var storedPackage = GetPackage(file);
                if (storedPackage == null)
                    continue;

                if (!string.Equals(storedPackage.Metadata.Id, metadata.Id, StringComparison.OrdinalIgnoreCase) || !string.Equals(storedPackage.Metadata.Version, metadata.Version, StringComparison.OrdinalIgnoreCase))
                    continue;

                if (string.IsNullOrWhiteSpace(metadata.Hash))
                    return storedPackage;

                if (metadata.Hash == storedPackage.Metadata.Hash)
                    return storedPackage;
            }

            return null;
        }
Beispiel #2
0
        public string GetFilenameForPackage(PackageMetadata metadata, string prefix = null)
        {
            var name = GetNameOfPackage(metadata);
            var fullPath = Path.Combine(GetPackageRoot(prefix), name + BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", string.Empty) + ".nupkg");

            fileSystem.EnsureDirectoryExists(rootDirectory);

            return fullPath;
        }
 PackageMetadata ReadManifestStream(Stream manifestStream)
 {
     var result = new PackageMetadata();
     var manifest = Manifest.ReadFrom(manifestStream, validateSchema: false);
     var packageMetadata = (IPackageMetadata)manifest.Metadata;
     result.Id = packageMetadata.Id;
     result.Version = packageMetadata.Version.ToString();
     return result;
 }
        protected override string GetTargetPath(RunningDeployment deployment, PackageMetadata metadata)
        {
            var packageExtractionPathVariable = deployment.Variables[SpecialVariables.Action.Azure.PackageExtractionPath];

            // The PackageExtractionPath variable will always be provided by the OD server, but just in case Calamari is run
            // stand-alone, we will fall-back to a temporary path
            return !string.IsNullOrWhiteSpace(packageExtractionPathVariable)
                ? packageExtractionPathVariable
                : fileSystem.CreateTemporaryDirectory();
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(packageId, "No package ID was specified. Please pass --packageId YourPackage");
            Guard.NotNullOrWhiteSpace(packageVersion, "No package version was specified. Please pass --packageVersion 1.0.0.0");
            Guard.NotNullOrWhiteSpace(packageHash, "No package hash was specified. Please pass --packageHash YourPackageHash");
            
            SemanticVersion version;
            if(!SemanticVersion.TryParse(packageVersion, out version))
                throw new CommandException(String.Format("Package version '{0}' is not a valid Semantic Version", packageVersion));

            var packageStore = new PackageStore();
            var packageMetadata = new PackageMetadata {Id = packageId, Version = packageVersion, Hash = packageHash};
            var package = packageStore.GetPackage(packageMetadata);
            if (package == null)
            {
                Log.VerboseFormat("Package {0} version {1} hash {2} has not been uploaded.", 
                    packageMetadata.Id, packageMetadata.Version, packageMetadata.Hash);

                Log.VerboseFormat("Finding earlier packages that have been uploaded to this Tentacle.");
                var nearestPackages = packageStore.GetNearestPackages(packageId, version).ToList();
                if (!nearestPackages.Any())
                {
                    Log.VerboseFormat("No earlier packages for {0} has been uploaded", packageId);
                    return 0;
                }

                Log.VerboseFormat("Found {0} earlier {1} of {2} on this Tentacle", 
                    nearestPackages.Count, nearestPackages.Count == 1 ? "version" : "versions", packageId);
                foreach(var nearestPackage in nearestPackages)
                {
                    Log.VerboseFormat("  - {0}: {1}", nearestPackage.Metadata.Version, nearestPackage.FullPath);
                    Log.ServiceMessages.PackageFound(nearestPackage.Metadata.Id, nearestPackage.Metadata.Version, nearestPackage.Metadata.Hash, nearestPackage.FullPath);
                }

                return 0;
            }

            Log.VerboseFormat("Package {0} {1} hash {2} has already been uploaded", package.Metadata.Id, package.Metadata.Version, package.Metadata.Hash);
            Log.ServiceMessages.PackageFound(package.Metadata.Id, package.Metadata.Version, package.Metadata.Hash, package.FullPath, true);
            return 0;
        }
 protected override string GetTargetPath(RunningDeployment deployment, PackageMetadata metadata)
 {
     var root = GetInitialExtractionDirectory(deployment.Variables);
     return EnsureTargetPathIsEmpty(Path.Combine(root, metadata.Id, metadata.Version));
 }
Beispiel #7
0
 public StoredPackage GetPackage(PackageMetadata metadata)
 {
     return GetPackage(null, metadata);
 }
Beispiel #8
0
 public bool DoesPackageExist(string prefix, PackageMetadata metadata)
 {
     var package = GetPackage(prefix, metadata);
     return package != null;
 }
Beispiel #9
0
 public bool DoesPackageExist(PackageMetadata metadata)
 {
     return DoesPackageExist(null, metadata);
 }
Beispiel #10
0
        StoredPackage ReadPackageFile(string filePath)
        {
            try
            {
                var metadata = new ZipPackage(filePath);

                using (var hashStream = metadata.GetStream())
                {
                    var hash = HashCalculator.Hash(hashStream);

                    var packageMetadata = new PackageMetadata
                    {
                       Id = metadata.Id,
                        Version = metadata.Version.ToString(),
                        Hash = hash
                    };

                    return new StoredPackage(packageMetadata, filePath);
                }
            }
            catch (FileNotFoundException)
            {
                return null;
            }
            catch (IOException)
            {
                return null;
            }
            catch (FileFormatException)
            {
                return null;
            }
        }
Beispiel #11
0
 static string GetNameOfPackage(PackageMetadata metadata)
 {
     return metadata.Id + "." + metadata.Version;
 }
Beispiel #12
0
 public StoredPackage(PackageMetadata metadata, string fullPath)
 {
     Metadata = metadata;
     FullPath = fullPath;
 }
Beispiel #13
0
 public StoredPackage(PackageMetadata metadata, string fullPath)
 {
     Metadata = metadata;
     FullPath = fullPath;
 }