Skip to content

Commit 307db7d

Browse files
committed
clarify
1 parent 0110c72 commit 307db7d

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

models/unittest/fscopy.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func Sync(srcPath, destPath string) error {
5959
}
6060

6161
// SyncDirs synchronizes files recursively from source to target directory.
62-
//
6362
// It returns error when error occurs in underlying functions.
6463
func SyncDirs(srcPath, destPath string) error {
6564
err := os.MkdirAll(destPath, os.ModePerm)
@@ -68,17 +67,16 @@ func SyncDirs(srcPath, destPath string) error {
6867
}
6968

7069
// find and delete all untracked files
71-
files, err := util.StatDir(destPath, true)
70+
destFiles, err := util.StatDir(destPath, true)
7271
if err != nil {
7372
return err
7473
}
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 {
7977
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 {
8280
return err
8381
}
8482
} else {
@@ -87,18 +85,18 @@ func SyncDirs(srcPath, destPath string) error {
8785
}
8886
}
8987

90-
// Gather directory info.
91-
files, err = util.StatDir(srcPath, true)
88+
// sync src files to dest
89+
srcFiles, err := util.StatDir(srcPath, true)
9290
if err != nil {
9391
return err
9492
}
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, "/") {
9997
err = os.MkdirAll(destFilePath, os.ModePerm)
10098
} else {
101-
err = Sync(filepath.Join(srcPath, file), destFilePath)
99+
err = Sync(filepath.Join(srcPath, srcFile), destFilePath)
102100
}
103101
if err != nil {
104102
return err

0 commit comments

Comments
 (0)