Skip to content

Commit 785ceb5

Browse files
committed
copy dir and file is improved
1 parent 11dc4c5 commit 785ceb5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

filepath.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func CopyFile(dest, src string) (int64, error) {
157157
return 0, fmt.Errorf("source file is not exists: %v", src)
158158
}
159159

160+
baseName := filepath.Base(src)
161+
if !strings.HasSuffix(dest, baseName) {
162+
dest = filepath.Join(dest, baseName)
163+
}
164+
160165
if IsFileExists(dest) {
161166
return 0, fmt.Errorf("destination file already exists: %v", dest)
162167
}
@@ -195,6 +200,11 @@ func CopyDir(dest, src string, excludes Excludes) error {
195200
return fmt.Errorf("source is not directory: %v", src)
196201
}
197202

203+
baseName := filepath.Base(src)
204+
if !strings.HasSuffix(dest, baseName) {
205+
dest = filepath.Join(dest, baseName)
206+
}
207+
198208
if IsFileExists(dest) {
199209
return fmt.Errorf("destination dir already exists: %v", dest)
200210
}

0 commit comments

Comments
 (0)