Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public sealed partial class FileSystemProvider : NavigationCmdletProvider,
// to copy an item onto itself.
private const string SelfCopyDataKey = "SelfCopy";

private const int DIRACTIVITYID = 0;
private const int FILEACTIVITYID = 1;

/// <summary>
/// An instance of the PSTraceSource class used for trace output
/// using "FileSystemProvider" as the category.
Expand Down Expand Up @@ -3732,6 +3735,17 @@ private void CopyDirectoryInfoItem(
files = directory.EnumerateFiles(Filter);
}

int total = files.Count();
int current = 0;

ProgressRecord progress = new ProgressRecord(
DIRACTIVITYID,
string.Format(CultureInfo.InvariantCulture, FileSystemProviderStrings.CopyDirActivity, directory.Name),
" "
);
progress.PercentComplete = 0;
progress.RecordType = ProgressRecordType.Processing;

foreach (FileInfo file in files)
{
// Making sure to obey the StopProcessing.
Expand All @@ -3742,6 +3756,15 @@ private void CopyDirectoryInfoItem(

if (file != null)
{
progress.StatusDescription = string.Format(
CultureInfo.InvariantCulture,
FileSystemProviderStrings.CopyItemStatusDescription,
file.Name,
destination
);
progress.PercentComplete = (int)(((double)current / total) * 100);
WriteProgress(progress);

try
{
// CopyFileInfoItem does the WriteItemObject for the new FileInfo
Expand All @@ -3761,8 +3784,12 @@ private void CopyDirectoryInfoItem(
WriteError(new ErrorRecord(accessException, "CopyDirectoryInfoItemUnauthorizedAccessError", ErrorCategory.PermissionDenied, file));
}
}

current++;
}

progress.PercentComplete = 0;

// Now copy all the directories to that directory
foreach (DirectoryInfo childDir in directory.EnumerateDirectories())
{
Expand All @@ -3774,6 +3801,9 @@ private void CopyDirectoryInfoItem(

if (childDir != null)
{
progress.Activity = string.Format(CultureInfo.InvariantCulture, FileSystemProviderStrings.CopyDirActivity, childDir.Name);
WriteProgress(progress);

try
{
CopyDirectoryInfoItem(childDir, destination, recurse, force, ps);
Expand All @@ -3793,6 +3823,9 @@ private void CopyDirectoryInfoItem(
}
}
}

progress.RecordType = ProgressRecordType.Completed;
WriteProgress(progress);
}
}
}
Expand Down Expand Up @@ -3839,8 +3872,18 @@ private void CopyFileInfoItem(FileInfo file, string destinationPath, bool force,
{
if (ShouldProcess(resource, action))
{
var progress = new ProgressRecord(
FILEACTIVITYID,
string.Format(CultureInfo.InvariantCulture, FileSystemProviderStrings.CopyFileActivity, file.Name),
" "
);
progress.RecordType = ProgressRecordType.Processing;
progress.PercentComplete = 0;

try
{
WriteProgress(progress);

if (ps == null)
{
// Now copy the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,13 @@
<data name="TargetCannotBeSubdirectoryOfSource" xml:space="preserve">
<value>Destination path cannot be a subdirectory of the source: {0}.</value>
</data>
<data name="CopyFileActivity" xml:space="preserve">
<value>Copying file {0}</value>
</data>
<data name="CopyDirActivity" xml:space="preserve">
<value>Copying dir {0}</value>
</data>
<data name="CopyItemStatusDescription" xml:space="preserve">
<value>{0} to {1}</value>
</data>
</root>