mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt.: system detect logic to avoid creating useless file (#905)
This commit is contained in:
1
.github/workflows/analysis.yml
vendored
1
.github/workflows/analysis.yml
vendored
@@ -32,7 +32,6 @@ jobs:
|
|||||||
path: |
|
path: |
|
||||||
${{ env.PUB_CACHE }}
|
${{ env.PUB_CACHE }}
|
||||||
~/.pub-cache
|
~/.pub-cache
|
||||||
${{ runner.tool_cache }}/flutter
|
|
||||||
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
|
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-pub-
|
${{ runner.os }}-pub-
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ class SystemDetector {
|
|||||||
///
|
///
|
||||||
/// First checks if a custom system type is configured in [spi].
|
/// First checks if a custom system type is configured in [spi].
|
||||||
/// If not, attempts to detect the system by running commands:
|
/// If not, attempts to detect the system by running commands:
|
||||||
/// 1. 'ver' command to detect Windows
|
/// 1. 'uname -a' command to detect Linux/BSD/Darwin
|
||||||
/// 2. 'uname -a' command to detect Linux/BSD/Darwin
|
/// 2. 'ver' command to detect Windows (if uname fails)
|
||||||
///
|
///
|
||||||
/// Returns [SystemType.linux] as default if detection fails.
|
/// Returns [SystemType.linux] as default if detection fails.
|
||||||
static Future<SystemType> detect(SSHClient client, Spi spi) async {
|
static Future<SystemType> detect(SSHClient client, Spi spi) async {
|
||||||
@@ -22,17 +22,8 @@ class SystemDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to detect Windows systems first (more reliable detection)
|
// Try to detect Unix/Linux/BSD systems first (more reliable and doesn't create files)
|
||||||
final powershellResult = await client.run('ver 2>nul').string;
|
final unixResult = await client.run('uname -a 2>/dev/null').string;
|
||||||
if (powershellResult.isNotEmpty &&
|
|
||||||
(powershellResult.contains('Windows') || powershellResult.contains('NT'))) {
|
|
||||||
detectedSystemType = SystemType.windows;
|
|
||||||
dprint('Detected Windows system type for ${spi.oldId}');
|
|
||||||
return detectedSystemType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to detect Unix/Linux/BSD systems
|
|
||||||
final unixResult = await client.run('uname -a').string;
|
|
||||||
if (unixResult.contains('Linux')) {
|
if (unixResult.contains('Linux')) {
|
||||||
detectedSystemType = SystemType.linux;
|
detectedSystemType = SystemType.linux;
|
||||||
dprint('Detected Linux system type for ${spi.oldId}');
|
dprint('Detected Linux system type for ${spi.oldId}');
|
||||||
@@ -42,6 +33,15 @@ class SystemDetector {
|
|||||||
dprint('Detected BSD system type for ${spi.oldId}');
|
dprint('Detected BSD system type for ${spi.oldId}');
|
||||||
return detectedSystemType;
|
return detectedSystemType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If uname fails, try to detect Windows systems
|
||||||
|
final powershellResult = await client.run('ver 2>nul').string;
|
||||||
|
if (powershellResult.isNotEmpty &&
|
||||||
|
(powershellResult.contains('Windows') || powershellResult.contains('NT'))) {
|
||||||
|
detectedSystemType = SystemType.windows;
|
||||||
|
dprint('Detected Windows system type for ${spi.oldId}');
|
||||||
|
return detectedSystemType;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Loggers.app.warning('System detection failed for ${spi.oldId}: $e');
|
Loggers.app.warning('System detection failed for ${spi.oldId}: $e');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user