From 615162b739957ff134320a57b7b09e6915a1d5b4 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 3 Mar 2023 16:34:53 +0100 Subject: [PATCH] Fix #1844: Do not build pebble on non-supported platforms --- config/config.go | 2 +- datastore/pebble/config.go | 2 + datastore/pebble/config_test.go | 2 + datastore/pebble/pebble.go | 2 + datastore/pebble/pebble_disabled.go | 75 +++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 datastore/pebble/pebble_disabled.go diff --git a/config/config.go b/config/config.go index afd49376..5ed86726 100644 --- a/config/config.go +++ b/config/config.go @@ -432,7 +432,7 @@ func (cfg *Manager) LoadJSON(bs []byte) error { loadCompJSON := func(name string, component ComponentConfig, jsonSection jsonSection, t SectionType) error { component.SetBaseDir(dir) raw, ok := jsonSection[name] - if ok { + if ok && raw != nil { err := component.LoadJSON([]byte(*raw)) if err != nil { return err diff --git a/datastore/pebble/config.go b/datastore/pebble/config.go index 4903c29a..70f66460 100644 --- a/datastore/pebble/config.go +++ b/datastore/pebble/config.go @@ -1,3 +1,5 @@ +//go:build !arm && !386 && !(openbsd && amd64) + package pebble import ( diff --git a/datastore/pebble/config_test.go b/datastore/pebble/config_test.go index 7e6d1e5b..07fcc2c9 100644 --- a/datastore/pebble/config_test.go +++ b/datastore/pebble/config_test.go @@ -1,3 +1,5 @@ +//go:build !arm && !386 && !(openbsd && amd64) + package pebble import ( diff --git a/datastore/pebble/pebble.go b/datastore/pebble/pebble.go index ca785ac7..a0acbbbf 100644 --- a/datastore/pebble/pebble.go +++ b/datastore/pebble/pebble.go @@ -1,3 +1,5 @@ +//go:build !arm && !386 && !(openbsd && amd64) + // Package pebble provides a configurable Pebble database backend for use with // IPFS Cluster. package pebble diff --git a/datastore/pebble/pebble_disabled.go b/datastore/pebble/pebble_disabled.go new file mode 100644 index 00000000..a8196720 --- /dev/null +++ b/datastore/pebble/pebble_disabled.go @@ -0,0 +1,75 @@ +//go:build arm || 386 || (openbsd && amd64) + +package pebble + +import ( + "errors" + + "github.com/ipfs-cluster/ipfs-cluster/config" + ds "github.com/ipfs/go-datastore" +) + +// ErrUnsupported is returned when trying to do something with this datastore +// backend. +var ErrUnsupported = errors.New("Pebble is unsupported in this OS/arch combination") + +const configKey = "pebble" +const envConfigKey = "cluster_pebble" + +// Config is a placeholder object for architectures where pebble is unsupported. +type Config struct { + config.Saver +} + +// ConfigKey returns a human-friendly identifier for this type of Datastore. +func (cfg *Config) ConfigKey() string { + return configKey +} + +// Default initializes this Config with sensible values. +func (cfg *Config) Default() error { + return nil +} + +// ApplyEnvVars fills in any Config fields found as environment variables. +func (cfg *Config) ApplyEnvVars() error { + return nil +} + +// Validate checks that the fields of this Config have working values, +// at least in appearance. +func (cfg *Config) Validate() error { + return nil +} + +// LoadJSON reads the fields of this Config from a JSON byteslice as +// generated by ToJSON. +func (cfg *Config) LoadJSON(raw []byte) error { + return nil +} + +// ToJSON generates a JSON-formatted human-friendly representation of this +// Config. +func (cfg *Config) ToJSON() (raw []byte, err error) { + return []byte("{}"), nil +} + +// GetFolder returns the Pebble folder. +func (cfg *Config) GetFolder() string { + return "" +} + +// ToDisplayJSON returns JSON config as a string. +func (cfg *Config) ToDisplayJSON() ([]byte, error) { + return nil, nil +} + +// New returns always ErrUnsupported +func New(cfg *Config) (ds.Datastore, error) { + return nil, ErrUnsupported +} + +// Cleanup does nothing +func Cleanup(cfg *Config) error { + return ErrUnsupported +}