From 649a22e07058d6d40200e78bd089524f059a1be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Thu, 23 Apr 2015 00:30:52 -0400 Subject: [PATCH] fileutils: add isDirectory The method returns true if given path is a directory filesystem entry Refs #68196 Change-Id: I983b23aec24e30321483b3f90d0ef9ccacbc515f --- src/fileutils.cpp | 8 ++++++++ src/fileutils.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/fileutils.cpp b/src/fileutils.cpp index 1b66b332ca..c6c40bf840 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -214,6 +214,14 @@ expand_path(const std::string &path) #endif } +bool isDirectory(const std::string& path) +{ + struct stat s; + if (stat(path.c_str(), &s) == 0) + return s.st_mode & S_IFDIR; + return false; +} + bool isDirectoryWritable(const std::string &directory) { return access(directory.c_str(), W_OK) == 0; diff --git a/src/fileutils.h b/src/fileutils.h index 192fba0122..d784e7b3c8 100644 --- a/src/fileutils.h +++ b/src/fileutils.h @@ -67,6 +67,8 @@ namespace ring { namespace fileutils { bool recursive_mkdir(const std::string& path); #endif + bool isDirectory(const std::string& path); + /** * Read content of the directory. * The result is a list of full paths of files in the directory, -- GitLab