Skip to content

Commit e9906df

Browse files
Add a new extend_permissions cache option. (#1404)
When enabled it overrides the creation permissions for files and directories to enable access for all users in the system. This enables different users in the system to access the cache. Relates-To: OAM-2037 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent c597579 commit e9906df

File tree

11 files changed

+605
-33
lines changed

11 files changed

+605
-33
lines changed

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2019-2021 HERE Europe B.V.
1+
# Copyright (C) 2019-2023 HERE Europe B.V.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -436,14 +436,37 @@ target_link_libraries(${PROJECT_NAME}
436436
)
437437

438438
if(OLP_SDK_ENABLE_DEFAULT_CACHE)
439+
include(CheckCXXSymbolExists)
440+
check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
441+
check_cxx_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_FULLFSYNC)
442+
check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)
443+
439444
target_include_directories(${PROJECT_NAME}
440445
PUBLIC
441-
$<BUILD_INTERFACE:${leveldb_INCLUDE_DIR}>
446+
$<BUILD_INTERFACE:${leveldb_INCLUDE_DIR}>
442447
)
443448
target_link_libraries(${PROJECT_NAME}
444449
PRIVATE
445-
leveldb::leveldb
450+
leveldb::leveldb
446451
)
452+
453+
if(HAVE_FDATASYNC)
454+
target_compile_definitions(${PROJECT_NAME}
455+
PRIVATE
456+
HAVE_FDATASYNC)
457+
endif()
458+
459+
if(HAVE_FULLFSYNC)
460+
target_compile_definitions(${PROJECT_NAME}
461+
PRIVATE
462+
HAVE_FULLFSYNC)
463+
endif()
464+
465+
if(HAVE_O_CLOEXEC)
466+
target_compile_definitions(${PROJECT_NAME}
467+
PRIVATE
468+
HAVE_O_CLOEXEC)
469+
endif()
447470
endif()
448471

449472
if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)

olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ struct CORE_API CacheSettings {
162162
* regardless of the network state.
163163
*/
164164
boost::optional<std::string> disk_path_protected = boost::none;
165+
166+
/**
167+
* @brief The extend permissions flag (applicable for Unix systems).
168+
*
169+
* A boolean option that controls the default permission for file and
170+
* directory creation. When enabled, all permissions for files and directories
171+
* will be set to 0666 and 0777 respectively, which allows read, write, and
172+
* execute access to all users.
173+
*
174+
* Note: the resulting permissions are affected by the umask.
175+
*/
176+
bool extend_permissions = false;
165177
};
166178

167179
#else

olp-cpp-sdk-core/include/olp/core/utils/Dir.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,10 +91,14 @@ class CORE_API Dir {
9191
* in the path.
9292
*
9393
* @param path The path of the directory.
94+
* @param extend_permissions Controls the permission extension.
95+
*
96+
* Note: extend_permissions are applicable for Unix systems, if enabled, it
97+
* sets the 0777 permissions for created folders.
9498
*
9599
* @return True if the operation is successful; false otherwise.
96100
*/
97-
static bool Create(const std::string& path);
101+
static bool Create(const std::string& path, bool extend_permissions = false);
98102

99103
/**
100104
* @brief Gets a platform-specific temporary path.

olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2022 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -828,7 +828,7 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupStorage() {
828828
}
829829

830830
DefaultCache::StorageOpenResult DefaultCacheImpl::SetupProtectedCache() {
831-
protected_cache_ = std::make_unique<DiskCache>();
831+
protected_cache_ = std::make_unique<DiskCache>(settings_.extend_permissions);
832832

833833
// Storage settings for protected cache are different. We want to specify the
834834
// max_file_size greater than the manifest file size. Or else leveldb will try
@@ -883,7 +883,7 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupProtectedCache() {
883883
DefaultCache::StorageOpenResult DefaultCacheImpl::SetupMutableCache() {
884884
auto storage_settings = CreateStorageSettings(settings_);
885885

886-
mutable_cache_ = std::make_unique<DiskCache>();
886+
mutable_cache_ = std::make_unique<DiskCache>(settings_.extend_permissions);
887887
auto status = mutable_cache_->Open(settings_.disk_path_mutable.get(),
888888
settings_.disk_path_mutable.get(),
889889
storage_settings, settings_.openOptions);

olp-cpp-sdk-core/src/cache/DiskCache.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ int CheckCompactionFinished(leveldb::DB& db) {
146146

147147
} // anonymous namespace
148148

149-
DiskCache::DiskCache() : env_(DiskCacheEnv::CreateEnv()){};
149+
DiskCache::DiskCache(bool extend_permissions)
150+
: env_(DiskCacheEnv::CreateEnv(extend_permissions)){};
150151
DiskCache::~DiskCache() { Close(); }
151152

152153
void DiskCache::LevelDBLogger::Logv(const char* format, va_list ap) {

olp-cpp-sdk-core/src/cache/DiskCache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -109,7 +109,7 @@ class DiskCache {
109109
void Logv(const char* format, va_list ap) override;
110110
};
111111

112-
DiskCache();
112+
explicit DiskCache(bool extend_permissions);
113113
~DiskCache();
114114
OpenResult Open(const std::string& data_path,
115115
const std::string& versioned_data_path,

0 commit comments

Comments
 (0)