private static Result CopyDirectoryWithProgressInternal(FileSystemClient fs, U8Span sourcePath, U8Span destPath, CreateFileOptions options, IProgressReport logger) { string sourcePathStr = sourcePath.ToString(); string destPathStr = destPath.ToString(); Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath, OpenDirectoryMode.All); if (rc.IsFailure()) { return(rc); } try { foreach (DirectoryEntryEx entry in fs.EnumerateEntries(sourcePathStr, "*", SearchOptions.Default)) { string subSrcPath = PathTools.Normalize(PathTools.Combine(sourcePathStr, entry.Name)); string subDstPath = PathTools.Normalize(PathTools.Combine(destPathStr, entry.Name)); if (entry.Type == DirectoryEntryType.Directory) { fs.EnsureDirectoryExists(subDstPath); rc = CopyDirectoryWithProgressInternal(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), options, logger); if (rc.IsFailure()) { return(rc); } } if (entry.Type == DirectoryEntryType.File) { logger?.LogMessage(subSrcPath); rc = fs.CreateOrOverwriteFile(subDstPath, entry.Size, options); if (rc.IsFailure()) { return(rc); } rc = CopyFileWithProgress(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), logger); if (rc.IsFailure()) { return(rc); } } } } finally { if (sourceHandle.IsValid) { fs.CloseDirectory(sourceHandle); } } return(Result.Success); }