From 726039f2461311c6e2ac349b470dcc90617b9008 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Thu, 10 Oct 2024 17:30:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/NewDatasetServiceImpl.java | 6 ++++-- .../com/ruoyi/platform/utils/DVCUtils.java | 18 +++++++++--------- .../com/ruoyi/platform/utils/FileUtil.java | 9 +++++++++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 79390c49..e6609895 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -384,8 +384,9 @@ public class NewDatasetServiceImpl implements NewDatasetService { LoginUser loginUser = SecurityUtils.getLoginUser(); String ci4sUsername = loginUser.getUsername(); - dvcUtils.deleteDirectory(localPathlocal + "/" + ci4sUsername + "/datasets/" + repoId + "/" + repo); - + String rootPath = localPathlocal + "/" + ci4sUsername + "/datasets/" + repoId + "/" + repo; + dvcUtils.deleteDirectory(rootPath); + FileUtil.renameFile(rootPath, rootPath + "_deleted"); } @Override @@ -394,6 +395,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { String rootPath = Paths.get(localPathlocal + "/" + relativePath).getParent().toString(); gitService.deleteBranch(token, owner, repo, version, rootPath); dvcUtils.deleteDirectory(rootPath); + FileUtil.renameFile(rootPath, rootPath + "_deleted"); } @Override diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java index fd307914..7ecbdc51 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java @@ -303,7 +303,7 @@ public class DVCUtils { .call(); log.info("基于 master 的远程分支 " + branchName + " 创建成功。"); } catch (IOException | GitAPIException e) { - log.error("Exception occurred while creating local branch based on master",e); + log.error("Exception occurred while creating local branch based on master", e); } } @@ -378,17 +378,17 @@ public class DVCUtils { .call(); // 打印结果 - pushResults.forEach(pr ->log.info(pr.getMessages())); + pushResults.forEach(pr -> log.info(pr.getMessages())); - log.info("分支 " + branchName + " 已成功推送到远程仓库。"); + log.info("分支 " + branchName + " 已成功推送到远程仓库。"); } } /** * 检查本地是否存在指定分支 * - * @param git Git 实例 - * @param branchName 分支名称 + * @param git Git 实例 + * @param branchName 分支名称 * @return 如果本地存在该分支返回 true,否则返回 false */ private static boolean branchExistsLocally(Git git, String branchName) throws GitAPIException { @@ -524,7 +524,7 @@ public class DVCUtils { - + public void gitFetch(String localPath, String username, String password) throws IOException, GitAPIException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File(localPath, ".git")) @@ -624,12 +624,12 @@ public class DVCUtils { * @param branch 分支名称 * @return 包含文件路径、名称和大小的List> */ - public List> getFileDetailsAfterGitPull(String localPath, String repoFolder, String branch, String filePath , String username, String password) { + public List> getFileDetailsAfterGitPull(String localPath, String repoFolder, String branch, String filePath, String username, String password) { try { //刷新 - refreshRemoteBranches(localPath+"/" + repoFolder + "/"+ branch, username, password,branch); + refreshRemoteBranches(localPath + "/" + repoFolder + "/" + branch, username, password, branch); // 读取data文件夹中的文件列表 - String path = localPath + "/" + repoFolder + "/"+ branch + "/" + filePath; + String path = localPath + "/" + repoFolder + "/" + branch + "/" + filePath; return FileUtil.getFiles(path); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java index 12ff7de3..e31eed5a 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java @@ -102,4 +102,13 @@ public class FileUtil { return fileInfoList; } + public static void renameFile(String oldPath ,String newPath){ + File oldFolder = new File(oldPath); + + // 新文件夹路径 + File newFolder = new File(newPath); + + // 重命名文件夹 + boolean renamed = oldFolder.renameTo(newFolder); + } }