]> err.no Git - systemd/commitdiff
util: unify code to check whether certain file names should be ignored when listing...
authorLennart Poettering <lennart@poettering.net>
Sun, 14 Feb 2010 00:07:01 +0000 (01:07 +0100)
committerLennart Poettering <lennart@poettering.net>
Sun, 14 Feb 2010 00:07:01 +0000 (01:07 +0100)
load-dropin.c
util.c
util.h

index af95d37a0313d9046d6849fd347e9b29beec969f..a3c9d3c77dde42b5eb859494eff1bd7880220ad6 100644 (file)
@@ -60,12 +60,8 @@ int unit_load_dropin(Unit *u) {
                         free(path);
 
                         while ((de = readdir(d))) {
-                                if (de->d_name[0] == '.')
-                                        continue;
-
-                                assert(de->d_name[0]);
 
-                                if (de->d_name[strlen(de->d_name)-1] == '~')
+                                if (ignore_file(de->d_name))
                                         continue;
 
                                 if (asprintf(&path, "%s/%s.wants/%s", *p, t, de->d_name) < 0) {
diff --git a/util.c b/util.c
index 496f55166b7f35a1dad171fbe7c2541a97dd7fa8..e31649861d3b642b16396c99a1787cc8baaacc53 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1058,6 +1058,20 @@ char *ascii_strlower(char *path) {
         return p;
 }
 
+bool ignore_file(const char *filename) {
+        assert(filename);
+
+        return
+                filename[0] == '.' ||
+                endswith(filename, "~") ||
+                endswith(filename, ".rpmnew") ||
+                endswith(filename, ".rpmsave") ||
+                endswith(filename, ".rpmorig") ||
+                endswith(filename, ".dpkg-old") ||
+                endswith(filename, ".dpkg-new") ||
+                endswith(filename, ".swp");
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",
diff --git a/util.h b/util.h
index 71645a70ccc076d54e698757096d2b3eaba727d1..e005a2a072b6cd67cb45fe83510c3a0f172e004c 100644 (file)
--- a/util.h
+++ b/util.h
@@ -151,6 +151,8 @@ char *xescape(const char *s, const char *bad);
 char *bus_path_escape(const char *s);
 char *bus_path_unescape(const char *s);
 
+bool ignore_file(const char *filename);
+
 #define DEFINE_STRING_TABLE_LOOKUP(name,type)                           \
         const char *name##_to_string(type i) {                          \
                 if (i < 0 || i >= (type) ELEMENTSOF(name##_table))      \