anqiansong 3 years ago committed by GitHub
parent 27249e021f
commit 7fb5bab26b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,7 +70,20 @@ func getParentPackage(dir string) (string, error) {
return "", err
}
return filepath.ToSlash(filepath.Join(projectCtx.Path, strings.TrimPrefix(projectCtx.WorkDir, projectCtx.Dir))), nil
// fix https://github.com/zeromicro/go-zero/issues/1058
wd := projectCtx.WorkDir
d := projectCtx.Dir
same, err := ctlutil.SameFile(wd, d)
if err != nil {
return "", err
}
trim := strings.TrimPrefix(projectCtx.WorkDir, projectCtx.Dir)
if same {
trim = strings.TrimPrefix(strings.ToLower(projectCtx.WorkDir), strings.ToLower(projectCtx.Dir))
}
return filepath.ToSlash(filepath.Join(projectCtx.Path, trim)), nil
}
func writeProperty(writer io.Writer, name, tag, comment string, tp spec.Type, indent int) error {

@ -148,6 +148,24 @@ func LoadTemplate(category, file, builtin string) (string, error) {
return string(content), nil
}
// SameFile compares the between path if the same path,
// it maybe the same path in case case-ignore, such as:
// /Users/go_zero and /Users/Go_zero, as far as we know,
// this case maybe appear on macOS and Windows.
func SameFile(path1, path2 string) (bool, error) {
stat1, err := os.Stat(path1)
if err != nil {
return false, err
}
stat2, err := os.Stat(path2)
if err != nil {
return false, err
}
return os.SameFile(stat1, stat2), nil
}
func createTemplate(file, content string, force bool) error {
if FileExists(file) && !force {
return nil

Loading…
Cancel
Save