Skip to content

Commit e8ec149

Browse files
committed
mount on job, fix: #3
1 parent 625d404 commit e8ec149

File tree

6 files changed

+1086
-1022
lines changed

6 files changed

+1086
-1022
lines changed

src/MDriveSync.Client.API/wwwroot/assets/index-KxJlzSCy.js

Lines changed: 1001 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MDriveSync.Client.API/wwwroot/assets/index-Rwnb1OPm.js

Lines changed: 0 additions & 1001 deletions
This file was deleted.
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<!doctype html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>MDrive</title>
7-
<script type="module" crossorigin src="/assets/index-Rwnb1OPm.js"></script>
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>MDrive</title>
7+
<script type="module" crossorigin src="/assets/index-KxJlzSCy.js"></script>
88
<link rel="stylesheet" crossorigin href="/assets/index-Sa9bKrsM.css">
9-
</head>
10-
<body>
11-
<div id="root"></div>
12-
</body>
13-
</html>
9+
</head>
10+
<body>
11+
<div id="root"></div>
12+
</body>
13+
</html>

src/MDriveSync.Core/Services/AliyunDriveMounter.cs

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ public class AliyunDriveMounter : IDokanOperations, IDisposable
129129
/// </summary>
130130
private string _driveParentFileId = "root";
131131

132+
/// <summary>
133+
/// 别名
134+
/// </summary>
135+
private string _alias = "";
136+
137+
/// <summary>
138+
/// 显示真实大小
139+
/// </summary>
140+
private bool _isRealSize;
141+
132142
/// <summary>
133143
/// 下载请求
134144
/// </summary>
@@ -137,9 +147,25 @@ public class AliyunDriveMounter : IDokanOperations, IDisposable
137147
Timeout = TimeSpan.FromMinutes(45)
138148
};
139149

