示例#1
0
        private async Task ExecuteCopyFilePath(string sourcePath, string sourceContentPath,
                                               PathGroupSpec copySpec, RepositoryReference sourceRepo,
                                               RepositoryReference targetRepo, CancellationToken cancelToken)
        {
            RepositoryContentEntry sourceContentEntry;

            try
            {
                sourceContentEntry = await GetRepositoryContentEntry(sourceRepo, sourceContentPath)
                                     .ConfigureAwait(continueOnCapturedContext: false);
            }
            catch (NotFoundException notFoundExcept)
            {
                Logger.LogError(notFoundExcept, $"Unable to get repository contents from {{{nameof(sourceRepo)}}} at path: {{{nameof(sourcePath)}}}", sourceRepo.ToLogString(), sourceContentPath);
                return;
            }
            if (cancelToken.IsCancellationRequested)
            {
                return;
            }
            var sourceContents = sourceContentEntry.Contents;

            foreach (var sourceContent in sourceContents)
            {
                bool unsupportedContentType = !sourceContent.Type.TryParse(out var sourceContentType);
                if (!unsupportedContentType)
                {
                    switch (sourceContentType)
                    {
                    case ContentType.File:
                        await ExecuteCopyFileContent(sourcePath, sourceContent,
                                                     copySpec, sourceRepo, targetRepo, cancelToken)
                        .ConfigureAwait(continueOnCapturedContext: false);

                        break;

                    case ContentType.Dir:
                        await ExecuteCopyFilePath(sourcePath, sourceContent.Path,
                                                  copySpec, sourceRepo, targetRepo, cancelToken)
                        .ConfigureAwait(continueOnCapturedContext: false);

                        break;

                    case ContentType.Symlink:
                        await ExecuteCopyFilePath(sourcePath, sourceContent.Target,
                                                  copySpec, sourceRepo, targetRepo, cancelToken)
                        .ConfigureAwait(continueOnCapturedContext: false);

                        break;

                    default:
                        unsupportedContentType = true;
                        break;
                    }
                }
                if (unsupportedContentType)
                {
                    Logger.LogWarning($"Unsupported content type '{{{nameof(sourceContentType)}}}' in repository {{{nameof(sourceRepo)}}} at path: {{{nameof(sourcePath)}}}", sourceContent.Type, sourceRepo.ToLogString(), sourceContent.Path);
                }
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }
            }
        }
示例#2
0
        private async Task ExecuteCopyFileContent(string sourcePath,
                                                  RepositoryContent sourceContent, PathGroupSpec copySpec,
                                                  RepositoryReference sourceRepo,
                                                  RepositoryReference targetRepo,
                                                  CancellationToken cancelToken)
        {
            var targetPath = await GetTargetPath(sourceContent, copySpec, targetRepo)
                             .ConfigureAwait(continueOnCapturedContext: false);

            if (cancelToken.IsCancellationRequested)
            {
                return;
            }

            RepositoryContentEntry targetEntry;

            try
            {
                targetEntry = await GetRepositoryContentEntry(targetRepo, targetPath)
                              .ConfigureAwait(false);
            }
            catch (NotFoundException) { targetEntry = null; }
            var targetContent = targetEntry?.Leaf;

            bool copyCond = copySpec.Condition?.Evaluate(
                sourcePath, sourceRepo, sourceContent,
                targetPath, targetRepo, targetContent
                ) ?? true;

            if (!copyCond)
            {
                Logger.LogDebug($"Not copying path '{{{nameof(sourcePath)}}}' from {{{nameof(sourceRepo)}}} to '{{{nameof(targetPath)}}}' in {{{nameof(targetRepo)}}}. Condition of type {{conditionType}} evaluated {{conditionValue}}.", sourcePath, sourceRepo.ToLogString(), targetPath, targetRepo.ToLogString(), copySpec.Condition?.GetType(), copyCond);
            }
        }