Exemple #1
0
        /// <inheritdoc/>
        public override async Task <ContentHash> GetFileContentHashAsync(string path, bool trackFile = true, HashType hashType = HashType.Unknown)
        {
            // If the tracker knows about this file, then we already have the hash
            ContentHash hash;

            if (trackFile)
            {
                if (m_inputTracker.TryGetHashForUnchangedFile(path, out hash))
                {
                    return(hash);
                }
            }

            using (
                var fs = FileUtilities.CreateFileStream(
                    path,
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.Delete | FileShare.Read,
                    FileOptions.SequentialScan))
            {
                // Otherwise, check if the file content table already knows about this
                var fileContentTable = m_getFileContentTable();

                VersionedFileIdentityAndContentInfo?maybeKnownIdentityAndHash = fileContentTable.TryGetKnownContentHash(fs);

                if (maybeKnownIdentityAndHash?.FileContentInfo.MatchesHashType(hashType) ?? false)
                {
                    return(maybeKnownIdentityAndHash.Value.FileContentInfo.Hash);
                }

                // Finally, if all the above failed, compute the hash and record it for next time
                hash = await ContentHashingUtilities.HashContentStreamAsync(fs, hashType);

                maybeKnownIdentityAndHash = fileContentTable.RecordContentHash(fs, hash);

                m_specCache?.AddFile(fs, maybeKnownIdentityAndHash.Value.FileContentInfo.Hash, path);
                m_inputTracker.RegisterFileAccess(fs.SafeFileHandle, path, maybeKnownIdentityAndHash.Value);

                return(hash);
            }
        }
Exemple #2
0
 private void AddFile(FileCombiner combiner, FakeFile fakeFile)
 {
     combiner.AddFile(fakeFile.Content, fakeFile.Hash, fakeFile.Path);
 }