MCPcopy
hub / github.com/perkeep/perkeep / versionMismatch

Method versionMismatch

pkg/client/client.go:865–908  ·  view source on GitHub ↗

versionMismatch returns true if the server was built before 2018-01-13 and the client was built at or after 2018-01-13.

(ctx context.Context)

Source from the content-addressed store, hash-verified

863// versionMismatch returns true if the server was built before 2018-01-13 and
864// the client was built at or after 2018-01-13.
865func (c *Client) versionMismatch(ctx context.Context) (bool, error) {
866 const shortRFC3339 = "2006-01-02"
867 version := buildinfo.GitInfo
868 if version == "" {
869 return false, errors.New("unknown client version")
870 }
871 version = version[:10] // keep only the date part
872 clientDate, err := time.Parse(shortRFC3339, version)
873 if err != nil {
874 return false, fmt.Errorf("could not parse date from version %q: %v", version, err)
875 }
876 apiChangeDate, _ := time.Parse(shortRFC3339, "2018-01-13")
877 if !clientDate.After(apiChangeDate) {
878 // client is old enough, all good.
879 return false, nil
880 }
881 url := c.discoRoot() + "/status/status.json"
882 req := c.newRequest(ctx, "GET", url)
883 res, err := c.doReqGated(req)
884 if err != nil {
885 return false, err
886 }
887 if res.StatusCode != 200 {
888 body, _ := io.ReadAll(io.LimitReader(res.Body, 1<<20))
889 res.Body.Close()
890 return false, fmt.Errorf("got status code %d from URL %s; body %s", res.StatusCode, url, body)
891 }
892 var status struct {
893 Version string `json:"version"`
894 }
895 if err := httputil.DecodeJSON(res, &status); err != nil {
896 return false, fmt.Errorf("error parsing JSON from URL %s: %v", url, err)
897 }
898 serverVersion := status.Version[:10]
899 serverDate, err := time.Parse(shortRFC3339, serverVersion)
900 if err != nil {
901 return false, fmt.Errorf("could not parse date from server version %q: %v", status.Version, err)
902 }
903 if serverDate.After(apiChangeDate) {
904 // server is recent enough, all good.
905 return false, nil
906 }
907 return true, nil
908}
909
910// FileHasContents returns true iff f refers to a "file" or "bytes" schema blob,
911// the server is configured with a "download helper", and the server responds

Callers 1

Calls 7

discoRootMethod · 0.95
newRequestMethod · 0.95
doReqGatedMethod · 0.95
DecodeJSONFunction · 0.92
ParseMethod · 0.80
ReadAllMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected