Recursively chown a path. Logs warnings but does not abort on failure.
| 267 | |
| 268 | /// Recursively chown a path. Logs warnings but does not abort on failure. |
| 269 | void recursiveChown(const std::string & path_str, uid_t uid, gid_t gid) |
| 270 | { |
| 271 | if (lchown(path_str.c_str(), uid, gid) < 0) |
| 272 | std::cerr << "docker-init: warning: lchown " << path_str << ": " << strerror(errno) << "\n"; // NOLINT(concurrency-mt-unsafe) |
| 273 | |
| 274 | std::error_code ec; |
| 275 | if (!fs::is_directory(path_str, ec)) |
| 276 | return; |
| 277 | |
| 278 | for (const auto & entry : fs::recursive_directory_iterator(path_str, fs::directory_options::skip_permission_denied, ec)) |
| 279 | { |
| 280 | if (lchown(entry.path().c_str(), uid, gid) < 0) |
| 281 | std::cerr << "docker-init: warning: lchown " << entry.path() << ": " << strerror(errno) << "\n"; // NOLINT(concurrency-mt-unsafe) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | /// Create a directory (and all parents) and optionally chown it. |
| 286 | /// |
no test coverage detected