示例#1
0
        public (bool, string) VerifyPackage(string packageId)
        {
            Manifest manifest = this.GetManifest(packageId);

            if (manifest == null)
            {
                throw new PackageNotFoundException(packageId);
            }

            StringBuilder hashes = new StringBuilder();

            string[]      files        = files = _hashService.SortFileArrayForHashing(manifest.Files.Select(r => r.Path).ToArray());
            List <string> missingFiles = new List <string>();

            foreach (string filePath in files)
            {
                ManifestItem manifestItem = manifest.Files.FirstOrDefault(r => r.Path == filePath);

                string directFilePath = Path.Combine(_settings.RepositoryPath, manifestItem.Path, manifestItem.Hash, "bin");
                if (File.Exists(directFilePath))
                {
                    hashes.Append(_hashService.FromString(manifestItem.Path));
                    hashes.Append(_hashService.FromFile(directFilePath).Item1);
                }
                else
                {
                    missingFiles.Add(directFilePath);
                }
            }

            if (missingFiles.Any())
            {
                return(false, $"Expected package files missing : {string.Join(",", missingFiles)}");
            }

            string finalHash = _hashService.FromString(hashes.ToString());

            if (finalHash != manifest.Hash)
            {
                return(false, $"Actual package hash {finalHash} does not match expected manifest hash {manifest.Hash}");
            }

            return(true, string.Empty);
        }
示例#2
0
 public (string, long) GetIncomingFileProperties(string relativePath)
 {
     return(_hashService.FromFile(Path.Join(this.WorkspacePath, "incoming", relativePath)));
 }