-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix reading long files #549
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
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -198,8 +198,8 @@ public class SystemUtils { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public static func executeCommand( | ||||||||||||||||||||||
| inDirectory directory: String = NSHomeDirectory(), | ||||||||||||||||||||||
| path: String, | ||||||||||||||||||||||
| inDirectory directory: String = NSHomeDirectory(), | ||||||||||||||||||||||
| path: String, | ||||||||||||||||||||||
| arguments: [String] | ||||||||||||||||||||||
| ) throws -> String? { | ||||||||||||||||||||||
| let task = Process() | ||||||||||||||||||||||
|
|
@@ -216,11 +216,21 @@ public class SystemUtils { | |||||||||||||||||||||
| task.arguments = arguments | ||||||||||||||||||||||
| task.standardOutput = pipe | ||||||||||||||||||||||
| task.currentDirectoryURL = URL(fileURLWithPath: directory) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var accumulatedOutput = Data() | ||||||||||||||||||||||
| pipe.fileHandleForReading.readabilityHandler = { handle in | ||||||||||||||||||||||
| let data = handle.availableData | ||||||||||||||||||||||
| guard data.isEmpty else { // End of file | ||||||||||||||||||||||
| return accumulatedOutput.append(data) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| handle.readabilityHandler = nil // Stop observing | ||||||||||||||||||||||
|
Comment on lines
+223
to
+227
|
||||||||||||||||||||||
| guard data.isEmpty else { // End of file | |
| return accumulatedOutput.append(data) | |
| } | |
| handle.readabilityHandler = nil // Stop observing | |
| guard !data.isEmpty else { // End of file | |
| handle.readabilityHandler = nil // Stop observing | |
| return | |
| } | |
| accumulatedOutput.append(data) |
Copilot
AI
Oct 2, 2025
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.
The accumulatedOutput variable is accessed from both the main thread and the readability handler callback without synchronization. This creates a potential race condition. Consider using a concurrent queue with barriers or other synchronization mechanism to ensure thread-safe access.
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.
The
appendmethod returnsVoid, but this is being used in areturnstatement. This line should just beaccumulatedOutput.append(data)without the return keyword.