diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-01-08 22:32:54 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-01-08 22:32:54 +0100 |
| commit | 9263e1d36eec53ee3c4e4d04da93a032c0596eec (patch) | |
| tree | 12afe91a09b60a9ae2a1b2fbff8fa81b24ceee41 /src/open_lib.cpp | |
| parent | da93fe3bea35ae8d2383e6006b7775bb96af6885 (diff) | |
| download | PROJ-9263e1d36eec53ee3c4e4d04da93a032c0596eec.tar.gz PROJ-9263e1d36eec53ee3c4e4d04da93a032c0596eec.zip | |
Add capability to read resource files from the user writable directory
Diffstat (limited to 'src/open_lib.cpp')
| -rw-r--r-- | src/open_lib.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/open_lib.cpp b/src/open_lib.cpp index 222dd757..ae387281 100644 --- a/src/open_lib.cpp +++ b/src/open_lib.cpp @@ -224,6 +224,16 @@ static bool is_rel_or_absolute_filename(const char *name) || (name[0] != '\0' && name[1] == ':' && strchr(dir_chars,name[2])); } +static bool ignoreUserWritableDirectory() +{ + // Env var mostly for testing purposes and being independent from + // an existing installation + const char* envVarIgnoreUserWritableDirectory = + getenv("PROJ_IGNORE_USER_WRITABLE_DIRECTORY"); + return envVarIgnoreUserWritableDirectory != nullptr && + envVarIgnoreUserWritableDirectory[0] != '\0'; +} + static void* pj_open_lib_internal(projCtx ctx, const char *name, const char *mode, void* (*open_file)(projCtx, const char*, const char*), @@ -279,6 +289,17 @@ pj_open_lib_internal(projCtx ctx, const char *name, const char *mode, break; } } + + else if( !ignoreUserWritableDirectory() && + (fid = open_file(ctx, + (pj_context_get_user_writable_directory(ctx, false) + + DIR_CHAR + name).c_str(), mode)) != nullptr ) { + fname = pj_context_get_user_writable_directory(ctx, false); + fname += DIR_CHAR; + fname += name; + sysname = fname.c_str(); + } + /* if is environment PROJ_LIB defined */ else if ((sysname = getenv("PROJ_LIB")) != nullptr) { auto paths = NS_PROJ::internal::split(std::string(sysname), dirSeparator); |
