diff options
author | Pavel Šimerda <psimerda@redhat.com> | 2014-09-02 13:25:19 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-01-23 18:42:58 +0100 |
commit | 02831c50591e570c8e714521c4d735eeeca7b954 (patch) | |
tree | aee8eb1d0250db0fec10246b8a63c002c3367a83 | |
parent | 868611767800656fc9b59613075c97730055b7b3 (diff) | |
download | NetworkManager-th/keyfile-escape-file-bgo735824.tar.gz |
keyfile: ignore all dot files (bgo#735824)th/keyfile-escape-file-bgo735824
https://bugzilla.gnome.org/show_bug.cgi?id=735824
-rw-r--r-- | src/settings/plugins/keyfile/tests/test-keyfile.c | 2 | ||||
-rw-r--r-- | src/settings/plugins/keyfile/utils.c | 27 |
2 files changed, 14 insertions, 15 deletions
diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index 094e4a775e..a81e55011f 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -3590,7 +3590,7 @@ test_nm_keyfile_plugin_utils_escape_filename (void) _escape_filename (".mkstemp.A23456", TRUE); _escape_filename (".#emacs-locking", TRUE); _escape_filename ("file-with-tilde~", TRUE); - _escape_filename (".file-with-dot", FALSE); + _escape_filename (".file-with-dot", TRUE); } /*****************************************************************************/ diff --git a/src/settings/plugins/keyfile/utils.c b/src/settings/plugins/keyfile/utils.c index 3fa7ae2879..1643941930 100644 --- a/src/settings/plugins/keyfile/utils.c +++ b/src/settings/plugins/keyfile/utils.c @@ -23,6 +23,7 @@ #include <glib.h> #include <stdlib.h> #include <string.h> +#include "gsystem-local-alloc.h" #include "utils.h" #include <nm-setting-wired.h> #include <nm-setting-wireless.h> @@ -87,27 +88,25 @@ check_suffix (const char *base, const char *tag) gboolean nm_keyfile_plugin_utils_should_ignore_file (const char *filename) { - char *base; - gboolean ignore = FALSE; + gs_free char *base = NULL; g_return_val_if_fail (filename != NULL, TRUE); base = g_path_get_basename (filename); g_return_val_if_fail (base != NULL, TRUE); - /* Ignore files with certain patterns */ + /* Ignore hidden and backup files */ /* should_ignore_file() must mirror escape_filename() */ - if ( (check_prefix (base, ".") && check_suffix (base, SWP_TAG)) /* vim temporary files: .filename.swp */ - || (check_prefix (base, ".") && check_suffix (base, SWPX_TAG)) /* vim temporary files: .filename.swpx */ - || check_suffix (base, PEM_TAG) /* 802.1x certificates and keys */ - || check_suffix (base, DER_TAG) /* 802.1x certificates and keys */ - || check_mkstemp_suffix (base) /* temporary files created by mkstemp() */ - || check_prefix (base, ".#") /* Emacs locking file (link) */ - || base[strlen (base) - 1] == '~') - ignore = TRUE; - - g_free (base); - return ignore; + if (check_prefix (base, ".") || check_suffix (base, "~")) + return TRUE; + /* Ignore temporary files */ + if (check_mkstemp_suffix (base)) + return TRUE; + /* Ignore 802.1x certificates and keys */ + if (check_suffix (base, PEM_TAG) || check_suffix (base, DER_TAG)) + return TRUE; + + return FALSE; } char * |