mirror of https://github.com/djcb/mu.git
mu: allow relative message paths in mu commands
This commit is contained in:
parent
6f2c934d72
commit
cd23e6015d
|
@ -73,11 +73,13 @@ struct Message::Private {
|
||||||
static void fill_document(Message::Private& priv);
|
static void fill_document(Message::Private& priv);
|
||||||
|
|
||||||
static Result<struct stat>
|
static Result<struct stat>
|
||||||
get_statbuf(const std::string& path)
|
get_statbuf(const std::string& path, Message::Options opts = Message::Options::None)
|
||||||
{
|
{
|
||||||
if (!g_path_is_absolute(path.c_str()))
|
if (none_of(opts & Message::Options::AllowRelativePath) &&
|
||||||
|
!g_path_is_absolute(path.c_str()))
|
||||||
return Err(Error::Code::File, "path '%s' is not absolute",
|
return Err(Error::Code::File, "path '%s' is not absolute",
|
||||||
path.c_str());
|
path.c_str());
|
||||||
|
|
||||||
if (::access(path.c_str(), R_OK) != 0)
|
if (::access(path.c_str(), R_OK) != 0)
|
||||||
return Err(Error::Code::File, "file @ '%s' is not readable",
|
return Err(Error::Code::File, "file @ '%s' is not readable",
|
||||||
path.c_str());
|
path.c_str());
|
||||||
|
@ -97,7 +99,7 @@ get_statbuf(const std::string& path)
|
||||||
Message::Message(const std::string& path, Message::Options opts):
|
Message::Message(const std::string& path, Message::Options opts):
|
||||||
priv_{std::make_unique<Private>(opts)}
|
priv_{std::make_unique<Private>(opts)}
|
||||||
{
|
{
|
||||||
const auto statbuf{get_statbuf(path)};
|
const auto statbuf{get_statbuf(path, opts)};
|
||||||
if (!statbuf)
|
if (!statbuf)
|
||||||
throw statbuf.error();
|
throw statbuf.error();
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,12 @@ namespace Mu {
|
||||||
class Message {
|
class Message {
|
||||||
public:
|
public:
|
||||||
enum struct Options {
|
enum struct Options {
|
||||||
None = 0, /**< Defaults */
|
None = 0, /**< Defaults */
|
||||||
Decrypt = 1 << 0, /**< Attempt to decrypt */
|
Decrypt = 1 << 0, /**< Attempt to decrypt */
|
||||||
RetrieveKeys = 1 << 1, /**< Auto-retrieve crypto keys (implies network
|
RetrieveKeys = 1 << 1, /**< Auto-retrieve crypto keys (implies network
|
||||||
* access) */
|
* access) */
|
||||||
|
AllowRelativePath = 1 << 2, /**< Allow relateive paths for filename
|
||||||
|
* in make_from_path */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -156,12 +156,7 @@ handle_msg(const std::string& fname, const Options& opts)
|
||||||
{
|
{
|
||||||
using Format = Options::View::Format;
|
using Format = Options::View::Format;
|
||||||
|
|
||||||
// make absolute.
|
auto message{Message::make_from_path(fname, message_options(opts.view))};
|
||||||
const auto fpath{to_string_opt_gchar(g_canonicalize_filename(fname.c_str(), NULL))};
|
|
||||||
if (!fpath)
|
|
||||||
return Err(Error::Code::File, "invalid file '%s'", fname.c_str());
|
|
||||||
|
|
||||||
auto message{Message::make_from_path(*fpath, message_options(opts.view))};
|
|
||||||
if (!message)
|
if (!message)
|
||||||
return Err(message.error());
|
return Err(message.error());
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ template<typename CmdOpts>
|
||||||
constexpr Message::Options
|
constexpr Message::Options
|
||||||
message_options(const CmdOpts& cmdopts)
|
message_options(const CmdOpts& cmdopts)
|
||||||
{
|
{
|
||||||
Message::Options mopts{};
|
Message::Options mopts{Message::Options::AllowRelativePath};
|
||||||
|
|
||||||
if (cmdopts.decrypt)
|
if (cmdopts.decrypt)
|
||||||
mopts |= Message::Options::Decrypt;
|
mopts |= Message::Options::Decrypt;
|
||||||
|
|
Loading…
Reference in New Issue