/// <inheritdoc /> public async Task <PutResult> PutFileAsync( Context context, HashType hashType, AbsolutePath path, FileRealizationMode realizationMode, CancellationToken cts, UrgencyHint urgencyHint) { if (hashType != RequiredHashType) { return(new PutResult( new ContentHash(hashType), $"BuildCache client requires HashType '{RequiredHashType}'. Cannot take HashType '{hashType}'.")); } try { long contentSize; ContentHash contentHash; using (var hashingStream = new FileStream( path.Path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete, StreamBufferSize)) { contentSize = hashingStream.Length; contentHash = await HashInfoLookup.Find(hashType).CreateContentHasher().GetContentHashAsync(hashingStream).ConfigureAwait(false); } using (var streamToPut = FileStreamUtils.OpenFileStreamForAsync( path.Path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) { BoolResult putSucceeded = await PutLazyStreamAsync( context, contentHash, streamToPut, cts, urgencyHint).ConfigureAwait(false); if (!putSucceeded.Succeeded) { return(new PutResult( putSucceeded, contentHash, $"Failed to add a BlobStore reference to content with hash=[{contentHash}]")); } } return(new PutResult(contentHash, contentSize)); } catch (Exception e) { return(new PutResult(e, new ContentHash(hashType))); } }
/// <inheritdoc /> protected override async Task <PutResult> PutFileCoreAsync( OperationContext context, ContentHash contentHash, AbsolutePath path, FileRealizationMode realizationMode, UrgencyHint urgencyHint, Counter retryCounter) { if (contentHash.HashType != RequiredHashType) { return(new PutResult( contentHash, $"BuildCache client requires HashType '{RequiredHashType}'. Cannot take HashType '{contentHash.HashType}'.")); } try { var fileInfo = new FileInfo(path.Path); var contentSize = fileInfo.Length; using (var streamToPut = FileStreamUtils.OpenFileStreamForAsync( path.Path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) { var putResult = await PutLazyStreamAsync(context, contentHash, streamToPut, urgencyHint).ConfigureAwait(false); if (!putResult.Succeeded) { return(new PutResult( putResult, contentHash, $"Failed to add a BlobStore reference to content with hash=[{contentHash}]")); } } return(new PutResult(contentHash, contentSize)); } catch (Exception e) { return(new PutResult(e, contentHash)); } }