Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cross device link error in rename #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

djosix
Copy link

@djosix djosix commented Apr 17, 2024

Extract mongod to the destination folder to ensure source and target for renaming are on the same device.

Fixes #27

What

After extracting mongod from the downloaded tgz file, mongod is renamed to the binary path in the cache dir. If the temp dir and the cache dir are not on the same FS the rename operation may fail (at least in unix). We can simply extract the mongod to the cache dir instead of the temp dir, so the source and target are always on the same FS.

Running GitLab CI pipeline and the mongod path is cached, before:

=== RUN   TestXXX
--- FAIL: TestXXX (82.42s)
panic: failed to init mongodb: rename /tmp/878417577 /builds/xxx/.cache/dp-mongodb-in-memory/mongodb-linux-x86_64-debian10-4.4.28.tgz/mongod: invalid cross-device link [recovered]
	panic: failed to init mongodb: rename /tmp/878417577 /builds/xxx/.cache/dp-mongodb-in-memory/mongodb-linux-x86_64-debian10-4.4.28.tgz/mongod: invalid cross-device link
goroutine 19 [running]:
testing.tRunner.func1.2({0xbd8020, 0xc000224170})
	/usr/local/go/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1634 +0x377
panic({0xbd8020?, 0xc000224170?})
	/usr/local/go/src/runtime/panic.go:770 +0x132
yyy/xxx/internal.NewFakeMongoClient(0xc000327520)
	/builds/xxx/internal/mongodb.go:25 +0x2ae
yyy/xxx/internal.NewFakeMongoDB(0xcc819f?)
	/builds/xxx/internal/mongodb.go:18 +0x13
yyy/xxx/zzz.TestXXX(0xc000327520)
	/builds/xxx/zzz/handler_test.go:53 +0x4c
testing.tRunner(0xc000327520, 0xd13770)
	/usr/local/go/src/testing/testing.go:1689 +0xfb
created by testing.(*T).Run in goroutine 1
	/usr/local/go/src/testing/testing.go:1742 +0x390
FAIL	yyy/xxx/zzz	82.433s
FAIL

After this change: all tests passed

How to review

Make sure there is no other problems.

Who can review

Anyone.

Extract mongod to the destination folder to ensure source and target for
renaming are on the same device.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid cross-device link
1 participant