-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
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 guard condition logic is inverted. When
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+220
to
+228
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 Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||
|
||||||||||||||||||||||
try task.run() | ||||||||||||||||||||||
task.waitUntilExit() | ||||||||||||||||||||||
let data = pipe.fileHandleForReading.readDataToEndOfFile() | ||||||||||||||||||||||
return String(data: data, encoding: .utf8) | ||||||||||||||||||||||
return String(data: accumulatedOutput + data, encoding: .utf8) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public func appendCommonBinPaths(path: String) -> String { | ||||||||||||||||||||||
|
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
append
method returnsVoid
, but this is being used in areturn
statement. This line should just beaccumulatedOutput.append(data)
without the return keyword.Copilot uses AI. Check for mistakes.