opt.: system detect logic to avoid creating useless file#905
Merged
lollipopkit merged 2 commits intomainfrom Sep 9, 2025
Merged
opt.: system detect logic to avoid creating useless file#905lollipopkit merged 2 commits intomainfrom
lollipopkit merged 2 commits intomainfrom
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.
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
Comment on lines
+39
to
+45
| 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.
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.
Suggested change
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: