public Task PutFileCreatesHardLink() { var context = new Context(Logger); return(TestStore(context, Clock, async store => { byte[] bytes = ThreadSafeRandom.GetBytes(ValueSize); ContentHash contentHash = bytes.CalculateHash(ContentHashType); // Verify content doesn't exist yet in store Assert.False(await store.ContainsAsync(context, contentHash, null)); using (var tempDirectory = new DisposableDirectory(FileSystem)) { AbsolutePath pathToContent = tempDirectory.Path / "tempContent.txt"; FileSystem.WriteAllBytes(pathToContent, bytes); // Put the content into the store w/ hard link var r = await store.PutFileAsync(context, pathToContent, FileRealizationMode.Any, ContentHashType, null); Assert.False(r.ContentAlreadyExistsInCache); ContentHash hashFromPut = r.ContentHash; byte[] newBytes = ThreadSafeRandom.GetBytes(10); Assert.False(newBytes.SequenceEqual(bytes)); // Update content // This sneaky approach is only for testing, and is unexpected behavior // in the system that could lead to cache inconsistencies. FileSystem.AllowFileWrites(pathToContent); FileSystem.AllowAttributeWrites(pathToContent); FileSystem.SetFileAttributes(pathToContent, FileAttributes.Normal); FileSystem.WriteAllBytes(pathToContent, newBytes); // Verify new content is now reflected into the cache under the covers var result = await store.OpenStreamAsync(context, hashFromPut, null); byte[] bytesFromGet = await result.Stream.GetBytes(); Assert.True(bytesFromGet.SequenceEqual(newBytes)); } })); }