Skip to content

Commit

Permalink
fix: run by root, linux target root path
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Jun 18, 2024
1 parent d326417 commit 9df4fc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ docker run --name mdrive -d --restart=always \
-v /data:/data:ro \
-e BASIC_AUTH_USER=admin -e BASIC_AUTH_PASSWORD=123456 \
-p 8080:8080 trueaiorg/mdrive
# 更多权限,容器内以 root 用户启动:--user root
```

### Windows 服务部署
Expand Down
1 change: 1 addition & 0 deletions src/MDriveSync.Client.API/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MDriveSync.Client.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
USER root # È·±£ÒÔ root Óû§ÔËÐÐ
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MDriveSync.Client.API.dll"]
26 changes: 18 additions & 8 deletions src/MDriveSync.Core/Services/LocalStorageJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ private void SyncFiles(CancellationToken token)
// 如果目标目录不存在,则创建
if (!_targetFolders.ContainsKey(item.Key))
{
var saveParentPath = $"{_targetSaveRootPath}/{item.Key}".TrimPath();
var saveParentPath = $"{_targetSaveRootPath}/{item.Key.TrimPath()}";
var dirInfo = new DirectoryInfo(saveParentPath);
if (!dirInfo.Exists)
{
Expand Down Expand Up @@ -1700,14 +1700,25 @@ private void Initialize()
_log.LogInformation($"Linux: {isLinux}");
// 格式化路径
_tartgetRestoreRootPath = _jobConfig.Restore.TrimPath();
if (isLinux && !string.IsNullOrWhiteSpace(_tartgetRestoreRootPath))
// 处理 RestoreRootPath
if (IsLinux() && (_jobConfig.Restore?.StartsWith("/") ?? false))
{
_tartgetRestoreRootPath = $"/{_tartgetRestoreRootPath}";
_tartgetRestoreRootPath = "/" + _jobConfig.Restore.TrimPath();
}
else
{
_tartgetRestoreRootPath = _jobConfig.Restore.TrimPath();
}
_targetSaveRootPath = _jobConfig.Target.TrimPrefix();
// 处理 TargetRootPath
if (IsLinux() && (_jobConfig.Target?.StartsWith("/") ?? false))
{
_targetSaveRootPath = "/" + _targetSaveRootPath.TrimPath(); ;
}
else
{
_targetSaveRootPath = _jobConfig.Target.TrimPath();
}
// 格式化备份目录
var sources = _jobConfig.Sources.Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c.TrimPath()).Distinct().ToList();
Expand Down Expand Up @@ -2494,8 +2505,7 @@ private void SyncFileDoWork(LocalStorageFileInfo localFileInfo)
private void InitTargetRootPath()
{
// 目标根目录初始化
var rootPath = _targetSaveRootPath.TrimPath();
var rootInfo = new DirectoryInfo(rootPath);
var rootInfo = new DirectoryInfo(_targetSaveRootPath);
if (!rootInfo.Exists)
{
rootInfo.Create();
Expand Down

0 comments on commit 9df4fc2

Please sign in to comment.