Ejemplo n.º 1
0
        private async Task <ExistenceResponse> CheckFileExistsAsync(ExistenceRequest request, CancellationToken token)
        {
            OperationStarted();

            DateTime    startTime    = DateTime.UtcNow;
            Context     cacheContext = new Context(new Guid(request.TraceId), Logger);
            HashType    type         = (HashType)request.HashType;
            ContentHash hash         = request.ContentHash.ToContentHash((HashType)request.HashType);

            // Iterate through all known stores, looking for content in each.
            // In most of our configurations there is just one store anyway,
            // and doing this means both we can callers don't have
            // to deal with cache roots and drive letters.

            foreach (KeyValuePair <string, IContentStore> entry in _contentStoreByCacheName)
            {
                if (entry.Value is IStreamStore store)
                {
                    FileExistenceResult result = await store.CheckFileExistsAsync(cacheContext, hash);

                    if (result.Succeeded)
                    {
                        return(new ExistenceResponse {
                            Header = ResponseHeader.Success(startTime)
                        });
                    }
                }
            }

            return(new ExistenceResponse {
                Header = ResponseHeader.Failure(startTime, $"{hash.ToShortString()} not found in the cache")
            });
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task <FileExistenceResult> CheckFileExistsAsync(AbsolutePath path, TimeSpan timeout, CancellationToken cancellationToken)
        {
            // Extract host and contentHash from sourcePath
            (string host, ContentHash contentHash) = ExtractHostHashFromAbsolutePath(path);

            FileExistenceResult fileExistenceResult = null;

            using (var clientWrapper = await _clientCache.CreateAsync(host, _grpcPort, _useCompression))
            {
                fileExistenceResult = await clientWrapper.Value.CheckFileExistsAsync(_context, contentHash);
            }

            return(fileExistenceResult);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public async Task <FileExistenceResult> CheckFileExistsAsync(AbsolutePath path, TimeSpan timeout, CancellationToken cancellationToken)
        {
            // Extract host and contentHash from sourcePath
            (string host, ContentHash contentHash) = ExtractHostHashFromAbsolutePath(path);

            FileExistenceResult fileExistenceResult = null;

            using (var client = GrpcCopyClient.Create(host, _grpcPort))
            {
                fileExistenceResult = await client.CheckFileExistsAsync(_context, contentHash);
            }

            return(fileExistenceResult);
        }