summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2020-05-26 19:07:56 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2020-05-26 19:22:41 +0300
commitfdac81e023a7bc33cffd4e2425fb5f52df8aa002 (patch)
tree645f8e5b4e50b202ffab0a91fed368477c1bd356 /lib/utils
parent015fae7b1ab944b2104643a2b079db5063703c63 (diff)
lib: follow symlinks in maildirs
Until now, mu would _not_ follow symlinks; with these changes, we do. There were some complications with that ~10 years ago, but I forgot the details. So let's re-enable. At least one thing is in place now: moving between file systems. Fixes #1489 Fixes #1628 (technically, this came with slightly earlier commit)
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/mu-util.c14
-rw-r--r--lib/utils/mu-util.h11
-rw-r--r--lib/utils/test-mu-util.c6
3 files changed, 20 insertions, 11 deletions
diff --git a/lib/utils/mu-util.c b/lib/utils/mu-util.c
index 9f76c3a..d988521 100644
--- a/lib/utils/mu-util.c
+++ b/lib/utils/mu-util.c
@@ -340,14 +340,21 @@ mu_util_play (const char *path, gboolean allow_local, gboolean allow_remote,
unsigned char
-mu_util_get_dtype_with_lstat (const char *path)
+mu_util_get_dtype (const char *path, gboolean use_lstat)
{
+ int res;
struct stat statbuf;
g_return_val_if_fail (path, DT_UNKNOWN);
- if (lstat (path, &statbuf) != 0) {
- g_warning ("stat failed on %s: %s", path, strerror(errno));
+ if (use_lstat)
+ res = lstat (path, &statbuf);
+ else
+ res = stat (path, &statbuf);
+
+ if (res != 0) {
+ g_warning ("%sstat failed on %s: %s",
+ use_lstat ? "l" : "", path, strerror(errno));
return DT_UNKNOWN;
}
@@ -363,6 +370,7 @@ mu_util_get_dtype_with_lstat (const char *path)
}
+
gboolean
mu_util_locale_is_utf8 (void)
{
diff --git a/lib/utils/mu-util.h b/lib/utils/mu-util.h
index 72be341..3bde4ba 100644
--- a/lib/utils/mu-util.h
+++ b/lib/utils/mu-util.h
@@ -257,15 +257,16 @@ enum {
/**
- * get the d_type (as in direntry->d_type) for the file at path, using
-* lstat(3)
+ * get the d_type (as in direntry->d_type) for the file at path, using either
+ * stat(3) or lstat(3)
*
* @param path full path
+ * @param use_lstat whether to use lstat (otherwise use stat)
*
- * @return DT_REG, DT_DIR, DT_LNK, or DT_UNKNOWN (other values are not
- * supported currently )
+ * @return DT_REG, DT_DIR, DT_LNK, or DT_UNKNOWN (other values are not supported
+ * currently )
*/
-unsigned char mu_util_get_dtype_with_lstat (const char *path);
+unsigned char mu_util_get_dtype (const char *path, gboolean use_lstat);
/**
diff --git a/lib/utils/test-mu-util.c b/lib/utils/test-mu-util.c
index f3b0277..7e6c4a5 100644
--- a/lib/utils/test-mu-util.c
+++ b/lib/utils/test-mu-util.c
@@ -165,11 +165,11 @@ static void
test_mu_util_get_dtype_with_lstat (void)
{
g_assert_cmpuint (
- mu_util_get_dtype_with_lstat (MU_TESTMAILDIR), ==, DT_DIR);
+ mu_util_get_dtype (MU_TESTMAILDIR, TRUE), ==, DT_DIR);
g_assert_cmpuint (
- mu_util_get_dtype_with_lstat (MU_TESTMAILDIR2), ==, DT_DIR);
+ mu_util_get_dtype (MU_TESTMAILDIR2, TRUE), ==, DT_DIR);
g_assert_cmpuint (
- mu_util_get_dtype_with_lstat (MU_TESTMAILDIR2 "/Foo/cur/mail5"),
+ mu_util_get_dtype (MU_TESTMAILDIR2 "/Foo/cur/mail5", TRUE),
==, DT_REG);
}