Skip to content

Commit e27493d

Browse files
committed
Use the helpers only privately
1 parent 318b581 commit e27493d

2 files changed

Lines changed: 32 additions & 35 deletions

File tree

include/openPMD/auxiliary/Filesystem.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#pragma once
2222

2323
#include <string>
24-
#include <sys/types.h>
2524
#include <vector>
2625

2726
#include "openPMD/config.hpp"
@@ -67,10 +66,6 @@ namespace auxiliary
6766
*/
6867
std::vector<std::string> list_directory(std::string const &path);
6968

70-
std::string get_parent(std::string const &path);
71-
72-
mode_t get_permissions(std::string const &path);
73-
7469
/** Create all required directories to have a reachable given absolute or
7570
* relative path.
7671
*

src/auxiliary/Filesystem.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -96,43 +96,45 @@ std::vector<std::string> list_directory(std::string const &path)
9696
return ret;
9797
}
9898

99-
std::string get_parent(std::string const &path)
99+
#ifndef _WIN32
100+
// Need to manually preserve sticky bit and setgid on Unix systems
101+
namespace
100102
{
101-
std::string parent = path;
102-
size_t pos = parent.find_last_of(directory_separator);
103-
if (pos != std::string::npos)
103+
std::string get_parent(std::string const &path)
104104
{
105-
parent = parent.substr(0, pos);
106-
if (parent.empty())
107-
parent = "/";
108-
}
109-
else
110-
{
111-
parent.clear();
105+
std::string parent = path;
106+
size_t pos = parent.find_last_of(directory_separator);
107+
if (pos != std::string::npos)
108+
{
109+
parent = parent.substr(0, pos);
110+
if (parent.empty())
111+
parent = "/";
112+
}
113+
else
114+
{
115+
parent.clear();
116+
}
117+
return parent;
112118
}
113-
return parent;
114-
}
115119

116-
mode_t get_permissions(std::string const &path)
117-
{
118-
std::string parent = get_parent(path);
119-
if (parent.empty())
120+
mode_t get_permissions(std::string const &path)
120121
{
121-
return 0;
122-
}
123-
if (!directory_exists(parent))
124-
{
125-
return 0;
126-
}
122+
std::string parent = get_parent(path);
123+
if (parent.empty() || !directory_exists(parent))
124+
{
125+
return 0;
126+
}
127127

128-
struct stat s;
129-
if (stat(parent.c_str(), &s) != 0)
130-
{
131-
return 0;
132-
}
128+
struct stat s;
129+
if (stat(parent.c_str(), &s) != 0)
130+
{
131+
return 0;
132+
}
133133

134-
return s.st_mode & 07777;
135-
}
134+
return s.st_mode & 07777;
135+
}
136+
} // namespace
137+
#endif
136138

137139
bool create_directories(std::string const &path)
138140
{

0 commit comments

Comments
 (0)