mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 05:51:51 +00:00
fix 'access denied' in file.remove for entry points 'export', 'config'
This commit is contained in:
parent
e0df715128
commit
1f4ef8a4de
1 changed files with 7 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include "coders/gzip.hpp"
|
#include "coders/gzip.hpp"
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
|
|
@ -53,11 +54,15 @@ static int l_file_write(lua::State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::set<std::string> writeable_entry_points {
|
||||||
|
"world", "export", "config"
|
||||||
|
};
|
||||||
|
|
||||||
static int l_file_remove(lua::State* L) {
|
static int l_file_remove(lua::State* L) {
|
||||||
std::string rawpath = lua::require_string(L, 1);
|
std::string rawpath = lua::require_string(L, 1);
|
||||||
fs::path path = resolve_path(rawpath);
|
fs::path path = resolve_path(rawpath);
|
||||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||||
if (entryPoint != "world") {
|
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||||
throw std::runtime_error("access denied");
|
throw std::runtime_error("access denied");
|
||||||
}
|
}
|
||||||
return lua::pushboolean(L, fs::remove(path));
|
return lua::pushboolean(L, fs::remove(path));
|
||||||
|
|
@ -67,7 +72,7 @@ static int l_file_remove_tree(lua::State* L) {
|
||||||
std::string rawpath = lua::require_string(L, 1);
|
std::string rawpath = lua::require_string(L, 1);
|
||||||
fs::path path = resolve_path(rawpath);
|
fs::path path = resolve_path(rawpath);
|
||||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||||
if (entryPoint != "world") {
|
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||||
throw std::runtime_error("access denied");
|
throw std::runtime_error("access denied");
|
||||||
}
|
}
|
||||||
return lua::pushinteger(L, fs::remove_all(path));
|
return lua::pushinteger(L, fs::remove_all(path));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue