Browse Source

fix: 解决文件复制到原路径导致文件内容清空的 BUG (#798)

pull/803/head
zhengkunwang223 2 years ago committed by GitHub
parent
commit
db2aa35b2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      backend/utils/files/file_op.go
  2. 8
      frontend/src/views/host/file-management/code-editor/index.vue

10
backend/utils/files/file_op.go

@ -322,17 +322,21 @@ func (f FileOp) CopyFile(src, dst string) error {
}
defer srcFile.Close()
err = f.Fs.MkdirAll(filepath.Dir(dst), 0666)
srcInfo, err := f.Fs.Stat(src)
if err != nil {
return err
}
dstPath := path.Join(dst, srcInfo.Name())
if src == dstPath {
return nil
}
srcInfo, err := f.Fs.Stat(src)
err = f.Fs.MkdirAll(filepath.Dir(dst), 0666)
if err != nil {
return err
}
dstFile, err := f.Fs.OpenFile(path.Join(dst, srcInfo.Name()), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775)
dstFile, err := f.Fs.OpenFile(dstPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775)
if err != nil {
return err
}

8
frontend/src/views/host/file-management/code-editor/index.vue

@ -82,10 +82,10 @@ interface EditorConfig {
eol: number;
}
let open = ref(false);
let loading = ref(false);
const open = ref(false);
const loading = ref(false);
let config = reactive<EditorConfig>({
const config = reactive<EditorConfig>({
theme: 'vs-dark',
language: 'plaintext',
eol: monaco.editor.EndOfLineSequence.LF,
@ -129,7 +129,7 @@ const handleClose = () => {
if (editor) {
editor.dispose();
}
em('close', false);
em('close', open.value);
};
const changeLanguage = () => {
monaco.editor.setModelLanguage(editor.getModel(), config.language);

Loading…
Cancel
Save