Skip to content

Commit

Permalink
fix: linux path
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Jun 18, 2024
1 parent e7ddd53 commit 3f5246e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
23 changes: 11 additions & 12 deletions src/MDriveSync.Core/Services/AliyunJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1859,11 +1859,14 @@ private void AliyunDriveInitialize()

_log.LogInformation($"Linux: {isLinux}");

// 格式化路径
_localRestorePath = _jobConfig.Restore.TrimPath();
if (isLinux && !string.IsNullOrWhiteSpace(_localRestorePath))
// 处理 RestoreRootPath
if (isLinux && (_jobConfig.Restore?.StartsWith("/") ?? false))
{
_localRestorePath = $"/{_localRestorePath}";
_localRestorePath = "/" + _jobConfig.Restore.TrimPath();
}
else
{
_localRestorePath = _jobConfig.Restore.TrimPath();
}

_driveSavePath = _jobConfig.Target.TrimPrefix();
Expand All @@ -1873,22 +1876,18 @@ private void AliyunDriveInitialize()
_jobConfig.Sources.Clear();
foreach (var item in sources)
{
var path = item.TrimPath();
if (isLinux && !string.IsNullOrWhiteSpace(path))
if (isLinux && item.StartsWith('/'))
{
// Linux
path = $"/{path}";
var dir = new DirectoryInfo(path);
var dir = new DirectoryInfo(item);
if (!dir.Exists)
{
dir.Create();
}
_jobConfig.Sources.Add($"/{dir.FullName.TrimPath()}");
_jobConfig.Sources.Add($"{dir.FullName.TrimPath()}");
}
else
{
// Windows
var dir = new DirectoryInfo(path);
var dir = new DirectoryInfo(item);
if (!dir.Exists)
{
dir.Create();
Expand Down
22 changes: 9 additions & 13 deletions src/MDriveSync.Core/Services/LocalStorageJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ private string GetDirectoryKey(string rootDirFullPath, DirectoryInfo directoryIn
var baseDirName = baseDirInfo.Name;

var subPath = directoryInfo.FullName.TrimPrefix(rootDirFullPath);
return $"{baseDirName}/{subPath}".TrimPath();
return $"{baseDirName}/{subPath.TrimPath()}";
}

/// <summary>
Expand All @@ -1472,7 +1472,7 @@ private string GetFileKey(string rootPath, string fileFullPath)
var rootPathName = rootInfo.Name;

var subPath = fileFullPath.TrimPrefix(rootInfo.FullName);
return $"{rootPathName}/{subPath}".TrimPath();
return $"{rootPathName}/{subPath.TrimPath()}";
}

/// <summary>
Expand All @@ -1487,7 +1487,7 @@ private string GetFileKeyPath(string rootPath, FileInfo fileInfo)
var rootName = rootInfo.Name;

var subPath = Path.GetDirectoryName(fileInfo.FullName).TrimPrefix(rootInfo.FullName);
return $"{rootName}/{subPath}".TrimPath();
return $"{rootName}/{subPath.TrimPath()}";
}

/// <summary>
Expand Down Expand Up @@ -1725,22 +1725,18 @@ private void Initialize()
_jobConfig.Sources.Clear();
foreach (var item in sources)
{
var path = item.TrimPath();
if (isLinux && !string.IsNullOrWhiteSpace(path))
if (isLinux && item.StartsWith('/'))
{
// Linux
path = $"/{path}";
var dir = new DirectoryInfo(path);
var dir = new DirectoryInfo(item);
if (!dir.Exists)
{
dir.Create();
}
_jobConfig.Sources.Add($"/{dir.FullName.TrimPath()}");
_jobConfig.Sources.Add($"{dir.FullName.TrimPath()}");
}
else
{
// Windows
var dir = new DirectoryInfo(path);
var dir = new DirectoryInfo(item);
if (!dir.Exists)
{
dir.Create();
Expand Down Expand Up @@ -2317,7 +2313,7 @@ private void SyncFile(LocalStorageFileInfo localFileInfo)
//outputFileStream1.Close();

// 计算文件存储路径
var targetFileFullName = $"{saveParentPath}/{name}".TrimPath();
var targetFileFullName = $"{saveParentPath}/{name}";

// 更新上传文件信息
// 将文件重命名为
Expand Down Expand Up @@ -2419,7 +2415,7 @@ private void SyncFileDoWork(LocalStorageFileInfo localFileInfo)
Directory.CreateDirectory(saveParentPath);

// 计算文件存储路径
var targetFileFullName = $"{saveParentPath}/{localFileInfo.Name}".TrimPath();
var targetFileFullName = $"{saveParentPath}/{localFileInfo.Name.TrimPath()}";

// 计算 hash
if (string.IsNullOrWhiteSpace(localFileInfo.Hash))
Expand Down

0 comments on commit 3f5246e

Please sign in to comment.