#define __CONTEXT_SERVER_UTIL_H__
#include <string>
+#include <vector>
#include <tzplatform_config.h>
#include <ContextTypes.h>
std::string getUserPath(uid_t uid, enum tzplatform_variable id, const std::string& path);
+ std::vector<std::string> getFiles(const std::string& dir, bool symlink = false);
+
} }
#endif /* __CONTEXT_SERVER_UTIL_H__ */
* limitations under the License.
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
#include <ScopeMutex.h>
#include <ClientBase.h>
#include <ServiceBase.h>
tzplatform_context_destroy(context);
return outPath;
}
+
+EXPORT_API std::vector<std::string> util::getFiles(const std::string& dirPath, bool symlink)
+{
+ static GMutex dirMutex;
+
+ DIR* dir = NULL;
+ struct dirent* entry = NULL;
+ struct stat fileStat;
+ std::string filePath;
+ std::vector<std::string> fileNames;
+
+ ScopeMutex sm(&dirMutex);
+
+ dir = opendir(dirPath.c_str());
+ IF_FAIL_RETURN_TAG(dir, fileNames, _E, "Failed to open: %s", dirPath.c_str());
+
+ while (true) {
+ entry = readdir(dir);
+ if (!entry)
+ break;
+
+ filePath = dirPath + "/" + entry->d_name;
+ if (symlink) {
+ if (stat(filePath.c_str(), &fileStat) != 0)
+ continue;
+ } else {
+ if (lstat(filePath.c_str(), &fileStat) != 0)
+ continue;
+ }
+
+ if (!S_ISREG(fileStat.st_mode))
+ continue;
+
+ fileNames.push_back(entry->d_name);
+ }
+
+ closedir(dir);
+ return fileNames;
+}