mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
Separate a special function for creating shared folders as permissions and logic is different from normal folder open/create logic in Unix
This commit is contained in:
@@ -101,9 +101,23 @@ inline file_handle_t file_handle_from_mapping_handle(mapping_handle_t hnd)
|
||||
{ return hnd.handle; }
|
||||
|
||||
template<class CharT>
|
||||
inline bool create_directory(const CharT *path, bool = false)
|
||||
inline bool create_directory(const CharT *path)
|
||||
{ return winapi::create_directory(path); }
|
||||
|
||||
template<class CharT>
|
||||
inline bool open_or_create_directory(const CharT *path)
|
||||
{
|
||||
//If fails, check that it's because it already exists
|
||||
return create_directory(path)
|
||||
|| error_info(system_error_code()).get_error_code() == already_exists_error;
|
||||
}
|
||||
|
||||
template<class CharT>
|
||||
inline bool open_or_create_shared_directory(const CharT *path)
|
||||
{
|
||||
return open_or_create_directory(path);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
inline bool remove_directory(const CharT *path)
|
||||
{ return winapi::remove_directory(path); }
|
||||
@@ -493,10 +507,23 @@ inline mapping_handle_t mapping_handle_from_file_handle(file_handle_t hnd)
|
||||
inline file_handle_t file_handle_from_mapping_handle(mapping_handle_t hnd)
|
||||
{ return hnd.handle; }
|
||||
|
||||
inline bool create_directory(const char *path, bool is_shared_dir = false)
|
||||
inline bool create_directory(const char *path)
|
||||
{
|
||||
::mode_t m = is_shared_dir ? 01777 : 0777;
|
||||
return ::mkdir(path, m) == 0 && ::chmod(path, m) == 0;
|
||||
::mode_t m = ::mode_t(0777);
|
||||
return ::mkdir(path, m) == 0;
|
||||
}
|
||||
|
||||
inline bool open_or_create_directory(const char *path)
|
||||
{
|
||||
::mode_t m = ::mode_t(0777);
|
||||
return ::mkdir(path, m) == 0 || (errno == EEXIST);
|
||||
}
|
||||
|
||||
inline bool open_or_create_shared_directory(const char *path)
|
||||
{
|
||||
::mode_t m = ::mode_t(01777);
|
||||
const bool created_or_exists = (::mkdir(path, m) == 0) || (errno == EEXIST);
|
||||
return created_or_exists && (::chmod(path, m) == 0);
|
||||
}
|
||||
|
||||
inline bool remove_directory(const char *path)
|
||||
@@ -785,18 +812,6 @@ inline bool delete_subdirectories(const std::string &refcstrRootDirectory, const
|
||||
|
||||
#endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
|
||||
|
||||
inline bool open_or_create_directory(const char *dir_name, bool is_shared_dir = false)
|
||||
{
|
||||
//If fails, check that it's because it already exists
|
||||
if(!create_directory(dir_name, is_shared_dir)){
|
||||
error_info info(system_error_code());
|
||||
if(info.get_error_code() != already_exists_error){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::string get_temporary_path()
|
||||
{
|
||||
std::size_t required_len = 0;
|
||||
|
||||
@@ -52,7 +52,7 @@ static void create_tmp_subdir_and_get_pid_based_filepath
|
||||
create_shared_dir_and_clean_old(s);
|
||||
s += "/";
|
||||
s += subdir_name;
|
||||
if(!open_or_create_directory(s.c_str(), true)){
|
||||
if(!open_or_create_shared_directory(s.c_str())){
|
||||
error_info err = system_error_code();
|
||||
throw interprocess_exception(err);
|
||||
}
|
||||
|
||||
@@ -209,22 +209,18 @@ inline void create_shared_dir_and_clean_old(std::basic_string<CharT> &shared_dir
|
||||
get_shared_dir_root(root_shared_dir);
|
||||
|
||||
//If fails, check that it's because already exists
|
||||
if(!create_directory(root_shared_dir.c_str(), true)){
|
||||
if(!open_or_create_shared_directory(root_shared_dir.c_str())){
|
||||
error_info info(system_error_code());
|
||||
if(info.get_error_code() != already_exists_error){
|
||||
throw interprocess_exception(info);
|
||||
}
|
||||
throw interprocess_exception(info);
|
||||
}
|
||||
|
||||
#if defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME)
|
||||
get_shared_dir(shared_dir);
|
||||
|
||||
//If fails, check that it's because already exists
|
||||
if(!create_directory(shared_dir.c_str(), true)){
|
||||
if(!open_or_create_shared_directory(shared_dir.c_str())){
|
||||
error_info info(system_error_code());
|
||||
if(info.get_error_code() != already_exists_error){
|
||||
throw interprocess_exception(info);
|
||||
}
|
||||
throw interprocess_exception(info);
|
||||
}
|
||||
//Now erase all old directories created in the previous boot sessions
|
||||
std::basic_string<CharT> subdir = shared_dir;
|
||||
|
||||
@@ -38,7 +38,7 @@ inline void get_shared_dir(std::string &shared_dir)
|
||||
shared_dir += "/boostipctesteventlog_";
|
||||
shared_dir += boost::interprocess::test::get_process_id_name();
|
||||
if(!dir_created)
|
||||
ipcdetail::create_directory(shared_dir.c_str(), true);
|
||||
ipcdetail::open_or_create_shared_directory(shared_dir.c_str());
|
||||
dir_created = true;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ inline void get_shared_dir(std::wstring &shared_dir)
|
||||
shared_dir += L"/boostipctesteventlog_";
|
||||
shared_dir += boost::interprocess::test::get_process_id_wname();
|
||||
if(!dir_created)
|
||||
ipcdetail::create_directory(shared_dir.c_str(), true);
|
||||
ipcdetail::open_or_create_shared_directory(shared_dir.c_str());
|
||||
dir_created = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ inline void get_shared_dir(std::string &shared_dir)
|
||||
shared_dir += "/boostipctest_";
|
||||
shared_dir += boost::interprocess::test::get_process_id_name();
|
||||
if(!dir_created)
|
||||
ipcdetail::create_directory(shared_dir.c_str(), true);
|
||||
ipcdetail::open_or_create_shared_directory(shared_dir.c_str());
|
||||
dir_created = true;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ inline void get_shared_dir(std::wstring &shared_dir)
|
||||
shared_dir += L"/boostipctest_";
|
||||
shared_dir += boost::interprocess::test::get_process_id_wname();
|
||||
if(!dir_created)
|
||||
ipcdetail::create_directory(shared_dir.c_str(), true);
|
||||
ipcdetail::open_or_create_shared_directory(shared_dir.c_str());
|
||||
dir_created = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user