Skip to content
Merged
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
22 changes: 4 additions & 18 deletions src/Tasks/Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ private bool DoCopyWithRetries(FileState sourceFileState, FileState destinationF
retries++;
Log.LogWarningWithCodeFromResources("Copy.Retrying", sourceFileState.Name,
destinationFileState.Name, retries, RetryDelayMilliseconds, e.Message,
GetLockedFileMessage(destinationFileState.Name));
LockCheck.GetLockedFileMessage(destinationFileState.Name));

// if we have to retry for some reason, wipe the state -- it may not be correct anymore.
destinationFileState.Reset();
Expand All @@ -982,7 +982,7 @@ private bool DoCopyWithRetries(FileState sourceFileState, FileState destinationF
{
// Exception message is logged in caller
Log.LogErrorWithCodeFromResources("Copy.ExceededRetries", sourceFileState.Name,
destinationFileState.Name, Retries, GetLockedFileMessage(destinationFileState.Name));
destinationFileState.Name, Retries, LockCheck.GetLockedFileMessage(destinationFileState.Name));
throw;
}
else
Expand All @@ -996,7 +996,7 @@ private bool DoCopyWithRetries(FileState sourceFileState, FileState destinationF
retries++;
Log.LogWarningWithCodeFromResources("Copy.Retrying", sourceFileState.Name,
destinationFileState.Name, retries, RetryDelayMilliseconds, String.Empty /* no details */,
GetLockedFileMessage(destinationFileState.Name));
LockCheck.GetLockedFileMessage(destinationFileState.Name));

// if we have to retry for some reason, wipe the state -- it may not be correct anymore.
destinationFileState.Reset();
Expand All @@ -1006,7 +1006,7 @@ private bool DoCopyWithRetries(FileState sourceFileState, FileState destinationF
else if (Retries > 0)
{
Log.LogErrorWithCodeFromResources("Copy.ExceededRetries", sourceFileState.Name,
destinationFileState.Name, Retries, GetLockedFileMessage(destinationFileState.Name));
destinationFileState.Name, Retries, LockCheck.GetLockedFileMessage(destinationFileState.Name));
return false;
}
else
Expand All @@ -1019,20 +1019,6 @@ private bool DoCopyWithRetries(FileState sourceFileState, FileState destinationF
return false;
}

/// <summary>
/// Try to get a message to inform the user which processes have a lock on a given file.
/// </summary>
private static string GetLockedFileMessage(string file)
{
string message = string.Empty;
if (NativeMethodsShared.IsWindows)
{
message = LockCheck.GetLockedFileMessage(file);
}

return message;
}

