Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/portal-web/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ export default {
existModalOk: "Confirm",
errorMessage: "{} error! A total of {} files/directories, {} succeeded, {} abandoned, {} failed",
successMessage: "{} succeeded! A total of {} files/directories, {} succeeded, {} abandoned",
invalidCopyTitle: "Invalid Copy Operation",
invalidCopyContent: "Cannot copy a folder into itself or its subfolder: {}",
},
delete: {
confirmTitle: "Confirm Deletion",
Expand Down
2 changes: 2 additions & 0 deletions apps/portal-web/src/i18n/zh_cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ export default {
existModalOk: "确认",
errorMessage: "{}错误!总计{}项文件/目录,其中成功{}项,放弃{}项,失败{}项",
successMessage: "{}成功!总计{}项文件/目录,其中成功{}项,放弃{}项",
invalidCopyTitle: "无效的复制操作",
invalidCopyContent: "不能将文件夹复制到自身或子文件夹: {}",
},
delete: {
confirmTitle: "确认删除",
Expand Down
11 changes: 11 additions & 0 deletions apps/portal-web/src/pageComponents/filemanager/FileManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ export const FileManager: React.FC<Props> = ({ cluster, path, urlPrefix, scowdEn
let abandonCount: number = 0;
const allCount = operation.selected.length;
for (const x of operation.selected) {
const fromPath = join(operation.originalPath, x.name);
const toPath = join(path, x.name);

// 阻止复制到自身或子目录
if (toPath === fromPath || toPath.startsWith(fromPath + "/")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的路径比较逻辑可以更精确一些,防止路径比较时的误判。建议使用path.resolve()规范化路径后再进行比较

Suggested change
if (toPath === fromPath || toPath.startsWith(fromPath + "/")) {
if (path.resolve(toPath) === path.resolve(fromPath) || path.resolve(toPath).startsWith(path.resolve(fromPath) + path.sep)) {

modal.error({
title: t(p("moveCopy.invalidCopyTitle")),
content: t(p("moveCopy.invalidCopyContent"), [x.name]),
});
continue;
}
try {

const exists = await api.fileExist({ query: { cluster: cluster.id, path: join(path, x.name) } });
Expand Down
Loading