fix: 修复 playbook 编辑器无法清空内容的bug (#9663)

Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
pull/9666/head
fit2bot 2023-02-21 15:22:08 +08:00 committed by GitHub
parent 1caca32a26
commit e4d28f5f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -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):