-
Notifications
You must be signed in to change notification settings - Fork 0
Fix RepositoryPaths.BuildVariables temp file deletion issue #151
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,10 +15,44 @@ public static class RepositoryPaths | |||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||
/// Holds the key value pairs of the build variables that this class can use. | ||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||
public static ReadOnlyDictionary<string, string?> BuildVariables { get; } = new(File.ReadAllLines(Path.Combine(Path.GetTempPath(), BuildVariableFileName)) | ||||||||||||||||||||||||||||||||||||
.Select(line => line.Split("::")) | ||||||||||||||||||||||||||||||||||||
.ToDictionary(split => split[0].Trim(), | ||||||||||||||||||||||||||||||||||||
split => !string.IsNullOrEmpty(split[1]) ? split[1].Trim() : null)); | ||||||||||||||||||||||||||||||||||||
public static ReadOnlyDictionary<string, string?> BuildVariables | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
get | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
if (_buildVariables == null) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
_buildVariables = LoadBuildVariables(); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return _buildVariables; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private static ReadOnlyDictionary<string, string?>? _buildVariables; | ||||||||||||||||||||||||||||||||||||
Comment on lines
+18
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lazy initialization of _buildVariables isn’t thread-safe. Consider using Lazy or a lock to prevent race conditions if BuildVariables is accessed concurrently.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
private static ReadOnlyDictionary<string, string?> LoadBuildVariables() | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
try | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
string filePath = Path.Combine(Path.GetTempPath(), BuildVariableFileName); | ||||||||||||||||||||||||||||||||||||
var lines = File.ReadAllLines(filePath); | ||||||||||||||||||||||||||||||||||||
var dictionary = lines | ||||||||||||||||||||||||||||||||||||
.Select(line => line.Split("::")) | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Split("::") splits on individual ':' characters rather than the literal "::" token. If the intent is to split on "::", use Split(new[] { "::" }, StringSplitOptions.None) for correct behavior.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||
.ToDictionary(split => split[0].Trim(), | ||||||||||||||||||||||||||||||||||||
split => !string.IsNullOrEmpty(split[1]) ? split[1].Trim() : null); | ||||||||||||||||||||||||||||||||||||
return new ReadOnlyDictionary<string, string?>(dictionary); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
catch (FileNotFoundException) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
// Return empty dictionary if the build variables file doesn't exist | ||||||||||||||||||||||||||||||||||||
// This can happen when the temp file is cleaned up by the OS | ||||||||||||||||||||||||||||||||||||
return new ReadOnlyDictionary<string, string?>(new Dictionary<string, string?>()); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
catch (DirectoryNotFoundException) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
// Return empty dictionary if the temp directory doesn't exist | ||||||||||||||||||||||||||||||||||||
return new ReadOnlyDictionary<string, string?>(new Dictionary<string, string?>()); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+48
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Allocating a new empty dictionary on each catch can be wasteful. Consider defining a static readonly empty ReadOnlyDictionary to reuse and avoid repeated allocations.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||
/// Finds the root of the repository by looking for the directory containing the .git directory. | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using reflection to reset a private static field makes the test brittle. Consider adding an internal reset method or using a public test hook to clear the cache more robustly.
Copilot uses AI. Check for mistakes.