sudo fix
This commit is contained in:
@@ -18,14 +18,7 @@ def sudo_open(file_path, mode='r', encoding='utf-8'):
|
||||
content = result.stdout
|
||||
yield content
|
||||
elif mode == 'w':
|
||||
# 使用 sudo 打开文件并写入内容
|
||||
def write_content(content):
|
||||
result = subprocess.run(["sudo", "tee", file_path], input=content, text=True, capture_output=True, encoding=encoding)
|
||||
if result.returncode != 0:
|
||||
raise PermissionError(f"无法写入文件: {file_path}")
|
||||
return result.stdout
|
||||
|
||||
yield write_content
|
||||
raise PermissionError(f"不允许以sudo权限写入文件: {file_path}")
|
||||
else:
|
||||
raise ValueError("只支持 'r' 或 'w' 模式")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user