Skip to content

Commit

Permalink
fix: linux path error
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Jun 18, 2024
1 parent d02345e commit 3a8c31f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 47 deletions.
9 changes: 3 additions & 6 deletions src/MDriveSync.Core/Services/AliyunJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ private void ClearDownloadCache(string saveRootPath)
private string GetDirectoryKey(string localRootPath, DirectoryInfo directoryInfo)
{
var localRootInfo = new DirectoryInfo(localRootPath);
var subPath = directoryInfo.FullName.TrimPrefix(localRootInfo.FullName);
var subPath = directoryInfo.FullName.TrimPath().TrimPrefix(localRootInfo.FullName.TrimPath());
return $"{localRootInfo.Name}/{subPath}".TrimPath();
}

Expand All @@ -1654,7 +1654,7 @@ private string GetDirectoryKey(string localRootPath, DirectoryInfo directoryInfo
private string GetFileKey(string localRootPath, string fileFullPath)
{
var localRootInfo = new DirectoryInfo(localRootPath);
var subPath = fileFullPath.TrimPrefix(localRootInfo.FullName);
var subPath = fileFullPath.TrimPath().TrimPrefix(localRootInfo.FullName.TrimPath());
return $"{localRootInfo.Name}/{subPath}".TrimPath();
}

Expand All @@ -1667,10 +1667,7 @@ private string GetFileKey(string localRootPath, string fileFullPath)
private string GetFileKeyPath(string localRootPath, FileInfo fileInfo)
{
var localRootInfo = new DirectoryInfo(localRootPath);

// fix: GetDirectoryName none / end
var subPath = Path.GetDirectoryName(fileInfo.FullName).TrimPath()
.TrimPrefix(localRootInfo.FullName.TrimPath());
var subPath = Path.GetDirectoryName(fileInfo.FullName).TrimPath().TrimPrefix(localRootInfo.FullName.TrimPath());
return $"{localRootInfo.Name}/{subPath}".TrimPath();
}

Expand Down
45 changes: 4 additions & 41 deletions src/MDriveSync.Core/Services/LocalStorageJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,28 +1427,6 @@ private int GetDownloadThreadCount()
return processorCount;
}

/// <summary>
/// 清理下载缓存
/// </summary>
private void ClearDownloadCache(string saveRootPath)
{
// 清理临时文件
var tempPath = Path.Combine(saveRootPath, ".duplicaticache");
if (Directory.Exists(tempPath))
{
Directory.Delete(tempPath, true);
}

var tmpFiles = Directory.GetFiles(saveRootPath, "*.duplicatidownload", SearchOption.AllDirectories);
foreach (var file in tmpFiles)
{
if (File.Exists(file))
{
File.Delete(file);
}
}
}

/// <summary>
/// 获取文件夹路径 key
/// 将本地路径转为 {备份根目录}/{子目录}
Expand All @@ -1461,8 +1439,8 @@ private string GetDirectoryKey(string rootDirFullPath, DirectoryInfo directoryIn
var baseDirInfo = new DirectoryInfo(rootDirFullPath);
var baseDirName = baseDirInfo.Name;

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

/// <summary>
Expand All @@ -1476,23 +1454,8 @@ private string GetFileKey(string rootPath, string fileFullPath)
var rootInfo = new DirectoryInfo(rootPath);
var rootPathName = rootInfo.Name;

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

/// <summary>
/// 获取文件路径 key
/// </summary>
/// <param name="rootPath"></param>
/// <param name="fileInfo"></param>
/// <returns></returns>
private string GetFileKeyPath(string rootPath, FileInfo fileInfo)
{
var rootInfo = new DirectoryInfo(rootPath);
var rootName = rootInfo.Name;

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

/// <summary>
Expand Down

0 comments on commit 3a8c31f

Please sign in to comment.