@@ -59,7 +59,6 @@ func Sync(srcPath, destPath string) error {
59
59
}
60
60
61
61
// SyncDirs synchronizes files recursively from source to target directory.
62
- //
63
62
// It returns error when error occurs in underlying functions.
64
63
func SyncDirs (srcPath , destPath string ) error {
65
64
err := os .MkdirAll (destPath , os .ModePerm )
@@ -68,17 +67,16 @@ func SyncDirs(srcPath, destPath string) error {
68
67
}
69
68
70
69
// find and delete all untracked files
71
- files , err := util .StatDir (destPath , true )
70
+ destFiles , err := util .StatDir (destPath , true )
72
71
if err != nil {
73
72
return err
74
73
}
75
-
76
- for _ , file := range files {
77
- destFilePath := filepath .Join (destPath , file )
78
- if _ , err = os .Stat (filepath .Join (srcPath , file )); err != nil {
74
+ for _ , destFile := range destFiles {
75
+ destFilePath := filepath .Join (destPath , destFile )
76
+ if _ , err = os .Stat (filepath .Join (srcPath , destFile )); err != nil {
79
77
if os .IsNotExist (err ) {
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 {
78
+ // if src file does not exist, remove dest file
79
+ if err = os .RemoveAll (destFilePath ); err != nil {
82
80
return err
83
81
}
84
82
} else {
@@ -87,18 +85,18 @@ func SyncDirs(srcPath, destPath string) error {
87
85
}
88
86
}
89
87
90
- // Gather directory info.
91
- files , err = util .StatDir (srcPath , true )
88
+ // sync src files to dest
89
+ srcFiles , err : = util .StatDir (srcPath , true )
92
90
if err != nil {
93
91
return err
94
92
}
95
-
96
- for _ , file := range files {
97
- destFilePath := filepath . Join ( destPath , file )
98
- if strings .HasSuffix (file , "/" ) {
93
+ for _ , srcFile := range srcFiles {
94
+ destFilePath := filepath . Join ( destPath , srcFile )
95
+ // util.StatDir appends a slash to the directory name
96
+ if strings .HasSuffix (srcFile , "/" ) {
99
97
err = os .MkdirAll (destFilePath , os .ModePerm )
100
98
} else {
101
- err = Sync (filepath .Join (srcPath , file ), destFilePath )
99
+ err = Sync (filepath .Join (srcPath , srcFile ), destFilePath )
102
100
}
103
101
if err != nil {
104
102
return err
0 commit comments