aops-ceres/0005-override-list-file-method.patch
weidongkl b47d9f2d49
sync: 同步sp3修改到sp4分支
Signed-off-by: weidongkl <weidong@uniontech.com>
2024-05-28 14:44:35 +08:00

59 lines
2.0 KiB
Diff

From 19b611645b9be2e72c81cab5cb456f9a943d3caa Mon Sep 17 00:00:00 2001
From: rabbitali <wenxin32@foxmail.com>
Date: Wed, 7 Feb 2024 12:23:28 +0800
Subject: [PATCH 1/1] override list file method
---
ceres/manages/list_file_manage.py | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/ceres/manages/list_file_manage.py b/ceres/manages/list_file_manage.py
index dab55e6..081a714 100644
--- a/ceres/manages/list_file_manage.py
+++ b/ceres/manages/list_file_manage.py
@@ -14,14 +14,9 @@
# Description: default
# Date: 2023/6/14 16:31
import os
-import subprocess
from ceres.function.log import LOGGER
-from ceres.function.status import (
- UNKNOWN_ERROR,
- SUCCESS
-)
-from ceres.function.util import execute_shell_command
+from ceres.function.status import FILE_NOT_FOUND, UNKNOWN_ERROR, SUCCESS, PARAM_ERROR
class ListFileManage:
@@ -39,15 +34,16 @@ class ListFileManage:
str: status code
"""
file_list_res = []
+
+ if not os.path.exists(directory_path):
+ return FILE_NOT_FOUND, {"resp": file_list_res}
+
+ if os.path.isfile(directory_path):
+ return PARAM_ERROR, {"resp": file_list_res}
+
try:
- command = [f"ls -l {directory_path}", "awk '{print $9}'"]
- _, stdout, _ = execute_shell_command(command)
- file_list = stdout.split("\n")
- for file in file_list:
- if file:
- file_path_res = os.path.join(directory_path, file)
- file_list_res.append(file_path_res)
+ file_list_res = [os.path.join(directory_path, file) for file in os.listdir(directory_path)]
return SUCCESS, {"resp": file_list_res}
- except Exception as e:
- LOGGER.error("list the pam.d file failed, with msg{}".format(e))
+ except OSError as e:
+ LOGGER.error(f"Failed to read the file list under the path with message {e}")
return UNKNOWN_ERROR, {"resp": list()}
--
2.33.0