refactor(file_util): Expand tilde manually

This commit is contained in:
Michael Carlberg
2017-01-25 17:07:55 +01:00
parent 9d589fa5a7
commit 95d5b03fa2
6 changed files with 17 additions and 16 deletions

View File

@ -7,6 +7,7 @@
#include <streambuf>
#include "errors.hpp"
#include "utils/env.hpp"
#include "utils/file.hpp"
POLYBAR_NS
@ -207,11 +208,17 @@ namespace file_util {
/**
* Get glob results using given pattern
*/
vector<string> glob(const string& pattern) {
vector<string> glob(string pattern) {
glob_t result{};
vector<string> ret;
if (glob(pattern.c_str(), GLOB_TILDE, nullptr, &result) == 0) {
// Manually expand tilde to fix builds using versions of libc
// that doesn't provide the GLOB_TILDE flag (musl for example)
if (pattern[0] == '~') {
pattern.replace(0, 1, env_util::get("HOME"));
}
if (::glob(pattern.c_str(), 0, nullptr, &result) == 0) {
for (size_t i = 0_z; i < result.gl_pathc; ++i) {
ret.emplace_back(result.gl_pathv[i]);
}