示例#1
0
 public Task <PinResult> PinAsync(
     Context context,
     ContentHash contentHash,
     CancellationToken cts,
     UrgencyHint urgencyHint = UrgencyHint.Nominal)
 {
     return(PreferredContentSession.PinAsync(context, contentHash, cts, urgencyHint));
 }
示例#2
0
        /// <inheritdoc />
        public Task <PlaceFileResult> PlaceFileAsync(Context context, FullPath path, VfsFilePlacementData placementData, CancellationToken token)
        {
            return(WithOperationContext(context, token, async operationContext =>
            {
                var result = await operationContext.PerformOperationAsync(
                    Tracer,
                    async() =>
                {
                    var virtualPath = ToVirtualPath(placementData, path);

                    var node = Tree.AddFileNode(virtualPath, placementData, path.Path);

                    var vfsPath = _configuration.VfsRootPath / virtualPath;

                    // TODO: Faster path for getting size of file. Also would be good to batch somehow.
                    // Maybe have FileContentManager batch pin files
                    var pinResult = await _placer.PinAsync(context, node.Hash, operationContext.Token);
                    if (pinResult.ContentSize > 0)
                    {
                        node.Size = pinResult.ContentSize;
                    }
                    else
                    {
                        return new PlaceFileResult($"Pin file size = {pinResult.ContentSize}");
                    }

                    if (placementData.AccessMode == FileAccessMode.ReadOnly)
                    {
                        // NOTE: This should cause the placeholder to get created under vfs root
                        _fileSystem.DenyFileWrites(vfsPath);
                    }

                    var result = _fileSystem.CreateHardLink(vfsPath, path, replaceExisting: true);
                    if (result != CreateHardLinkResult.Success)
                    {
                        if (result == CreateHardLinkResult.FailedDestinationDirectoryDoesNotExist)
                        {
                            _fileSystem.CreateDirectory(path.Parent);
                            result = _fileSystem.CreateHardLink(vfsPath, path, replaceExisting: true);
                        }

                        if (result != CreateHardLinkResult.Success)
                        {
                            return new PlaceFileResult($"Failed to create hardlink: {result}");
                        }
                    }

                    return new PlaceFileResult(GetPlaceResultCode(placementData.RealizationMode, placementData.AccessMode), fileSize: pinResult.ContentSize /* Unknown */);
                },
                    caller: "PlaceVirtualFile",
                    extraEndMessage: r => $"Hash={placementData.Hash}");

                if (!result.Succeeded)
                {
                    return await _placer.PlaceFileAsync(context, path, placementData, token);
                }

                return result;
            }));
        }
示例#3
0
        private async Task PinAsync(
            IReadOnlyContentSession session, IReadOnlyCollection <ContentHash> hashes, List <PinResult> results)
        {
            var tasks = hashes.Select(contentHash => Task.Run(async() =>
                                                              await session.PinAsync(_context, contentHash, Token)));

            foreach (var task in tasks.ToList())
            {
                var result = await task;
                results.Add(result);
            }
        }
示例#4
0
 /// <inheritdoc />
 public Task <PinResult> PinAsync(Context context, ContentHash contentHash, CancellationToken cts, UrgencyHint urgencyHint)
 {
     return(_contentReadOnlySession.PinAsync(context, contentHash, cts, urgencyHint));
 }