feat: 完成将要删除的旧文件备份

1. websocket pipe测试
2. 需要更多测试
3. 需要前端操作页面
This commit is contained in:
zerlei 2024-09-27 18:41:12 +08:00
parent 468701b9ed
commit d572e9466e
8 changed files with 59 additions and 13 deletions

View file

@ -258,17 +258,23 @@ public static class DirExtension
if (child.Type == DirOrFile.Dir)
{
if (child is Dir childDir)
{
if (childDir.NextOp != NextOpType.Del)
{
fileDirOp.DirCreate(childDir, false);
f(childDir, fileDirOp);
}
}
}
else
{
if (child is File childFile)
{
if (childFile.NextOp != NextOpType.Del)
{
fileDirOp.FileCreate(child.FormatedPath, childFile.MTime);
}
}
else
{
throw new ArgumentException("child is not File!");

View file

@ -167,6 +167,37 @@ public class FileDirOpForPack(string srcRootPath, string dstRootPath) : FileDirO
public class FileDirOpForUnpack(string srcRootPath, string dstRootPath) : FileDirOpStra
{
/// <summary>
/// 备份文件
/// </summary>
/// <param name="absolutePath"> 源文件位置,将要删除的或者替换的</param>
private void BacklogFile(string absolutePath)
{
var dstPath = absolutePath.Replace(DstRootPath, SrcRootPath);
var dstDirPath =
Path.GetDirectoryName(dstPath) ?? throw new NullReferenceException("父路径不存在!");
if (!Directory.Exists(dstDirPath))
{
Directory.CreateDirectory(dstDirPath);
}
//文件时间不会更改
System.IO.File.Move(absolutePath, dstPath + ".bak", true);
}
private void BacklogDir(string absolutePath)
{
var dstPath = absolutePath.Replace(DstRootPath, SrcRootPath);
var dstDirPath =
Path.GetDirectoryName(dstPath) ?? throw new NullReferenceException("父路径不存在!");
if (!Directory.Exists(dstDirPath))
{
Directory.CreateDirectory(dstDirPath);
}
Directory.Move(absolutePath, dstPath);
}
/// <summary>
/// 解压缩,必须首先调用
/// </summary>
@ -273,17 +304,20 @@ public class FileDirOpForUnpack(string srcRootPath, string dstRootPath) : FileDi
public override void FileModify(string absolutePath, DateTime mtime)
{
BacklogFile(absolutePath);
this.FileCreate(absolutePath, mtime);
}
public override void FileDel(string absolutePath)
{
BacklogFile(absolutePath);
System.IO.File.Delete(absolutePath);
}
public override void DirDel(Dir dir, bool IsRecursion = true)
{
System.IO.Directory.Delete(dir.FormatedPath, IsRecursion);
BacklogDir(dir.FormatedPath);
//System.IO.Directory.Delete(dir.FormatedPath, IsRecursion);
}
}

View file

@ -8,7 +8,8 @@ public class LocalSyncServer
#pragma warning disable CA2211 // Non-constant fields should not be visible
public static string TempRootFile = "C:/TempPack";
public static string SqlPackageAbPath = "sqlpackage";
public static string MsdeployAbPath = "msdeploy";
//public static string MsdeployAbPath = "msdeploy";
//与visual studio 匹配的Msbuild 路径。在vs 中打开power shell 命令行,使用 `(get-Command -Name msbuild).Source `
public static string MSBuildAbPath = "MSBuild";

View file

@ -11,9 +11,10 @@ IConfiguration _configuration = configurationBuilder.Build();
LocalSyncServer.TempRootFile = _configuration["TempDir"] ?? "C:/TempPack";
LocalSyncServer.SqlPackageAbPath =
_configuration["SqlPackageAbPath"] ?? "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe";
LocalSyncServer.MsdeployAbPath =
_configuration["MsdeployAbPath"]
?? "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe";
//LocalSyncServer.MsdeployAbPath =
// _configuration["MsdeployAbPath"]
// ?? "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe";
// Add services to the container.

View file

@ -260,6 +260,7 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
};
e.LocalDirInfo.ExtractInfo(e.CherryPicks, e.Excludes);
});
//将配置信息发送到remoteServer
var options = new JsonSerializerOptions { WriteIndented = true };
Context
@ -286,6 +287,9 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
Context.NotNullSyncConfig.LocalRootPath,
LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString()
);
Directory.CreateDirectory(
LocalSyncServer.TempRootFile + "/" + Context.NotNullSyncConfig.Id.ToString()
);
Context.NotNullSyncConfig.DirFileConfigs.ForEach(e =>
{
if (e.DiffDirInfo != null)

View file

@ -8,6 +8,6 @@
"AllowedHosts": "*",
"TempDir": "D:/TempPack",
"SqlPackageAbPath": "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe",
"MsdeployAbPath": "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe",
//"MsdeployAbPath": "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe",
"MSBuildAbPath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\amd64\\MSBuild.exe"
}

View file

@ -13,8 +13,8 @@ public class PipeSeed : IDisposable
Name = "Test",
RemoteUrl = "D:/FileSyncTest/dtemp",
RemotePwd = "t123",
IsDeployDb = true,
IsDeployProject = true,
IsDeployDb = false,
IsDeployProject = false,
LocalProjectAbsolutePath = "D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB",
LocalRootPath = "D:/FileSyncTest/src",

View file

@ -44,8 +44,8 @@ public class PipeTest
p4.Other = p3;
LocalSyncServer.TempRootFile = "D:/FileSyncTest/stemp";
RemoteSyncServer.SqlPackageAbPath = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe";
LocalSyncServer.MsdeployAbPath =
"C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe";
//LocalSyncServer.MsdeployAbPath =
// "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe";
LocalSyncServer.SqlPackageAbPath = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe";
LocalSyncServer.MSBuildAbPath =
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\amd64\\MSBuild.exe";