From 762a183b6b9e7c7438ff9167a740a2ff86e1ab54 Mon Sep 17 00:00:00 2001 From: Jason Schutz Date: Mon, 30 Aug 2021 15:23:41 -0400 Subject: [PATCH] Do not copy texture file on itself --- src/gltf/TextureBuilder.cpp | 3 +++ src/utils/File_Utils.hpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index 752136f..b2325e5 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -201,6 +201,9 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: } else if (!relativeFilename.empty()) { image = new ImageData(relativeFilename, relativeFilename); std::string outputPath = outputFolder + "/" + relativeFilename; + auto srcAbs = FileUtils::GetAbsolutePath(rawTexture.fileLocation); + auto dstAbs = FileUtils::GetAbsolutePath(outputPath); + if (srcAbs != dstAbs) if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { if (verboseOutput) { fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath); diff --git a/src/utils/File_Utils.hpp b/src/utils/File_Utils.hpp index 8a2aa12..10f31ca 100644 --- a/src/utils/File_Utils.hpp +++ b/src/utils/File_Utils.hpp @@ -34,7 +34,7 @@ bool CopyFile( bool createPath = false); inline std::string GetAbsolutePath(const std::string& filePath) { - return boost::filesystem::absolute(filePath).string(); + return boost::filesystem::canonical(boost::filesystem::absolute(filePath)).string(); } inline std::string GetCurrentFolder() {