0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd::magic: Add conf item for magic file path; default to $MAGIC from environment. #138

This commit is contained in:
Jason Volk 2020-04-19 17:51:51 -07:00
parent a063b4a681
commit f86a938a8a
2 changed files with 32 additions and 9 deletions

View file

@ -80,8 +80,8 @@
#include "fmt.h"
#include "http.h"
#include "http2/http2.h"
#include "magic.h"
#include "conf.h"
#include "magic.h"
#include "stats.h"
#include "prof/prof.h"
#include "fs/fs.h"

View file

@ -12,7 +12,7 @@
namespace ircd::magic
{
extern const char *const fallback_paths[]
extern const char *const fallback_paths[];
extern magic_t cookie;
extern int flags;
@ -35,6 +35,13 @@ ircd::magic::version_abi
"magic", info::versions::ABI, ::magic_version()
};
decltype(ircd::magic::file_path)
ircd::magic::file_path
{
{ "name", "ircd.magic.file" },
{ "default", getenv("MAGIC") },
};
decltype(ircd::magic::fallback_paths)
ircd::magic::fallback_paths
{
@ -61,15 +68,31 @@ ircd::magic::flags
ircd::magic::init::init()
{
const auto load
{
[](const string_view &path)
{
return !empty(path)
&& fs::exists(path)
&& magic_check(cookie, fs::path_cstr(path)) == 0
&& magic_load(cookie, fs::path_cstr(path)) == 0
;
}
};
version_check();
if(unlikely(!(cookie = ::magic_open(flags))))
throw error{"magic_open() failed"};
throw error
{
"magic_open() failed"
};
for(const char *const *path{paths}; *path; ++path)
if(fs::exists(*path))
if(magic_check(cookie, *path) == 0)
if(magic_load(cookie, *path) == 0)
// Try the conf item first
if(load(string_view(file_path)))
return;
for(const char *const *path{fallback_paths}; *path; ++path)
if(load(*path))
return;
throw error