Skip to content

Commit

Permalink
merger: fixed non-sequential logging
Browse files Browse the repository at this point in the history
  • Loading branch information
stojy committed Sep 5, 2023
1 parent 09239c9 commit 290abb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions ClrVpin/Merger/MergerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ void LogFuzzyMatch()
{
fixFileType = FixFileTypeEnum.Ignored;

// added lock to ensure the logs are not intermingled from other concurrent access, i.e. we want to keep these log lines together
Monitor.Enter(_processMergeLoggingLock);

if (!ShouldIgnore(localGame.Game, hit, sourceFileInfo, destinationFileInfo ?? correctDestinationFileInfo, LogFuzzyMatch))
{
fixFileType = FixFileTypeEnum.Merged;
Expand All @@ -141,6 +144,8 @@ void LogFuzzyMatch()
LogFuzzyMatch();
FileUtils.Merge(hit.Path, destinationFileName, hit.Type, hit.ContentType, shouldDeleteSource, preserveDateModified, contentType.KindredExtensionsList, backupFile => hit.Path = backupFile);
}

Monitor.Exit(_processMergeLoggingLock);
}

return new FileDetail(hit.ContentTypeEnum, hit.Type, fixFileType, sourceFileInfo.Name, hit.Size ?? 0);
Expand Down Expand Up @@ -182,9 +187,6 @@ private static bool ProcessIgnore(Game game, string ignoreCriteriaDescription, H
private static bool ProcessIgnore(Game game, string ignoreCriteriaDescription, HitTypeEnum hitTypeEnum, ContentTypeEnum contentTypeEnum, Hit hit, FileSystemInfo sourceFileInfo,
FileSystemInfo destinationFileInfo, Action logAction = null)
{
// added lock to ensure the logs are not intermingled from other concurrent access, i.e. we want to keep these log lines together
Monitor.Enter(_processIgnoreLoggingLock);

var prefix = _settings.Merger.DeleteIgnoredFiles ? "Removing (delete ignored selected)" : "Skipping (ignore option selected)";
Logger.Info($"{prefix}.. table: {game?.Name ?? "n/a"}, description: {game?.Description ?? "n/a"}, type: {hitTypeEnum.GetDescription()}, " +
$"content: {contentTypeEnum.GetDescription()}, ignore option: {ignoreCriteriaDescription}, delete ignored: {_settings.Merger.DeleteIgnoredFiles}");
Expand All @@ -206,8 +208,6 @@ private static bool ProcessIgnore(Game game, string ignoreCriteriaDescription, H
Logger.Debug($"- ignored..\n source: {FileUtils.GetFileInfoStatistics(sourceFileInfo.FullName)}\n dest: {FileUtils.GetFileInfoStatistics(destinationFileInfo?.FullName)}");
}

Monitor.Exit(_processIgnoreLoggingLock);

return true;
}

Expand Down Expand Up @@ -241,7 +241,7 @@ private static void RemoveUnmatchedIgnored(IList<FileDetail> unmatchedFiles, Act
});
}

private static readonly object _processIgnoreLoggingLock = new();
private static readonly object _processMergeLoggingLock = new();

private static readonly Models.Settings.Settings _settings;
}
Expand Down
2 changes: 1 addition & 1 deletion ClrVpin/Shared/Utils/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private static void Rename(string sourcePath, string newPath, HitTypeEnum hitTyp
Rename(sourcePath, newPath);
}

[SuppressMessage("ReSharper", "UnusedParameter.Local")]
// ReSharper disable once UnusedParameter.Local
private static void Merge(string sourcePath, string destinationPath, HitTypeEnum hitTypeEnum, string contentType, bool deleteSource, bool preserveDateModified, Action<string> backupAction = null)
{
// backup the existing file (if any) before overwriting
Expand Down

0 comments on commit 290abb7

Please sign in to comment.