Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress to Copy-Item #18735

Merged
merged 15 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move calculation of totals to a new thread
  • Loading branch information
SteveL-MSFT committed Jan 25, 2023
commit 30db5ed906f8c06c0095e65d88bea13ce79338c3
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ internal static bool IsMinimalProgressRenderingEnabled()

sb.Append(secRemain);

if (PercentComplete > 0 && PercentComplete < 100 && barWidth > 0)
if (PercentComplete >= 0 && PercentComplete < 100 && barWidth > 0)
{
int barLength = PercentComplete * barWidth / 100;
if (barLength >= barWidth)
Expand Down
22 changes: 12 additions & 10 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Security;
using System.Security.AccessControl;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.XPath;

Expand Down Expand Up @@ -3550,25 +3551,26 @@ private static bool DirectoryInfoHasChildItems(DirectoryInfo directory)
}
else // Copy-Item local
{
var progress = new ProgressRecord(COPY_FILE_ACTIVITY_ID, " ", " ");
if (Context != null)
{
if (Context.ExecutionContext.SessionState.PSVariable.Get(SpecialVariables.ProgressPreferenceVarPath.ToString()).Value is ActionPreference progressPreference)
{
if (progressPreference == ActionPreference.Continue)
{
progress.Activity = FileSystemProviderStrings.CollectingTotalActivity;
progress.PercentComplete = 0;
progress.RecordType = ProgressRecordType.Processing;
WriteProgress(progress);
GetTotalFiles(path, recurse);
// we use a thread to gather the total files so that copying can start right away
Thread t = new Thread(() =>
{
GetTotalFiles(path, recurse);
});
t.Start();
}
}
}

CopyItemLocalOrToSession(path, destinationPath, recurse, Force, null);
if (_totalFiles > 0)
{
var progress = new ProgressRecord(COPY_FILE_ACTIVITY_ID, " ", " ");
progress.RecordType = ProgressRecordType.Completed;
WriteProgress(progress);
}
Expand All @@ -3590,15 +3592,15 @@ private void GetTotalFiles(string path, bool recurse)
var dir = new DirectoryInfo(path);
foreach (var file in dir.EnumerateFiles())
{
_totalFiles++;
_totalBytes += file.Length;
Interlocked.Add(ref _totalFiles, 1);
Interlocked.Add(ref _totalBytes, file.Length);
SteveL-MSFT marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
{
var file = new FileInfo(path);
_totalFiles++;
_totalBytes += file.Length;
Interlocked.Add(ref _totalFiles, 1);
Interlocked.Add(ref _totalBytes, file.Length);
}
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,4 @@
<data name="CopyingLocalBytesStatus" xml:space="preserve">
<value>{0} MB of {1} MB</value>
</data>
<data name="CollectingTotalActivity" xml:space="preserve">
<value>Collecting total files</value>
</data>
</root>