-
-
Notifications
You must be signed in to change notification settings - Fork 466
opt.: system detect logic to avoid creating useless file #905
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
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors SystemDetector.detect to prioritize Unix detection via ‘uname -a 2>/dev/null’, removes the previous ‘ver’-based Windows check, introduces an ‘echo %OS%’ fallback for Windows, and updates documentation to match the new, side-effect-free logic. Sequence diagram for updated system detection logic in SystemDetector.detectsequenceDiagram
participant Client as SSHClient
participant Detector as SystemDetector
participant Spi as Spi
Note over Detector: Start system detection
Detector->Spi: Check for custom system type
alt Custom system type configured
Detector->Detector: Return custom system type
else No custom system type
Detector->Client: Run 'uname -a 2>/dev/null'
Client->Detector: Return unixResult
alt unixResult contains 'Linux' or 'BSD'
Detector->Detector: Return SystemType.linux or SystemType.bsd
else unixResult does not match
Detector->Client: Run 'echo %OS%'
Client->Detector: Return windowsResult
alt windowsResult contains 'windows'
Detector->Detector: Return SystemType.windows
else Detection fails
Detector->Detector: Return SystemType.linux (default)
end
end
end
Class diagram for updated SystemDetector.detect methodclassDiagram
class SystemDetector {
+static Future<SystemType> detect(SSHClient client, Spi spi)
}
class SSHClient {
+run(String command)
}
class Spi {
+oldId
}
class SystemType {
<<enumeration>>
linux
bsd
windows
}
SystemDetector ..> SSHClient : uses
SystemDetector ..> Spi : uses
SystemDetector ..> SystemType : returns
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `lib/data/helper/system_detector.dart:39` </location>
<code_context>
+
+ // If uname fails, try to detect Windows systems
+ // Use echo %OS% which is Windows-specific and doesn't create files on Unix
+ final windowsResult = await client.run('echo %OS%').string;
+ if (windowsResult.isNotEmpty &&
+ windowsResult.toLowerCase().contains('windows')) {
</code_context>
<issue_to_address>
The use of 'echo %OS%' may not be reliable on all Windows configurations.
%OS% may not always be set or could return unexpected values. Consider checking for both 'Windows' and 'Windows_NT', or use a more robust detection method.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
final windowsResult = await client.run('echo %OS%').string;
if (windowsResult.isNotEmpty &&
windowsResult.toLowerCase().contains('windows')) {
detectedSystemType = SystemType.windows;
dprint('Detected Windows system type for ${spi.oldId}');
return detectedSystemType;
}
=======
final windowsResult = await client.run('echo %OS%').string;
if (windowsResult.isNotEmpty) {
final osValue = windowsResult.trim().toLowerCase();
if (osValue.contains('windows') || osValue.contains('windows_nt')) {
detectedSystemType = SystemType.windows;
dprint('Detected Windows system type for ${spi.oldId}');
return detectedSystemType;
}
}
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
lib/data/helper/system_detector.dart
Outdated
| final windowsResult = await client.run('echo %OS%').string; | ||
| if (windowsResult.isNotEmpty && | ||
| windowsResult.toLowerCase().contains('windows')) { | ||
| detectedSystemType = SystemType.windows; | ||
| dprint('Detected Windows system type for ${spi.oldId}'); | ||
| return detectedSystemType; | ||
| } |
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.
suggestion: The use of 'echo %OS%' may not be reliable on all Windows configurations.
%OS% may not always be set or could return unexpected values. Consider checking for both 'Windows' and 'Windows_NT', or use a more robust detection method.
| final windowsResult = await client.run('echo %OS%').string; | |
| if (windowsResult.isNotEmpty && | |
| windowsResult.toLowerCase().contains('windows')) { | |
| detectedSystemType = SystemType.windows; | |
| dprint('Detected Windows system type for ${spi.oldId}'); | |
| return detectedSystemType; | |
| } | |
| final windowsResult = await client.run('echo %OS%').string; | |
| if (windowsResult.isNotEmpty) { | |
| final osValue = windowsResult.trim().toLowerCase(); | |
| if (osValue.contains('windows') || osValue.contains('windows_nt')) { | |
| detectedSystemType = SystemType.windows; | |
| dprint('Detected Windows system type for ${spi.oldId}'); | |
| return detectedSystemType; | |
| } | |
| } |
Fixes #904
Summary by Sourcery
Optimize remote system detection to avoid creating unnecessary files by running Unix detection via
uname -a 2>/dev/nullfirst and falling back to Windows detection withecho %OS%instead of using thevercommand.Enhancements:
uname -awith stderr suppressed before Windows detectionvercommand withecho %OS%fallback to prevent file creation on remote systemsDocumentation: