(src, dst string)
| 776 | |
| 777 | |
| 778 | func CopyFile(src, dst string) error { |
| 779 | if _, err := os.Stat(dst); err == nil { |
| 780 | // 如果目标文件已经存在, 则不允许覆盖. |
| 781 | return err |
| 782 | } |
| 783 | |
| 784 | source_file, err := os.Open(src) |
| 785 | if err != nil { |
| 786 | return err |
| 787 | } |
| 788 | defer source_file.Close() |
| 789 | |
| 790 | if err := os.MkdirAll(filepath.Dir(dst), os.ModePerm); err != nil { |
| 791 | return err |
| 792 | } |
| 793 | |
| 794 | destination_file, err := os.Create(dst) |
| 795 | if err != nil { |
| 796 | return err |
| 797 | } |
| 798 | defer destination_file.Close() |
| 799 | |
| 800 | _, err = io.Copy(destination_file, source_file) |
| 801 | return err |
| 802 | } |
| 803 | |
| 804 | |
| 805 | func CopyDirectory(src, dst string) error { |
no outgoing calls
no test coverage detected