140-
public AliyunDriveMounter(AliyunDriveConfig driveConfig, AliyunDriveMountConfig driveMountConfig)
150+
/// <summary>
151+
/// 创建挂载
152+
/// </summary>
153+
/// <param name="driveConfig">云盘配置</param>
154+
/// <param name="driveMountConfig">挂载配置</param>
155+
/// <param name="alias">别名</param>
156+
public AliyunDriveMounter(
157+
AliyunDriveConfig driveConfig,
158+
AliyunDriveMountConfig driveMountConfig,
159+
string alias = "")
141160
{
142161
_log = Log.Logger;
162+
_alias = alias;
163+
164+
// 如果挂载为目录,则显示真实大小
165+
if (!string.IsNullOrWhiteSpace(driveMountConfig.MountPath))
166+
{
167+
_isRealSize = true;
168+
}
143169

144170
_driveApi = new AliyunDriveApi();
145171

@@ -196,7 +222,8 @@ private async Task<byte[]> DownloadFileSegment(string url, int start, int end)
196222
/// <returns></returns>
197223
private string GetPathKey(string fileName)
198224
{
199-
return $"{_driveMountConfig.MountPath.TrimPath()}/{fileName.TrimPath()}".ToUrlPath();
225+
// {_driveMountConfig.MountPath.TrimPath()}/
226+
return $"{fileName.TrimPath()}".ToUrlPath();
200227
}
201228

202229
/// <summary>
@@ -1445,7 +1472,7 @@ public IList<FileInformation> FindFilesHelper(string fileName, string searchPatt
14451472
}
14461473

14471474
/// <summary>
1448-
/// 创建文件/文件夹
1475+
/// 创建/打开文件/文件夹
14491476
/// </summary>
14501477
/// <param name="fileName">文件名</param>
14511478
/// <param name="access">访问权限</param>
@@ -1743,9 +1770,9 @@ public NtStatus ReadFile(string fileName, byte[] buffer, out int bytesRead, long
17431770
partialContent = DownloadFileSegment(url, (int)offset, endOffset).GetAwaiter().GetResult();
17441771
}
17451772

1746-
if (fileName.Contains("jpg"))
1747-
{
1748-
}
1773+
//if (fileName.Contains("jpg"))
1774+
//{
1775+
//}
17491776

17501777
// 确保不会复制超出 buffer 大小的数据
17511778
int bytesToCopy = Math.Min(buffer.Length, partialContent.Length);
@@ -1919,8 +1946,21 @@ public NtStatus GetDiskFreeSpace(out long freeBytesAvailable, out long totalNumb
19191946
// diskSpaceInfo.FreeSpace - 云盘的剩余空间
19201947

19211948
totalNumberOfBytes = _driveConfig?.Metadata?.TotalSize ?? long.MaxValue;
1922-
totalNumberOfFreeBytes = _driveConfig?.Metadata?.UsedSize ?? 0;
1923-
freeBytesAvailable = totalNumberOfBytes > 0 ? totalNumberOfBytes - totalNumberOfFreeBytes : long.MaxValue;
1949+
1950+
// 如果显示真实使用量,则根据文件计算
1951+
if (_isRealSize)
1952+
{
1953+
totalNumberOfFreeBytes = _driveFiles.Sum(x => x.Value.Size ?? 0);
1954+
freeBytesAvailable = totalNumberOfBytes > 0 ? totalNumberOfBytes - totalNumberOfFreeBytes : long.MaxValue;
1955+
1956+
_log.Information($"真实大小 {totalNumberOfFreeBytes}");
1957+
}
1958+
else
1959+
{
1960+
totalNumberOfFreeBytes = _driveConfig?.Metadata?.UsedSize ?? 0;
1961+
freeBytesAvailable = totalNumberOfBytes > 0 ? totalNumberOfBytes - totalNumberOfFreeBytes : long.MaxValue;
1962+
}
1963+
19241964

19251965
return NtStatus.Success;
19261966
}
@@ -1939,6 +1979,11 @@ public NtStatus GetVolumeInformation(out string volumeLabel, out FileSystemFeatu
19391979
// 设置卷标,这个标签可以根据您的需求自定义,例如"我的云盘"
19401980
volumeLabel = _driveConfig?.Name ?? "我的云盘";
19411981

1982+
if (!string.IsNullOrWhiteSpace(_alias))
1983+
{
1984+
volumeLabel += $"({_alias})";
1985+
}
1986+
19421987
// 设置文件系统的特性。这些特性描述了文件系统支持的不同功能。
19431988
// 例如,可以设置为支持Unicode文件名、持久ACLs(访问控制列表)、大文件等
19441989
features = FileSystemFeatures.UnicodeOnDisk |

src/MDriveSync.Core/Services/Job.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,18 @@ public void JobUpdate(JobConfig cfg)
11541154
throw new LogicException("作业标识错误");
11551155
}
11561156

1157+
var drive = DriveDb.Instacne.GetAll().Where(c => c.Id == _driveConfig.Id).FirstOrDefault();
1158+
if (drive == null)
1159+
{
1160+
throw new LogicException("配置配置错误,请重启程序");
1161+
}
1162+
1163+
// 禁止作业指向同一目标
1164+
if (!string.IsNullOrWhiteSpace(cfg.Target) && drive.Jobs.Any(x => x.Target == cfg.Target))
1165+
{
1166+
throw new LogicException("多个作业禁止指向云盘同一个目标目录");
1167+
}
1168+
11571169
// 清除表达式所有作业
11581170
_schedulers.Clear();
11591171

@@ -2938,7 +2950,7 @@ public void DriveMount()
29382950
//_mountDrive = new AliyunDriveMounterByJob(mountPoint, this, _driveFolders, _driveFiles);
29392951
//_mountDrive.Mount();
29402952

2941-
_mountDrive = new AliyunDriveMounter(_driveConfig, _jobConfig.MountConfig);
2953+
_mountDrive = new AliyunDriveMounter(_driveConfig, _jobConfig.MountConfig, _jobConfig.Name);
29422954
_mountDrive.Mount();
29432955
}
29442956

src/MDriveSync.Core/Services/TimedHostedService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ public void JobAdd(string driveId, JobConfig cfg)
176176
cfg.Id = Guid.NewGuid().ToString("N");
177177

178178
drive.Jobs ??= new List<JobConfig>();
179+
180+
// 禁止作业指向同一目标
181+
if (!string.IsNullOrWhiteSpace(cfg.Target) && drive.Jobs.Any(x => x.Target == cfg.Target))
182+
{
183+
throw new LogicException("多个作业禁止指向云盘同一个目标目录");
184+
}
185+
179186
drive.Jobs.Add(cfg);
180187

181188
// 持久化

0 commit comments

Comments
 (0)