Skip to content

Conversation

@lollipopkit
Copy link
Owner

@lollipopkit lollipopkit commented Sep 9, 2025

Fixes #904

Summary by Sourcery

Optimize remote system detection to avoid creating unnecessary files by running Unix detection via uname -a 2>/dev/null first and falling back to Windows detection with echo %OS% instead of using the ver command.

Enhancements:

  • Reorder detection sequence to prefer Unix/BSD via uname -a with stderr suppressed before Windows detection
  • Replace Windows ver command with echo %OS% fallback to prevent file creation on remote systems

Documentation:

  • Update method doc comments to reflect the new detection command order

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 9, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors 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.detect

sequenceDiagram
    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
Loading

Class diagram for updated SystemDetector.detect method

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Reorder and optimize detection logic to avoid creating files
  • Swap detection order to try ‘uname -a 2>/dev/null’ first
  • Remove the ‘ver 2>nul’ Windows check
  • Add Windows fallback using ‘echo %OS%’
  • Redirect errors on ‘uname’ to prevent file creation
lib/data/helper/system_detector.dart
Update documentation comments to reflect new logic
  • Adjust the numbered list in the class doc comment
  • Clarify commands and detection order in comment text
lib/data/helper/system_detector.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#904 Prevent creation of 'nul' file in the server user's path when using server box.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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;
}
Copy link

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.

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;
}
}

@lollipopkit lollipopkit merged commit 194774d into main Sep 9, 2025
1 check passed
@lollipopkit lollipopkit deleted the lollipopkit/issue904 branch September 9, 2025 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

使用server box会在服务器用户路径下创建nul文件

2 participants