using EvilEngine.Mounts; namespace EvilEngine.Conversion; public sealed class FileStamp { private readonly Lazy _hash; private volatile bool _forgotten; internal FileStamp(IFileSource files, VirtualPath path, long length) { Path = path; Length = length; _hash = new Lazy(() => { if (_forgotten) throw new InvalidOperationException( $"'{path}' changed in its namespace before anything asked for the hash of the copy that was read."); if (!files.TryOpenAccess(path, out var access)) throw new FileNotFoundException($"'{path}' left its namespace before it was hashed.", path.Value); using (access) { if (access.Length != length) throw new InvalidOperationException( $"'{path}' is {access.Length} bytes, not the {length} it was read at, so its hash isn't the one read."); return ConversionContext.Hash(access); } }); } public VirtualPath Path { get; } public long Length { get; } public bool Hashed => _hash.IsValueCreated; public string Hash => _hash.Value; internal void Forget() { _forgotten = true; } }