diff options
Diffstat (limited to 'lib/xdsserver')
-rw-r--r-- | lib/xdsserver/sdk.go | 20 | ||||
-rw-r--r-- | lib/xdsserver/sdks.go | 9 |
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/xdsserver/sdk.go b/lib/xdsserver/sdk.go index 2736246..374fb12 100644 --- a/lib/xdsserver/sdk.go +++ b/lib/xdsserver/sdk.go @@ -64,9 +64,18 @@ type CrossSDK struct { } // ListCrossSDK List all available and installed SDK (call "db-dump" script) -func ListCrossSDK(scriptDir string, log *logrus.Logger) ([]xsapiv1.SDK, error) { +func ListCrossSDK(scriptDir string, update bool, log *logrus.Logger) ([]xsapiv1.SDK, error) { sdksList := []xsapiv1.SDK{} + // First update sdk DB when requested + if update { + out, err := UpdateSDKDb(scriptDir, log) + if err != nil { + log.Errorf("SDK DB update failure (%v): %v", err, out) + return sdksList, fmt.Errorf("Error while updating SDK DB (%v)", err) + } + } + // Retrieve SDKs list and info cmd := exec.Command(path.Join(scriptDir, scriptDbDump)) stdout, err := cmd.CombinedOutput() @@ -111,6 +120,15 @@ func GetSDKInfo(scriptDir, url, filename, md5sum string, log *logrus.Logger) (xs return sdk, nil } +// UpdateSDKDb Used db-update script to update SDK database +func UpdateSDKDb(scriptDir string, log *logrus.Logger) (string, error) { + args := []string{} + cmd := exec.Command(path.Join(scriptDir, scriptDbUpdate), args...) + stdout, err := cmd.CombinedOutput() + + return string(stdout), err +} + // NewCrossSDK creates a new instance of CrossSDK func NewCrossSDK(ctx *Context, sdk xsapiv1.SDK, scriptDir string) (*CrossSDK, error) { s := CrossSDK{ diff --git a/lib/xdsserver/sdks.go b/lib/xdsserver/sdks.go index c006861..6094045 100644 --- a/lib/xdsserver/sdks.go +++ b/lib/xdsserver/sdks.go @@ -63,6 +63,12 @@ func NewSDKs(ctx *Context) (*SDKs, error) { return &s, err } + // Update SDK DB on startup by default (can be disable using config file) + update := true + if s.Config.FileConf.SdkDbUpdate != "startup" { + update = false + } + s.mutex.Lock() defer s.mutex.Unlock() @@ -73,10 +79,11 @@ func NewSDKs(ctx *Context) (*SDKs, error) { continue } - sdksList, err := ListCrossSDK(d, s.Log) + sdksList, err := ListCrossSDK(d, update, s.Log) if err != nil { // allow to use XDS even if error on list s.Log.Errorf("Cannot retrieve SDK list: %v", err) + sdksList, _ = ListCrossSDK(d, false, s.Log) } s.LogSillyf("'%s' SDKs list: %v", d, sdksList) |