Skip to content

Commit

Permalink
fix: mac path error
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Jun 20, 2024
1 parent 3f62a38 commit ce949ac
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 32 deletions.
11 changes: 7 additions & 4 deletions src/MDriveSync.Core/Services/AliyunJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,12 +1862,15 @@ private void AliyunDriveInitialize()
var sw = new Stopwatch();
sw.Start();
var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
_log.LogInformation($"Linux: {isLinux}");
var isLinux = GlobalConfiguration.IsLinux();
var isMacOS = GlobalConfiguration.IsMacOS();
var isWindows = GlobalConfiguration.IsWindows();
_log.LogInformation($"Linux: {isLinux}, macOS: {isMacOS}, Windows: {isWindows}");
// 处理 RestoreRootPath
if (isLinux && (_jobConfig.Restore?.StartsWith("/") ?? false))
if ((isLinux || isMacOS) && (_jobConfig.Restore?.StartsWith("/") ?? false))
{
_localRestorePath = "/" + _jobConfig.Restore.TrimPath();
}
Expand All @@ -1883,7 +1886,7 @@ private void AliyunDriveInitialize()
_jobConfig.Sources.Clear();
foreach (var item in sources)
{
if (isLinux && item.StartsWith('/'))
if ((isLinux || isMacOS) && item.StartsWith('/'))
{
var dir = new DirectoryInfo(item);
if (!dir.Exists)
Expand Down
38 changes: 11 additions & 27 deletions src/MDriveSync.Core/Services/LocalStorageJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,24 +1633,6 @@ private LocalStorageFileInfo GetLocalDirectory(string dirFullPath, string rootDi
return ld;
}

/// <summary>
/// 判断是否是 Windows 系统
/// </summary>
/// <returns></returns>
private static bool IsWindows()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}

/// <summary>
/// 判断是否是 Linux 系统
/// </summary>
/// <returns></returns>
private static bool IsLinux()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
}

#endregion 私有方法

#region 本地存储
Expand All @@ -1674,12 +1656,14 @@ private void Initialize()
var sw = new Stopwatch();
sw.Start();
var isLinux = IsLinux();
var isLinux = GlobalConfiguration.IsLinux();
var isMacOS = GlobalConfiguration.IsMacOS();
var isWindows = GlobalConfiguration.IsWindows();
_log.LogInformation($"Linux: {isLinux}");
_log.LogInformation($"Linux: {isLinux}, macOS: {isMacOS}, Windows: {isWindows}");
// 处理 RestoreRootPath
if (isLinux && (_jobConfig.Restore?.StartsWith("/") ?? false))
if ((isLinux || isMacOS) && (_jobConfig.Restore?.StartsWith("/") ?? false))
{
_tartgetRestoreRootPath = "/" + _jobConfig.Restore.TrimPath();
}
Expand All @@ -1689,7 +1673,7 @@ private void Initialize()
}
// 处理 TargetRootPath
if (isLinux && (_jobConfig.Target?.StartsWith("/") ?? false))
if ((isLinux || isMacOS) && (_jobConfig.Target?.StartsWith("/") ?? false))
{
_targetSaveRootPath = "/" + _jobConfig.Target.TrimPath();
}
Expand All @@ -1703,7 +1687,7 @@ private void Initialize()
_jobConfig.Sources.Clear();
foreach (var item in sources)
{
if (isLinux && item.StartsWith('/'))
if ((isLinux || isMacOS) && item.StartsWith('/'))
{
var dir = new DirectoryInfo(item);
if (!dir.Exists)
Expand Down Expand Up @@ -1790,7 +1774,7 @@ private void SyncVerify()
try
{
// 如果是 windows 平台并且启动回收站
if (IsWindows() && _jobConfig.IsRecycleBin)
if (GlobalConfiguration.IsWindows() && _jobConfig.IsRecycleBin)
{
// 删除文件夹到系统回收站
// 将文件移动到回收站
Expand Down Expand Up @@ -1840,7 +1824,7 @@ private void SyncVerify()
{
try
{
if (IsWindows() && _jobConfig.IsRecycleBin)
if (GlobalConfiguration.IsWindows() && _jobConfig.IsRecycleBin)
{
// 删除文件到系统回收站
// 将文件移动到回收站
Expand Down Expand Up @@ -1889,7 +1873,7 @@ private void SyncVerify()
{
try
{
if (IsWindows() && _jobConfig.IsRecycleBin)
if (GlobalConfiguration.IsWindows() && _jobConfig.IsRecycleBin)
{
// 删除文件到系统回收站
// 将文件移动到回收站
Expand Down Expand Up @@ -1934,7 +1918,7 @@ private void SyncVerify()
{
try
{
if (IsWindows() && _jobConfig.IsRecycleBin)
if (GlobalConfiguration.IsWindows() && _jobConfig.IsRecycleBin)
{
// 删除文件到系统回收站
// 将文件移动到回收站
Expand Down
33 changes: 32 additions & 1 deletion src/MDriveSync.Infrastructure/GlobalConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MDriveSync.Infrastructure
using System.Runtime.InteropServices;

namespace MDriveSync.Infrastructure
{
/// <summary>
/// 全局配置
Expand All @@ -9,5 +11,34 @@ public class GlobalConfiguration
/// 网站配置为演示模式
/// </summary>
public static bool? IsDemoMode { get; set; }

/// <summary>
/// 判断是否是 Windows 系统
/// </summary>
/// <returns></returns>
public static bool IsWindows()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}

/// <summary>
/// 判断是否是 Linux 系统
/// </summary>
/// <returns></returns>
public static bool IsLinux()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
}

/// <summary>
/// 判断是否是 macOS 系统
/// </summary>
/// <returns></returns>
public static bool IsMacOS()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
|| Environment.OSVersion.Platform == PlatformID.Unix
|| Environment.OSVersion.Platform == PlatformID.MacOSX;
}
}
}

0 comments on commit ce949ac

Please sign in to comment.