Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,32 @@ func getAppPath() (string, error) {
}
// Note: we don't use path.Dir here because it does not handle case
// which path starts with two "/" in Windows: "//psf/Home/..."
return strings.ReplaceAll(appPath, "\\", "/"), err
appPath = strings.ReplaceAll(appPath, "\\", "/")

// Fix issue 16209: When running in a snap and repositories are
// created, paths in the hooks include the snap revision. But as new
// revisions come out the older revisions are eventually deleted, and
// the hooks begin to fail.
// The code below replaces the snap revision with "current", which
// is a link to the current snap revision.
snap := os.Getenv("SNAP")
if snap != "" && strings.HasPrefix(appPath, snap) {
split := strings.Split(appPath, "/")
if len(split) >= 3 {
oldAppPath := appPath
split[len(split)-2] = "current"
newAppPath := strings.Join(split, "/")
appPath, err = exec.LookPath(newAppPath)
if err != nil {
appPath = oldAppPath
log.Error("Could not change AppPath from %s to %s while running in snap. Hooks for new repositories may fail after snap upgrades.", oldAppPath, newAppPath)
} else {
log.Info("AppPath changed from %s to %s because we are running in snap.", oldAppPath, newAppPath)
}
}
}

return appPath, nil
}

func getWorkPath(appPath string) string {
Expand Down