/// <summary>
/// Standard entry point.
/// </summary>
Expand Down
12 changes: 7 additions & 5 deletions src/Tasks/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,18 @@ public override bool Execute()
}
catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
{
string lockedFileMessage = LockCheck.GetLockedFileMessage(file?.ItemSpec ?? string.Empty);
if (retries < Retries)
{
retries++;
Log.LogWarningWithCodeFromResources("Delete.Retrying", file.ToString(), retries, RetryDelayMilliseconds, e.Message);
Log.LogWarningWithCodeFromResources("Delete.Retrying", file.ToString(), retries, RetryDelayMilliseconds, e.Message, lockedFileMessage);

Thread.Sleep(RetryDelayMilliseconds);
continue;
}
else
{
LogError(file, e);
LogError(file, e, lockedFileMessage);
// Add on failure to avoid reattempting
deletedFilesSet.Add(file.ItemSpec);
}
Expand All @@ -173,15 +174,16 @@ public override bool Execute()
/// </summary>
/// <param name="file">The file that wasn't deleted.</param>
/// <param name="e">The exception.</param>
private void LogError(ITaskItem file, Exception e)
/// <param name="lockedFileMessage">Message from <see cref="LockCheck"/>.</param>
private void LogError(ITaskItem file, Exception e, string lockedFileMessage)
{
if (TreatErrorsAsWarnings)
{
Log.LogWarningWithCodeFromResources("Delete.Error", file.ItemSpec, e.Message);
Log.LogWarningWithCodeFromResources("Delete.Error", file.ItemSpec, e.Message, lockedFileMessage);
}
else
{
Log.LogErrorWithCodeFromResources("Delete.Error", file.ItemSpec, e.Message);
Log.LogErrorWithCodeFromResources("Delete.Error", file.ItemSpec, e.Message, lockedFileMessage);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Tasks/FileIO/WriteLinesToFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Build.Eventing;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using Microsoft.Build.Utilities;

#nullable disable

Expand Down Expand Up @@ -148,7 +149,8 @@ public override bool Execute()
}
catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
{
Log.LogErrorWithCodeFromResources("WriteLinesToFile.ErrorOrWarning", File.ItemSpec, e.Message);
string lockedFileMessage = LockCheck.GetLockedFileMessage(File.ItemSpec);
Log.LogErrorWithCodeFromResources("WriteLinesToFile.ErrorOrWarning", File.ItemSpec, e.Message, lockedFileMessage);
success = false;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Tasks/GenerateManifestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,7 @@ private bool WriteManifest()
}
catch (Exception ex)
{
string lockedFileMessage = string.Empty;
if (NativeMethodsShared.IsWindows)
{
lockedFileMessage = LockCheck.GetLockedFileMessage(OutputManifest.ItemSpec);
}
string lockedFileMessage = LockCheck.GetLockedFileMessage(OutputManifest.ItemSpec);
Log.LogErrorWithCodeFromResources("GenerateManifest.WriteOutputManifestFailed", OutputManifest.ItemSpec, ex.Message, lockedFileMessage);

return false;
Expand Down
1 change: 0 additions & 1 deletion src/Tasks/Microsoft.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@
<Compile Include="LC.cs" />
<Compile Include="ListOperators\FindUnderPath.cs" />
<Compile Include="ListOperators\RemoveDuplicates.cs" />
<Compile Include="LockCheck.cs" />
<Compile Include="MakeDir.cs" />
<Compile Include="ManifestUtil\*.cs" Exclude="ManifestUtil\CngLightup.cs" />
<Compile Include="Message.cs" />
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public override bool Execute()
}
catch (ArgumentException e)
{
Log.LogErrorWithCodeFromResources("Move.Error", SourceFiles[i].ItemSpec, DestinationFolder.ItemSpec, e.Message);
Log.LogErrorWithCodeFromResources("Move.Error", SourceFiles[i].ItemSpec, DestinationFolder.ItemSpec, e.Message, string.Empty);

// Clear the outputs.
DestinationFiles = Array.Empty<ITaskItem>();
Expand Down Expand Up @@ -169,7 +169,8 @@ public override bool Execute()
}
catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
{
Log.LogErrorWithCodeFromResources("Move.Error", sourceFile, destinationFile, e.Message);
string lockedFileMessage = LockCheck.GetLockedFileMessage(sourceFile);
Log.LogErrorWithCodeFromResources("Move.Error", sourceFile, destinationFile, e.Message, lockedFileMessage);
success = false;

// Continue with the rest of the list
Expand Down
27 changes: 12 additions & 15 deletions src/Tasks/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@
</data>
<data name="Copy.Retrying">
<value>MSB3026: Could not copy "{0}" to "{1}". Beginning retry {2} in {3}ms. {4} {5}</value>
<comment>{StrBegin="MSB3026: "} LOCALIZATION: {0} and {1} are paths. {2} and {3} are numbers. {4} is an optional localized message. {5} is either empty or a string from Copy.FileLocked ("The file is locked by: "{0}"")</comment>
<comment>{StrBegin="MSB3026: "} LOCALIZATION: {0} and {1} are paths. {2} and {3} are numbers. {4} is an optional localized message. {5} is either empty or a string from Utilities LockCheck.FileLocked ("The file is locked by: "{0}"")</comment>
</data>
<data name="Copy.ExceededRetries">
<value>MSB3027: Could not copy "{0}" to "{1}". Exceeded retry count of {2}. Failed. {3}</value>
<comment>{StrBegin="MSB3027: "} LOCALIZATION: {0} and {1} are paths. {2} is a number. {3} is either empty or a string from Copy.FileLocked ("The file is locked by: "{0}"")</comment>
<comment>{StrBegin="MSB3027: "} LOCALIZATION: {0} and {1} are paths. {2} is a number. {3} is either empty or a string from Utilities LockCheck.FileLocked ("The file is locked by: "{0}"")</comment>
</data>
<data name="Copy.InvalidRetryCount">
<value>MSB3028: {0} is an invalid retry count. Value must not be negative.</value>
Expand All @@ -293,9 +293,6 @@
<value>MSB3030: Could not copy the file "{0}" because it was not found.</value>
<comment>{StrBegin="MSB3030: "} LOCALIZATION: {0} is a number.</comment>
</data>
<data name="Task.FileLocked">
<value>The file is locked by: "{0}"</value>
</data>

<!--
The CreateItem message bucket is: MSB3031 - MSB3040
Expand Down Expand Up @@ -366,15 +363,15 @@
<value>Deleting file "{0}".</value>
</data>
<data name="Delete.Error">
<value>MSB3061: Unable to delete file "{0}". {1}</value>
<value>MSB3061: Unable to delete file "{0}". {1} {2}</value>
<comment>{StrBegin="MSB3061: "}</comment>
</data>
<data name="Delete.SkippingNonexistentFile">
<value>File "{0}" doesn't exist. Skipping.</value>
</data>
<data name="Delete.Retrying">
<value>MSB3062: Could not delete file "{0}". Beginning retry {1} in {2}ms. {3}</value>
<comment>{StrBegin="MSB3062: "} LOCALIZATION: {0} are paths. {1} and {2} are numbers. {3} is an optional localized message.</comment>
<value>MSB3062: Could not delete file "{0}". Beginning retry {1} in {2}ms. {3} {4}</value>
<comment>{StrBegin="MSB3062: "} LOCALIZATION: {0} are paths. {1} and {2} are numbers. {3} is an optional localized message, {4} is message from LockCheck.</comment>
</data>
<data name="Delete.InvalidRetryCount">
<value>MSB3028: {0} is an invalid retry count. Value must not be negative.</value>
Expand Down Expand Up @@ -1239,7 +1236,7 @@
<comment>{StrBegin="MSB3676: "}</comment>
</data>
<data name="Move.Error">
<value>MSB3677: Unable to move file "{0}" to "{1}". {2}</value>
<value>MSB3677: Unable to move file "{0}" to "{1}". {2} {3}</value>
<comment>{StrBegin="MSB3677: "}</comment>
</data>
<data name="Move.ExactlyOneTypeOfDestination">
Expand Down Expand Up @@ -2094,15 +2091,15 @@
<comment>{StrBegin="MSB3371: "}</comment>
</data>
<data name="Touch.CannotMakeFileWritable">
<value>MSB3372: The file "{0}" cannot be made writable. {1}</value>
<value>MSB3372: The file "{0}" cannot be made writable. {1} {2}</value>
<comment>{StrBegin="MSB3372: "}</comment>
</data>
<data name="Touch.CannotRestoreAttributes">
<value>MSB3373: The attributes on file "{0}" cannot be restored to their original value. {1}</value>
<comment>{StrBegin="MSB3373: "}</comment>
</data>
<data name="Touch.CannotTouch">
<value>MSB3374: The last access/last write time on file "{0}" cannot be set. {1}</value>
<value>MSB3374: The last access/last write time on file "{0}" cannot be set. {1} {2}</value>
<comment>{StrBegin="MSB3374: "}</comment>
</data>
<data name="Touch.CreatingFile">
Expand Down Expand Up @@ -2188,7 +2185,7 @@
If this bucket overflows, pls. contact 'vsppbdev'.
-->
<data name="WriteLinesToFile.ErrorOrWarning">
<value>MSB3491: Could not write lines to file "{0}". {1}</value>
<value>MSB3491: Could not write lines to file "{0}". {1} {2}</value>
<comment>{StrBegin="MSB3491: "}</comment>
</data>
<data name="WriteLinesToFile.ErrorReadingFile">
Expand Down Expand Up @@ -2430,7 +2427,7 @@
<comment>{StrBegin="MSB3712: "}</comment>
</data>
<data name="WriteCodeFragment.CouldNotWriteOutput" xml:space="preserve">
<value>MSB3713: The file "{0}" could not be created. {1}</value>
<value>MSB3713: The file "{0}" could not be created. {1} {2}</value>
<comment>{StrBegin="MSB3713: "}</comment>
</data>
<data name="WriteCodeFragment.SkippedNumberedParameter" xml:space="preserve">
Expand Down Expand Up @@ -2871,7 +2868,7 @@
<comment>{StrBegin="MSB3934: "}</comment>
</data>
<data name="Unzip.ErrorCouldNotMakeFileWriteable">
<value>MSB3935: Failed to unzip file "{0}" because destination file "{1}" is read-only and could not be made writable. {2}</value>
<value>MSB3935: Failed to unzip file "{0}" because destination file "{1}" is read-only and could not be made writable. {2} {3}</value>
<comment>{StrBegin="MSB3935: "}</comment>
</data>
<data name="Unzip.ErrorCouldNotExtractFile">
Expand Down Expand Up @@ -2912,7 +2909,7 @@
<comment>{StrBegin="MSB3942: "}</comment>
</data>
<data name="ZipDirectory.ErrorFailed">
<value>MSB3943: Failed to zip directory "{0}" to file "{1}". {2}</value>
<value>MSB3943: Failed to zip directory "{0}" to file "{1}". {2} {3}</value>
<comment>{StrBegin="MSB3943: "}</comment>
</data>
<data name="ZipDirectory.Comment">
Expand Down
Loading