onflow/flow-emulator

Emulator DB path option doesn't work with a relative path depth greater than 1

Closed this issue · 1 comments

Problem

Enabling snapshot support and specifying the emulator DB path option (via Flow CLI) with a relative path depth greater than 1 fails to start the emulator.

The emulator logs report the following error:

ERR ❗  Failed to configure storage               error="unable to open database file: out of memory (14)"

Steps to Reproduce

Flow CLI version: v1.0.2
Emulator version: v0.48.0

Run the emulator via the Flow CLI as follows:

> flow emulator --snapshot --dbpath ./some/path/depth/greater/than/one/

Additional Notes

Digging through the emulator project I found the following snippet at storage/sqlite/store.go:207:

func New(url string) (store *Store, err error) {

	dbUrl := url
	if dbUrl != ":memory:" {
		urlInfo, err := os.Stat(url)
		if err == nil && urlInfo.IsDir() {
			dbUrl = filepath.Join(urlInfo.Name(), "emulator.sqlite")
			if err != nil {
				return nil, err
			}
		}
	}

	db, err := sql.Open("sqlite", dbUrl)
	...

I'm not sure, but I think the line

dbUrl = filepath.Join(urlInfo.Name(), "emulator.sqlite")

should be changed to

dbUrl = filepath.Join(url, "emulator.sqlite")

thanks for reporting @jp-at-work , I will make a PR for this today