Esempio n. 1
0
        private void Test(string expected, string sampleContent)
        {
            var fingerprint = FingerprintUtilities.Hash(sampleContent);
            var actual      = FingerprintUtilities.FingerprintToFileName(fingerprint.ToByteArray());

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a fingerprint from a content hash.
        /// </summary>
        public static Hash ToFingerprint(this CasHash casHash)
        {
            var hex         = casHash.ToString();
            var fingerprint = FingerprintUtilities.Hash(hex);

            return(new Hash(fingerprint));
        }
Esempio n. 3
0
        private static ContentFingerprint CreateDownloadFingerprint(string baseText)
        {
            // In case something in the cached Bond data becomes incompatible, we must not match.
            const string VersionText = ", BondDataVersion=2;FingerprintVersion=1";
            var          fingerprint = FingerprintUtilities.Hash(baseText + VersionText);

            return(new ContentFingerprint(fingerprint));
        }
Esempio n. 4
0
        private Tuple <Fingerprint, string> ComputeTimestampBasedHashInternal(bool skipManifestCheckTestHook)
        {
            Stopwatch sw = Stopwatch.StartNew();

            // Computes a hash based on the paths and timestamps of all of the referenced files
            using (var wrapper = Pools.StringBuilderPool.GetInstance())
            {
                StringBuilder sb = wrapper.Instance;

                foreach (var file in GetRelevantRelativePaths(forServerDeployment: true))
                {
                    try
                    {
                        FileInfo fi = new FileInfo(Path.Combine(BaseDirectory, file));

                        sb.Append(fi.Name);
                        sb.Append(':');
                        sb.Append(fi.LastWriteTimeUtc.ToBinary());
                        sb.AppendLine();
                    }
#pragma warning disable ERP022 // TODO: This should really handle specific errors
                    catch
                    {
                        // noop for files that cannot be found. The manifest will include exteraneous files
                    }
#pragma warning restore ERP022 // Unobserved exception in generic exception handler
                }

                if (!skipManifestCheckTestHook)
                {
                    ContentHashingUtilities.SetDefaultHashType();
                    AddHashForManifestFile(sb);
                }

                if (sb.Length == 0)
                {
                    throw new BuildXLException("App Deployment hash could not be computed because no files from the deployment manifest could be accessed.");
                }

                string      text        = sb.ToString();
                Fingerprint fingerprint = FingerprintUtilities.Hash(text);
                ComputeTimestampBasedHashTime = sw.Elapsed;
                return(new Tuple <Fingerprint, string>(fingerprint, text));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This will do a build into the session with a given name
        /// and output count.
        /// </summary>
        /// <param name="session">The cache session to work with</param>
        /// <param name="pipName">Some text that acts as a base element in the output</param>
        /// <param name="pipSize">Number of elements in the output.  Must be enough to cover the variants</param>
        /// <param name="weakIndex">Variant with different weak index - defaults to 1</param>
        /// <param name="hashIndex">Variant with different hash index - defaults to 0</param>
        /// <param name="accessMethod">Method (File or stream) for how files are materialized from the cache</param>
        /// <param name="determinism">Determinism to provide for new build records</param>
        /// <returns>The FullCacheRecord of the build</returns>
        /// <remarks>
        /// This will do a "fake build" including a cache lookup via weak fingerprints
        /// and then return either the existing FullCacheRecord or add the build as a new
        /// one.  A new FullCacheRecord will have the StrongFingerprint.CacheId set to NewRecordCacheId
        /// </remarks>
        public static Task <FullCacheRecord> DoPipAsync(
            ICacheSession session,
            string pipName,
            int pipSize   = DefaultFakeBuildSize,
            int weakIndex = 1,
            int hashIndex = 0,
            CacheDeterminism determinism = default(CacheDeterminism),
            CasAccessMethod accessMethod = CasAccessMethod.Stream)
        {
            Contract.Requires(session != null);
            Contract.Requires(pipName != null);
            Contract.Requires(pipSize > 0);
            Contract.Requires(weakIndex >= 0 && weakIndex < pipSize);
            Contract.Requires(hashIndex >= 0 && hashIndex < pipSize);

            FakeBuild fake = new FakeBuild(pipName, pipSize);

            WeakFingerprintHash weak = new WeakFingerprintHash(FingerprintUtilities.Hash(fake.OutputHashes[weakIndex].ToString()).ToByteArray());
            Hash simpleHash          = new Hash(FingerprintUtilities.Hash(fake.OutputHashes[hashIndex].ToString()));

            return(DoPipAsyncImpl(session, weak, simpleHash, fake, determinism, accessMethod));
        }
Esempio n. 6
0
        private static string Hash(string content)
        {
            var hashedBlob = FingerprintUtilities.Hash(content);

            return(FingerprintUtilities.FingerprintToFileName(hashedBlob));
        }
Esempio n. 7
0
 private static StrongContentFingerprint CreateStrongFingerprint(string content)
 {
     return(new StrongContentFingerprint(FingerprintUtilities.Hash(content)));
 }
Esempio n. 8
0
 private static WeakContentFingerprint CreateWeakFingerprint(string content)
 {
     return(new WeakContentFingerprint(FingerprintUtilities.Hash(content)));
 }
Esempio n. 9
0
        public async Task DisconnectedCacheNotQueriedForStrongFingerprints()
        {
            string testCacheId = "Disconnected";
            ICache testCache   = await InitializeCacheAsync(NewCache(testCacheId, false)).SuccessAsync();

            PoisonAllRemoteSessions(testCache);

            ICacheReadOnlySession roSession = await testCache.CreateReadOnlySessionAsync().SuccessAsync();

            DisconnectRemoteCache(testCache);

            FakeBuild fb = new FakeBuild("test", 1);

            foreach (var fingerprint in roSession.EnumerateStrongFingerprints(new WeakFingerprintHash(FingerprintUtilities.Hash("fingerprint").ToByteArray())))
            {
                // Just run the enumerator, should all return.
            }
        }
Esempio n. 10
0
 private static Fingerprint GetHashForString(string target)
 {
     return(FingerprintUtilities.Hash(target));
 }
Esempio n. 11
0
        private const int GetBuildManifestHashFromLocalFileRetryLimit        = 5;   // Starts from 0, retry multiplier is applied upto (GetBuildManifestHashFromLocalFileRetryLimit - 1)

        /// <summary>
        /// EngineEnviromentSettings.BuildManifestHashCacheSalt is used to create a salted weak fingerprint for [VSO:SHA] cache entries using the file's VSO hash as input.
        /// </summary>
        private WeakContentFingerprint GenerateSaltedWeakFingerprint(ContentHash hash) => new WeakContentFingerprint(FingerprintUtilities.Hash($"Hash: '{hash.ToHex()}' Salt: '{m_buildManifestHashCacheSalt}'")); // Changes to this string will invalidate all existing cache entries