4
4
package unittest
5
5
6
6
import (
7
- "io"
8
7
"os"
9
- "path"
8
+ "path/filepath "
10
9
"strings"
11
10
12
11
"code.gitea.io/gitea/modules/util"
@@ -31,27 +30,7 @@ func Copy(src, dest string) error {
31
30
return os .Symlink (target , dest )
32
31
}
33
32
34
- sr , err := os .Open (src )
35
- if err != nil {
36
- return err
37
- }
38
- defer sr .Close ()
39
-
40
- dw , err := os .Create (dest )
41
- if err != nil {
42
- return err
43
- }
44
- defer dw .Close ()
45
-
46
- if _ , err = io .Copy (dw , sr ); err != nil {
47
- return err
48
- }
49
-
50
- // Set back file information.
51
- if err = os .Chtimes (dest , si .ModTime (), si .ModTime ()); err != nil {
52
- return err
53
- }
54
- return os .Chmod (dest , si .Mode ())
33
+ return util .CopyFile (src , dest )
55
34
}
56
35
57
36
// Sync synchronizes the two files. This is skipped if both files
@@ -89,18 +68,17 @@ func SyncDirs(srcPath, destPath string) error {
89
68
}
90
69
91
70
// find and delete all untracked files
92
- infos , err := util .StatDir (destPath , true )
71
+ files , err := util .StatDir (destPath , true )
93
72
if err != nil {
94
73
return err
95
74
}
96
75
97
- for _ , info := range infos {
98
- curPath := path .Join (destPath , info )
99
-
100
- if _ , err := os .Stat (path .Join (srcPath , info )); err != nil {
76
+ for _ , file := range files {
77
+ destFilePath := filepath .Join (destPath , file )
78
+ if _ , err = os .Stat (filepath .Join (srcPath , file )); err != nil {
101
79
if os .IsNotExist (err ) {
102
- // Delete
103
- if err := os .RemoveAll (curPath ); err != nil {
80
+ // TODO: why delete? it should happen because the file list is just queried above, why not exist?
81
+ if err := os .RemoveAll (destFilePath ); err != nil {
104
82
return err
105
83
}
106
84
} else {
@@ -110,17 +88,17 @@ func SyncDirs(srcPath, destPath string) error {
110
88
}
111
89
112
90
// Gather directory info.
113
- infos , err = util .StatDir (srcPath , true )
91
+ files , err = util .StatDir (srcPath , true )
114
92
if err != nil {
115
93
return err
116
94
}
117
95
118
- for _ , info := range infos {
119
- curPath := path .Join (destPath , info )
120
- if strings .HasSuffix (info , "/" ) {
121
- err = os .MkdirAll (curPath , os .ModePerm )
96
+ for _ , file := range files {
97
+ destFilePath := filepath .Join (destPath , file )
98
+ if strings .HasSuffix (file , "/" ) {
99
+ err = os .MkdirAll (destFilePath , os .ModePerm )
122
100
} else {
123
- err = Sync (path .Join (srcPath , info ), curPath )
101
+ err = Sync (filepath .Join (srcPath , file ), destFilePath )
124
102
}
125
103
if err != nil {
126
104
return err
0 commit comments