diff options
author | 6543 <6543@obermui.de> | 2021-03-22 18:03:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-22 18:03:18 +0100 |
commit | 5f038cd7febd834c9b86b9e734848870efbdce86 (patch) | |
tree | 8b3e9b8fd52c537766d3fd05c56d0ff90a7aa6da /vendor/code.gitea.io/sdk/gitea/version.go | |
parent | 8567cba0d978e6ab68c337c0a80244704a15718a (diff) | |
download | gitea-5f038cd7febd834c9b86b9e734848870efbdce86.tar.gz gitea-5f038cd7febd834c9b86b9e734848870efbdce86.zip |
[Vendor] update gitea-sdk v0.14.0 (#15103)
* upgraded code.gitea.io/sdk/gitea v0.13.2 => v0.14.0
* rm workaround
Diffstat (limited to 'vendor/code.gitea.io/sdk/gitea/version.go')
-rw-r--r-- | vendor/code.gitea.io/sdk/gitea/version.go | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/vendor/code.gitea.io/sdk/gitea/version.go b/vendor/code.gitea.io/sdk/gitea/version.go index 747117ccc2..ed8a2ae5dd 100644 --- a/vendor/code.gitea.io/sdk/gitea/version.go +++ b/vendor/code.gitea.io/sdk/gitea/version.go @@ -22,14 +22,8 @@ func (c *Client) ServerVersion() (string, *Response, error) { // CheckServerVersionConstraint validates that the login's server satisfies a // given version constraint such as ">= 1.11.0+dev" func (c *Client) CheckServerVersionConstraint(constraint string) error { - c.versionLock.RLock() - if c.serverVersion == nil { - c.versionLock.RUnlock() - if err := c.loadClientServerVersion(); err != nil { - return err - } - } else { - c.versionLock.RUnlock() + if err := c.loadServerVersion(); err != nil { + return err } check, err := version.NewConstraint(constraint) @@ -37,48 +31,48 @@ func (c *Client) CheckServerVersionConstraint(constraint string) error { return err } if !check.Check(c.serverVersion) { - return fmt.Errorf("gitea server at %s does not satisfy version constraint %s", c.url, constraint) + c.mutex.RLock() + url := c.url + c.mutex.RUnlock() + return fmt.Errorf("gitea server at %s does not satisfy version constraint %s", url, constraint) } return nil } // predefined versions only have to be parsed by library once var ( - version1_10_0, _ = version.NewVersion("1.10.0") version1_11_0, _ = version.NewVersion("1.11.0") version1_12_0, _ = version.NewVersion("1.12.0") version1_13_0, _ = version.NewVersion("1.13.0") + version1_14_0, _ = version.NewVersion("1.14.0") ) // checkServerVersionGreaterThanOrEqual is internally used to speed up things and ignore issues with prerelease func (c *Client) checkServerVersionGreaterThanOrEqual(v *version.Version) error { - c.versionLock.RLock() - if c.serverVersion == nil { - c.versionLock.RUnlock() - if err := c.loadClientServerVersion(); err != nil { - return err - } - } else { - c.versionLock.RUnlock() + if err := c.loadServerVersion(); err != nil { + return err } if !c.serverVersion.GreaterThanOrEqual(v) { - return fmt.Errorf("gitea server at %s is older than %s", c.url, v.Original()) + c.mutex.RLock() + url := c.url + c.mutex.RUnlock() + return fmt.Errorf("gitea server at %s is older than %s", url, v.Original()) } return nil } -// loadClientServerVersion init the serverVersion variable -func (c *Client) loadClientServerVersion() error { - c.versionLock.Lock() - defer c.versionLock.Unlock() - - raw, _, err := c.ServerVersion() - if err != nil { - return err - } - if c.serverVersion, err = version.NewVersion(raw); err != nil { - return err - } - return nil +// loadServerVersion init the serverVersion variable +func (c *Client) loadServerVersion() (err error) { + c.getVersionOnce.Do(func() { + raw, _, err2 := c.ServerVersion() + if err2 != nil { + err = err2 + return + } + if c.serverVersion, err = version.NewVersion(raw); err != nil { + return + } + }) + return } |