spnda / fastgltf

A modern C++17 glTF 2.0 library focused on speed, correctness, and usability
https://fastgltf.readthedocs.io/v0.8.x/
MIT License
301 stars 44 forks source link

Textures are not created on disk if the destination directory does not exist #53

Closed Cyphall closed 8 months ago

Cyphall commented 8 months ago

When exporting as GLTF, the FileExporter does not write the texture files (probably buffer files too, not tested) on disk if the destination directory does not already exist. This is probably due to std::ofstream not being able to open a file if the file's directory doesn't exist on disk.

spnda commented 8 months ago

I think this was intentional behaviour as I think the caller should be the one who manages the creation of the directories. I do this in the tests, too. Call std::filesystem::create_directory with the path you pass to setImagePath.

Or do you think the FileExporter should also always handle creating directories?

Cyphall commented 8 months ago

Since the FileExporter is responsible for creating the files on disk, I believe it should also be responsible for creating any required folder for these files.

It would be a bit weird for the FileExporter to be allowed to create files but not folders.

Cyphall commented 8 months ago

On that note, image and buffer names should probably be validated and escaped before being concatenated with the base path to create the final file path. This would avoid cases where these names contain relative paths that would put them outside their corresponding base folder. (eg. an image called "../test" would not be created in the image folder but in the parent folder)