Skip to content

Commit c20205c

Browse files
committed
extra check to ensure only process dir or symlink for legacy files
1 parent a3fec8e commit c20205c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/git/git.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,13 @@ func initFixGitHome117rc() error {
194194
var hasCheckErr bool
195195
for _, wellDirName := range []string{".ssh", ".gnupg"} {
196196
checkLegacyDir := filepath.Join(setting.RepoRootPath, wellDirName)
197-
_ = os.Remove(checkLegacyDir) // try to remove the empty dummy directory first
198-
_, checkErr := os.Stat(checkLegacyDir) // if the directory is not empty, then it won't be removed, it should be handled manually
199-
if checkErr == nil || !errors.Is(checkErr, os.ErrNotExist) {
197+
st, err := os.Lstat(checkLegacyDir) // only process dir or symlink
198+
if err != nil || (!st.IsDir() && st.Mode()&os.ModeSymlink != os.ModeSymlink) {
199+
continue
200+
}
201+
_ = os.Remove(checkLegacyDir) // try to remove the empty dummy directory first
202+
_, err = os.Stat(checkLegacyDir) // if the directory is not empty, then it won't be removed, it should be handled manually
203+
if err == nil || !errors.Is(err, os.ErrNotExist) {
200204
log.Error(`Git HOME has been moved to [git].HOME_PATH, but there are legacy file in old place. Please backup and remove the legacy files %q`, checkLegacyDir)
201205
hasCheckErr = true
202206
}

0 commit comments

Comments
 (0)