Skip to content

Commit 74309b7

Browse files
committed
scripting: fix mkdirs and canonical path on image::save
1 parent 595b22b commit 74309b7

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/noggit/scripting/script_filesystem.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ namespace noggit
1818
{
1919
namespace scripting
2020
{
21-
namespace
21+
void mkdirs(std::string const& pathstr)
2222
{
23-
void mkdirs(std::string const& pathstr)
23+
auto path = fs::path(pathstr);
24+
auto parent_path = path.parent_path();
25+
if (parent_path.string().size() > 0)
2426
{
25-
auto path = fs::path(pathstr);
26-
auto parent_path = path.parent_path();
27-
if (parent_path.string().size() > 0)
28-
{
29-
fs::create_directories(path.parent_path());
30-
}
27+
fs::create_directories(path.parent_path());
3128
}
3229
}
3330

src/noggit/scripting/script_filesystem.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ namespace noggit
1818
std::string read_file(std::string const& path);
1919
bool path_exists(std::string const& path);
2020
void register_filesystem(script_context * state);
21+
void mkdirs(std::string const& path);
2122
} // namespace scripting
2223
} // namespace noggit

src/noggit/scripting/script_image.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ namespace noggit
129129
void image::save(std::string const& filename)
130130
{
131131
auto writable_path = get_writable_path("image::save", state(), filename);
132-
unsigned error = lodepng::encode(filename, get_image(), _width, _height);
132+
mkdirs(writable_path.string());
133+
unsigned error = lodepng::encode(writable_path.string(), get_image(), _width, _height);
133134
if (error)
134135
{
135136
throw script_exception(

0 commit comments

Comments
 (0)