diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-01-20 15:01:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-20 15:01:33 +0100 |
| commit | a6390b59ae2bad2a763e7ab3341ee4c80e708b3d (patch) | |
| tree | 26d5016def90e3e9f71a51da694ff3028e1006ed /src/open_lib.cpp | |
| parent | f1209ff020cc9f5490f8e6c7edced6877f53da49 (diff) | |
| parent | 90b6685a990b8c4931aafb508853401a89163e78 (diff) | |
| download | PROJ-a6390b59ae2bad2a763e7ab3341ee4c80e708b3d.tar.gz PROJ-a6390b59ae2bad2a763e7ab3341ee4c80e708b3d.zip | |
Merge pull request #1826 from rouault/rfc4_code_review
[RFC4_dev] Address code review comments
Diffstat (limited to 'src/open_lib.cpp')
| -rw-r--r-- | src/open_lib.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/open_lib.cpp b/src/open_lib.cpp index 23ee79a0..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); @@ -381,6 +402,23 @@ std::unique_ptr<NS_PROJ::File> NS_PROJ::FileManager::open_resource_file( "Using %s", remote_file.c_str() ); pj_ctx_set_errno( ctx, 0 ); } + } else { + // For example for resource files like 'alaska' + auto remote_file_tif = remote_file + ".tif"; + file = open(ctx, remote_file_tif.c_str()); + if( file ) { + pj_log( ctx, PJ_LOG_DEBUG_MAJOR, + "Using %s", remote_file_tif.c_str() ); + pj_ctx_set_errno( ctx, 0 ); + } else { + // Init files + file = open(ctx, remote_file.c_str()); + if( file ) { + pj_log( ctx, PJ_LOG_DEBUG_MAJOR, + "Using %s", remote_file.c_str() ); + pj_ctx_set_errno( ctx, 0 ); + } + } } } } |
