Can't figure out how mod security works

Post Reply
User avatar
gigaturbo
New member
Posts: 3
Joined: Fri Jun 24, 2022 16:45
GitHub: gigaturbo
In-game: gigaturbo

Can't figure out how mod security works

by gigaturbo » Post

Hi,

I've got an error related to mod security in my mod and I struggle to fix it. From viewtopic.php?t=12471 I understand that I can't read files from the mod directory after the init stage. But when I try to read a directory content with

Code: Select all

local files = minetest.get_dir_list('examples', false)
in

Code: Select all

init.lua
if got the following error:

Code: Select all

ModError: Failed to load and run script from /home/blac/.minetest/mods/codeblock/init.lua:
Mod security: Blocked attempted read from examples
stack traceback:
	[C]: in function 'get_dir_list'
	/home/blac/.minetest/mods/codeblock/init.lua:15: in main chunk
Check debug.txt for details.
There's something I don't understand :'( Can you help me?

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Can't figure out how mod security works

by rubenwardy » Post

Mod security limits you to only reading and writing from certain directories

You've not provided a path to examples, so it's defaulting to whereever the working directory is. This may be somewhere like /home/blac/examples. As it's outside the Minetest directory, it blocks the read

To fix this, include either get_modpath or get_worldpath:

Code: Select all

local files = minetest.get_dir_list(minetest.get_modpath("codeblock") .. '/examples', false)
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
gigaturbo
New member
Posts: 3
Joined: Fri Jun 24, 2022 16:45
GitHub: gigaturbo
In-game: gigaturbo

Re: Can't figure out how mod security works

by gigaturbo » Post

wow I forgot the path are not relative to the mod directory, thanks for your help!

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests