lib: use join_paths
Convert some manual concatenation to the new join_paths helper.
This commit is contained in:
@ -33,6 +33,7 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "utils/mu-utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
|
#include "utils/mu-utils-file.hh"
|
||||||
#include "utils/mu-error.hh"
|
#include "utils/mu-error.hh"
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
@ -44,10 +45,7 @@ struct Scanner::Private {
|
|||||||
if (!handler_)
|
if (!handler_)
|
||||||
throw Mu::Error{Error::Code::Internal, "missing handler"};
|
throw Mu::Error{Error::Code::Internal, "missing handler"};
|
||||||
}
|
}
|
||||||
~Private()
|
~Private() { stop(); }
|
||||||
{
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool start();
|
bool start();
|
||||||
bool stop();
|
bool stop();
|
||||||
@ -67,9 +65,6 @@ is_dotdir(const char *d_name)
|
|||||||
if (d_name[0] == '\0' || (d_name[1] == '\0' && d_name[0] == '.') ||
|
if (d_name[0] == '\0' || (d_name[1] == '\0' && d_name[0] == '.') ||
|
||||||
(d_name[2] == '\0' && d_name[0] == '.' && d_name[1] == '.'))
|
(d_name[2] == '\0' && d_name[0] == '.' && d_name[1] == '.'))
|
||||||
return true;
|
return true;
|
||||||
/* gnus? */
|
|
||||||
if (d_name[0] == '.' && g_strcmp0(d_name + 1, "nnmaildir") == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -97,7 +92,7 @@ Scanner::Private::process_dentry(const std::string& path, struct dirent *dentry,
|
|||||||
return true; // ignore
|
return true; // ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto fullpath{path + "/" + d_name};
|
const auto fullpath{join_paths(path, d_name)};
|
||||||
struct stat statbuf {};
|
struct stat statbuf {};
|
||||||
if (::stat(fullpath.c_str(), &statbuf) != 0) {
|
if (::stat(fullpath.c_str(), &statbuf) != 0) {
|
||||||
g_warning("failed to stat %s: %s", fullpath.c_str(), g_strerror(errno));
|
g_warning("failed to stat %s: %s", fullpath.c_str(), g_strerror(errno));
|
||||||
|
|||||||
@ -73,7 +73,7 @@ Mu::message_file_parts(const std::string& file)
|
|||||||
Mu::Result<DirFile>
|
Mu::Result<DirFile>
|
||||||
Mu::base_message_dir_file(const std::string& path)
|
Mu::base_message_dir_file(const std::string& path)
|
||||||
{
|
{
|
||||||
constexpr auto newdir{ G_DIR_SEPARATOR_S "new"};
|
constexpr auto newdir{"/new"};
|
||||||
|
|
||||||
char *dirname{g_path_get_dirname(path.c_str())};
|
char *dirname{g_path_get_dirname(path.c_str())};
|
||||||
bool is_new{!!g_str_has_suffix(dirname, newdir)};
|
bool is_new{!!g_str_has_suffix(dirname, newdir)};
|
||||||
|
|||||||
@ -74,7 +74,7 @@ create_maildir(const std::string& path, mode_t mode)
|
|||||||
std::array<std::string,3> subdirs = {"new", "cur", "tmp"};
|
std::array<std::string,3> subdirs = {"new", "cur", "tmp"};
|
||||||
for (auto&& subdir: subdirs) {
|
for (auto&& subdir: subdirs) {
|
||||||
|
|
||||||
const auto fullpath{path + G_DIR_SEPARATOR_S + subdir};
|
const auto fullpath{join_paths(path, subdir)};
|
||||||
|
|
||||||
/* if subdir already exists, don't try to re-create
|
/* if subdir already exists, don't try to re-create
|
||||||
* it */
|
* it */
|
||||||
@ -98,7 +98,7 @@ create_maildir(const std::string& path, mode_t mode)
|
|||||||
static Mu::Result<void> /* create a noindex file if requested */
|
static Mu::Result<void> /* create a noindex file if requested */
|
||||||
create_noindex(const std::string& path)
|
create_noindex(const std::string& path)
|
||||||
{
|
{
|
||||||
const auto noindexpath{path + G_DIR_SEPARATOR_S MU_MAILDIR_NOINDEX_FILE};
|
const auto noindexpath{join_paths(path, MU_MAILDIR_NOINDEX_FILE)};
|
||||||
|
|
||||||
/* note, if the 'close' failed, creation may still have succeeded...*/
|
/* note, if the 'close' failed, creation may still have succeeded...*/
|
||||||
int fd = ::creat(noindexpath.c_str(), 0644);
|
int fd = ::creat(noindexpath.c_str(), 0644);
|
||||||
@ -163,18 +163,15 @@ get_target_fullpath(const std::string& src, const std::string& targetpath,
|
|||||||
*/
|
*/
|
||||||
std::string fulltargetpath;
|
std::string fulltargetpath;
|
||||||
if (unique_names)
|
if (unique_names)
|
||||||
fulltargetpath = format("%s%c%s%c%u_%s",
|
fulltargetpath = join_paths(targetpath,
|
||||||
targetpath.c_str(),
|
in_cur ? "cur" : "new",
|
||||||
G_DIR_SEPARATOR, in_cur ? "cur" : "new",
|
format("%u_%s",
|
||||||
G_DIR_SEPARATOR,
|
g_str_hash(src.c_str()),
|
||||||
g_str_hash(src.c_str()),
|
srcfile));
|
||||||
srcfile);
|
|
||||||
else
|
else
|
||||||
fulltargetpath = format("%s%c%s%c%s",
|
fulltargetpath = join_paths(targetpath,
|
||||||
targetpath.c_str(),
|
in_cur ? "cur" : "new",
|
||||||
G_DIR_SEPARATOR, in_cur ? "cur" : "new",
|
srcfile);
|
||||||
G_DIR_SEPARATOR,
|
|
||||||
srcfile);
|
|
||||||
g_free(srcfile);
|
g_free(srcfile);
|
||||||
|
|
||||||
return fulltargetpath;
|
return fulltargetpath;
|
||||||
@ -213,8 +210,7 @@ clear_links(const std::string& path, DIR* dir)
|
|||||||
if (dentry->d_name[0] == '.')
|
if (dentry->d_name[0] == '.')
|
||||||
continue; /* ignore .,.. other dotdirs */
|
continue; /* ignore .,.. other dotdirs */
|
||||||
|
|
||||||
const auto fullpath{
|
const auto fullpath{join_paths(path, dentry->d_name)};
|
||||||
format("%s" G_DIR_SEPARATOR_S "%s",path.c_str(), dentry->d_name)};
|
|
||||||
const auto d_type = get_dtype(dentry, fullpath.c_str(), true/*lstat*/);
|
const auto d_type = get_dtype(dentry, fullpath.c_str(), true/*lstat*/);
|
||||||
switch(d_type) {
|
switch(d_type) {
|
||||||
case DT_LNK:
|
case DT_LNK:
|
||||||
@ -441,8 +437,8 @@ Mu::maildir_determine_target(const std::string& old_path,
|
|||||||
|
|
||||||
/* if target_mdir is empty, the src_dir does not change (though cur/
|
/* if target_mdir is empty, the src_dir does not change (though cur/
|
||||||
* maybe become new or vice-versa) */
|
* maybe become new or vice-versa) */
|
||||||
const auto dst_mdir{target_maildir.empty() ? src_mdir :
|
const auto dst_mdir = target_maildir.empty() ? src_mdir :
|
||||||
root_maildir_path + target_maildir};
|
join_paths(root_maildir_path, target_maildir);
|
||||||
|
|
||||||
/* now calculate the message name (incl. its immediate parent dir) */
|
/* now calculate the message name (incl. its immediate parent dir) */
|
||||||
const auto dst_file{determine_dst_filename(src_file, newflags, new_name)};
|
const auto dst_file{determine_dst_filename(src_file, newflags, new_name)};
|
||||||
@ -455,5 +451,5 @@ Mu::maildir_determine_target(const std::string& old_path,
|
|||||||
return "new";
|
return "new";
|
||||||
});
|
});
|
||||||
|
|
||||||
return dst_mdir + G_DIR_SEPARATOR_S + subdir + G_DIR_SEPARATOR_S + dst_file;
|
return join_paths(dst_mdir, subdir,dst_file);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,11 +153,9 @@ Mu::runtime_path(Mu::RuntimePath path, const std::string& muhome)
|
|||||||
{
|
{
|
||||||
auto [mu_cache, mu_config] =
|
auto [mu_cache, mu_config] =
|
||||||
std::invoke([&]()->std::pair<std::string, std::string> {
|
std::invoke([&]()->std::pair<std::string, std::string> {
|
||||||
|
|
||||||
static std::string mu{"/mu"};
|
|
||||||
if (muhome.empty())
|
if (muhome.empty())
|
||||||
return { g_get_user_cache_dir() + mu,
|
return { join_paths(g_get_user_cache_dir(), "mu"),
|
||||||
g_get_user_config_dir() + mu };
|
join_paths(g_get_user_config_dir(), "mu")};
|
||||||
else
|
else
|
||||||
return { muhome, muhome };
|
return { muhome, muhome };
|
||||||
});
|
});
|
||||||
@ -166,15 +164,15 @@ Mu::runtime_path(Mu::RuntimePath path, const std::string& muhome)
|
|||||||
case Mu::RuntimePath::Cache:
|
case Mu::RuntimePath::Cache:
|
||||||
return mu_cache;
|
return mu_cache;
|
||||||
case Mu::RuntimePath::XapianDb:
|
case Mu::RuntimePath::XapianDb:
|
||||||
return mu_cache + "/xapian";
|
return join_paths(mu_cache, "xapian");
|
||||||
case Mu::RuntimePath::LogFile:
|
case Mu::RuntimePath::LogFile:
|
||||||
return mu_cache + "/mu.log";
|
return join_paths(mu_cache, "mu.log");
|
||||||
case Mu::RuntimePath::Bookmarks:
|
case Mu::RuntimePath::Bookmarks:
|
||||||
return mu_config + "/bookmarks";
|
return join_paths(mu_config, "bookmarks");
|
||||||
case Mu::RuntimePath::Config:
|
case Mu::RuntimePath::Config:
|
||||||
return mu_config;
|
return mu_config;
|
||||||
case Mu::RuntimePath::Scripts:
|
case Mu::RuntimePath::Scripts:
|
||||||
return mu_config + "/scripts";
|
return join_paths(mu_config, "scripts");
|
||||||
default:
|
default:
|
||||||
throw std::logic_error("unknown path");
|
throw std::logic_error("unknown path");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user