From e4d28f5f3eb481fbde405eb341af1e4bcb423951 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:22:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20playbook=20?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E6=97=A0=E6=B3=95=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E7=9A=84bug=20(#9663)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aaron3S --- apps/ops/api/playbook.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/ops/api/playbook.py b/apps/ops/api/playbook.py index ea856df37..c26643fe5 100644 --- a/apps/ops/api/playbook.py +++ b/apps/ops/api/playbook.py @@ -145,16 +145,17 @@ class PlaybookFileBrowserAPIView(APIView): return Response(status=status.HTTP_400_BAD_REQUEST) file_path = os.path.join(work_path, file_key) + # rename if new_name: new_file_path = os.path.join(os.path.dirname(file_path), new_name) if os.path.exists(new_file_path): return Response({'msg': '{} already exists'.format(new_name)}, status=status.HTTP_400_BAD_REQUEST) os.rename(file_path, new_file_path) - file_path = new_file_path - - if not is_directory and content: - with open(file_path, 'w') as f: - f.write(content) + # edit content + else: + if not is_directory: + with open(file_path, 'w') as f: + f.write(content) return Response({'msg': 'ok'}) def delete(self, request, **kwargs):