From a1891219175503cc2c9d3ccbdfc19606e84c60e8 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 17 Sep 2018 12:23:21 -0400 Subject: [PATCH] Add support for rc files as symlinks This prevents a symlink from being overwritten with an actual file contents. Instead, the symlink is preserved, and its target gets updated. Fixes bug #14698 --- libxfce4util/xfce-rc-simple.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libxfce4util/xfce-rc-simple.c b/libxfce4util/xfce-rc-simple.c index c615d93..d2604da 100644 --- a/libxfce4util/xfce-rc-simple.c +++ b/libxfce4util/xfce-rc-simple.c @@ -699,7 +699,8 @@ void _xfce_rc_simple_flush (XfceRc *rc) { XfceRcSimple *simple = XFCE_RC_SIMPLE (rc); - gchar tmp_path[PATH_MAX]; + gchar *filename = simple->filename; + gchar tmp_path[PATH_MAX], buf[PATH_MAX] = {0}; if (G_UNLIKELY (!simple->dirty)) return; @@ -707,11 +708,15 @@ _xfce_rc_simple_flush (XfceRc *rc) g_snprintf (tmp_path, PATH_MAX, "%s.%d.tmp", simple->filename, (int)getpid ()); if (simple_write (simple, tmp_path)) { - if (rename (tmp_path, simple->filename) < 0) + /* support rc file being a symlink: see bug #14698 */ + if (readlink (simple->filename, buf, sizeof (buf)-1) != -1) + filename = buf; + + if (rename (tmp_path, filename) < 0) { g_critical ("Unable to rename %s to %s: %s", tmp_path, - simple->filename, + filename, g_strerror (errno)); unlink (tmp_path); } -- 2.19.0