private VersionedFileIdentityAndContentInfo RecordContentHash(FileContentTable table, AbsolutePath path, ContentHash hash, bool strict = false)
        {
            Contract.Requires(table != null);

            using (
                FileStream fs = File.Open(
                    path.ToString(m_pathTable),
                    FileMode.Open,
                    strict ? FileAccess.ReadWrite : FileAccess.Read,
                    FileShare.Read | FileShare.Delete))
            {
                var info = table.RecordContentHash(fs, hash, strict: strict);
                XAssert.AreEqual(hash, info.FileContentInfo.Hash);
                XAssert.IsTrue(info.Identity.Kind == VersionedFileIdentity.IdentityKind.StrongUsn || info.Identity.Kind == VersionedFileIdentity.IdentityKind.Anonymous);
                return(info);
            }
        }
Example #2
0
            public VersionedFileIdentityAndContentInfo RecordHashAndTrackFile(AbsolutePath path)
            {
                Contract.Requires(path.IsValid);

                string expandedPath = path.ToString(m_pathTable);

                using (
                    FileStream fs = File.Open(
                        expandedPath,
                        FileMode.Open,
                        FileAccess.Read,
                        FileShare.Read | FileShare.Delete))
                {
                    var hash          = ContentHashingUtilities.HashContentStream(fs);
                    var versionedFile = m_fileContentTable.RecordContentHash(fs, hash);
                    // ReSharper disable once AssignNullToNotNullAttribute
                    m_fileChangeTracker.TryTrackChangesToFile(fs.SafeFileHandle, expandedPath, versionedFile.Identity, TrackingUpdateMode.Supersede);
                    return(versionedFile);
                }
            }