mirror of
https://github.com/polybar/polybar.git
synced 2026-03-03 06:52:57 +00:00
config: Better error messages when opening files
If a config file is a directory, ifstream would just read it as an empty file without any errors. Failing early here is a good idea.
This commit is contained in:
committed by
Patrick Ziegler
parent
9d31b51a63
commit
75eb41f5ad
@ -170,12 +170,29 @@ int fd_streambuf::underflow() {
|
||||
namespace file_util {
|
||||
/**
|
||||
* Checks if the given file exist
|
||||
*
|
||||
* May also return false if the file status cannot be read
|
||||
*
|
||||
* Sets errno when returning false
|
||||
*/
|
||||
bool exists(const string& filename) {
|
||||
struct stat buffer {};
|
||||
return stat(filename.c_str(), &buffer) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given path exists and is a file
|
||||
*/
|
||||
bool is_file(const string& filename) {
|
||||
struct stat buffer {};
|
||||
|
||||
if (stat(filename.c_str(), &buffer) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return S_ISREG(buffer.st_mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Picks the first existing file out of given entries
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user