file_utils: add exists_dir_at()

parent ae9215cf
......@@ -539,3 +539,15 @@ int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset)
return 0;
}
bool exists_dir_at(int dir_fd, const char *path)
{
struct stat sb;
int ret;
ret = fstatat(dir_fd, path, &sb, 0);
if (ret < 0)
return false;
return S_ISDIR(sb.st_mode);
}
......@@ -73,5 +73,6 @@ __hidden extern int lxc_open_dirfd(const char *dir);
__hidden extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer);
__hidden extern FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer);
__hidden extern int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset);
__hidden extern bool exists_dir_at(int dir_fd, const char *path);
#endif /* __LXC_FILE_UTILS_H */
......@@ -569,15 +569,7 @@ gid_t get_ns_gid(gid_t orig)
bool dir_exists(const char *path)
{
struct stat sb;
int ret;
ret = stat(path, &sb);
if (ret < 0)
/* Could be something other than eexist, just say "no". */
return false;
return S_ISDIR(sb.st_mode);
return exists_dir_at(-1, path);
}
/* Note we don't use SHA-1 here as we don't want to depend on HAVE_GNUTLS.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment