Skip to content

Commit

Permalink
fix(ai): 修改 checkpermission 函数对于命令执行错误时的判断逻辑 (#1174)
Browse files Browse the repository at this point in the history
原本对于 ssh 命令执行错误的判断是 判断 stderr 有无输出,但是发现有情况属于 stderr
有输出(warning)但是命令执行成功的情况,所以将此处修改改为判断 code 的值
  • Loading branch information
Miracle575 committed Mar 22, 2024
1 parent b8d7684 commit 01cfdae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-hornets-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/ai": patch
---

修改对于 ssh 命令执行错误的判断
16 changes: 8 additions & 8 deletions apps/ai/src/server/utils/checkPathPermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ export async function checkCopyFilePath({ host, userIdentityId, toPath, fileName
// 判断文件是否有读写权限
const checkReadableResult = await loggedExec(ssh, logger, false, "ls", [toPath]);

if (checkReadableResult.stderr) {
if (checkReadableResult.code !== 0) {
throw new TRPCError({
code: "FORBIDDEN",
message: `${toPath} is not readable`,
message: `${toPath} is not readable, ${checkReadableResult.stderr}`,
cause: ErrorCode.FILE_NOT_READABLE,
});
}

// 尝试写入文件
const checkWritableResult
= await loggedExec(ssh, logger, false, "touch", [join(toPath, "test_wirte_permission_file")]);
if (checkWritableResult.stderr) {
if (checkWritableResult.code !== 0) {
throw new TRPCError({
code: "FORBIDDEN",
message: `${toPath} is not writable`,
message: `${toPath} is not writable, ${checkWritableResult.stderr}`,
cause: ErrorCode.FILE_NOT_WRITABLE,
});
} else {
Expand Down Expand Up @@ -104,10 +104,10 @@ export async function checkCreateResourcePath({ host, userIdentityId, toPath }:
// 判断文件夹是否有读写权限
const checkReadableResult = await loggedExec(ssh, logger, false, "ls", [toPath]);

if (checkReadableResult.stderr) {
if (checkReadableResult.code !== 0) {
throw new TRPCError({
code: "FORBIDDEN",
message: `${toPath} is not readable`,
message: `${toPath} is not readable, ${checkReadableResult.stderr}`,
cause: ErrorCode.FILE_NOT_READABLE,
});
}
Expand All @@ -116,10 +116,10 @@ export async function checkCreateResourcePath({ host, userIdentityId, toPath }:
const checkWritableResult =
await loggedExec(ssh, logger, false, "touch", [join(toPath, "test_wirte_permission_file")]);

if (checkWritableResult.stderr) {
if (checkWritableResult.code !== 0) {
throw new TRPCError({
code: "FORBIDDEN",
message: `${toPath} is not writable`,
message: `${toPath} is not writable, ${checkWritableResult.stderr}`,
cause: ErrorCode.FILE_NOT_WRITABLE,
});
} else {
Expand Down

0 comments on commit 01cfdae

Please sign in to comment.