From 10eedf62b8b6ddea269a1231800174a57f094efb Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 2 Jul 2016 11:46:15 -0300 Subject: [PATCH] Fixed bug using DirAccess in Android Marshmallow due to data dir being a symlink --- platform/android/os_android.cpp | 28 ++++++++++++++++++++++++++-- platform/android/os_android.h | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 2ef28333bed..97589520c59 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -703,8 +703,32 @@ void OS_Android::set_need_reload_hooks(bool p_needs_them) { String OS_Android::get_data_dir() const { - if (get_data_dir_func) - return get_data_dir_func(); + if (data_dir_cache!=String()) + return data_dir_cache; + + if (get_data_dir_func) { + String data_dir=get_data_dir_func(); + + //store current dir + char real_current_dir_name[2048]; + getcwd(real_current_dir_name,2048); + + //go to data dir + chdir(data_dir.utf8().get_data()); + + //get actual data dir, so we resolve potential symlink (Android 6.0+ seems to use symlink) + char data_current_dir_name[2048]; + getcwd(data_current_dir_name,2048); + + //cache by parsing utf8 + data_dir_cache.parse_utf8(data_current_dir_name); + + //restore original dir so we don't mess things up + chdir(real_current_dir_name); + + return data_dir_cache; + } + return "."; //return Globals::get_singleton()->get_singleton_object("GodotOS")->call("get_data_dir"); }; diff --git a/platform/android/os_android.h b/platform/android/os_android.h index ec1f4119b49..711ee724cd1 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -113,6 +113,8 @@ private: bool use_apk_expansion; bool use_16bits_fbo; + + mutable String data_dir_cache; Rasterizer *rasterizer; VisualServer *visual_server;