]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: rename hidden_file to hidden_or_backup_file and optimize
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 27 Apr 2016 13:24:59 +0000 (09:24 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Apr 2016 12:25:17 +0000 (08:25 -0400)
In standard linux parlance, "hidden" usually means that the file name starts
with ".", and nothing else. Rename the function to convey what the function does
better to casual readers.

Stop exposing hidden_file_allow_backup which is rather ugly and rewrite
hidden_file to extract the suffix first. Note that hidden_file_allow_backup
excluded files with "~" at the end, which is quite confusing. Let's get
rid of it before it gets used in the wrong place.

src/basic/dirent-util.c
src/basic/dirent-util.h
src/basic/fd-util.c
src/basic/fdset.c
src/basic/path-util.c
src/basic/path-util.h
src/basic/util.c
src/shared/dropin.c
src/tty-ask-password-agent/tty-ask-password-agent.c

index 5019882a0adda998a8b41de6735089c4a81b85ea..59067121b74f0c93c56a27673eeb1c7cfa109e12 100644 (file)
@@ -52,10 +52,10 @@ int dirent_ensure_type(DIR *d, struct dirent *de) {
 bool dirent_is_file(const struct dirent *de) {
         assert(de);
 
-        if (hidden_file(de->d_name))
+        if (!IN_SET(de->d_type, DT_REG, DT_LNK, DT_UNKNOWN))
                 return false;
 
-        if (!IN_SET(de->d_type, DT_REG, DT_LNK, DT_UNKNOWN))
+        if (hidden_or_backup_file(de->d_name))
                 return false;
 
         return true;
index 6bf099b46c0a51ba6cb304aecfaf1e02d045d828..b91d04908f9a01545ed7f68e4f32fbc91323288d 100644 (file)
@@ -38,7 +38,7 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pu
                                 on_error;                               \
                         }                                               \
                         break;                                          \
-                } else if (hidden_file((de)->d_name))                   \
+                } else if (hidden_or_backup_file((de)->d_name))         \
                         continue;                                       \
                 else
 
index 3d46d708c7b766cbf966a9a9f85fec3a4ab6e0d4..9130d023d7f6ee0c5f9f88d4fc429cf737355f66 100644 (file)
@@ -231,7 +231,7 @@ int close_all_fds(const int except[], unsigned n_except) {
         while ((de = readdir(d))) {
                 int fd = -1;
 
-                if (hidden_file(de->d_name))
+                if (hidden_or_backup_file(de->d_name))
                         continue;
 
                 if (safe_atoi(de->d_name, &fd) < 0)
index 06f8ecbdbcf3c682c34bdb4f8b8296f10587c2d1..527f27bc67a730a5ef596ca20facb079cf46b8c1 100644 (file)
@@ -151,7 +151,7 @@ int fdset_new_fill(FDSet **_s) {
         while ((de = readdir(d))) {
                 int fd = -1;
 
-                if (hidden_file(de->d_name))
+                if (hidden_or_backup_file(de->d_name))
                         continue;
 
                 r = safe_atoi(de->d_name, &fd);
index 25aa355397a4d0b4771797e536ce43fecff9eaab..100e3f5af257f16dd23965b2ae62639313bec9cc 100644 (file)
@@ -756,37 +756,37 @@ char *file_in_same_dir(const char *path, const char *filename) {
         return ret;
 }
 
-bool hidden_file_allow_backup(const char *filename) {
-        assert(filename);
-
-        return
-                filename[0] == '.' ||
-                streq(filename, "lost+found") ||
-                streq(filename, "aquota.user") ||
-                streq(filename, "aquota.group") ||
-                endswith(filename, ".rpmnew") ||
-                endswith(filename, ".rpmsave") ||
-                endswith(filename, ".rpmorig") ||
-                endswith(filename, ".dpkg-old") ||
-                endswith(filename, ".dpkg-new") ||
-                endswith(filename, ".dpkg-tmp") ||
-                endswith(filename, ".dpkg-dist") ||
-                endswith(filename, ".dpkg-bak") ||
-                endswith(filename, ".dpkg-backup") ||
-                endswith(filename, ".dpkg-remove") ||
-                endswith(filename, ".ucf-new") ||
-                endswith(filename, ".ucf-old") ||
-                endswith(filename, ".ucf-dist") ||
-                endswith(filename, ".swp");
-}
+bool hidden_or_backup_file(const char *filename) {
+        const char *p;
 
-bool hidden_file(const char *filename) {
         assert(filename);
 
-        if (endswith(filename, "~"))
+        if (filename[0] == '.' ||
+            streq(filename, "lost+found") ||
+            streq(filename, "aquota.user") ||
+            streq(filename, "aquota.group") ||
+            endswith(filename, "~"))
                 return true;
 
-        return hidden_file_allow_backup(filename);
+        p = strrchr(filename, '.');
+        if (!p)
+                return false;
+
+        return STR_IN_SET(p + 1,
+                          "rpmnew",
+                          "rpmsave",
+                          "rpmorig",
+                          "dpkg-old",
+                          "dpkg-new",
+                          "dpkg-tmp",
+                          "dpkg-dist",
+                          "dpkg-bak",
+                          "dpkg-backup",
+                          "dpkg-remove",
+                          "ucf-new",
+                          "ucf-old",
+                          "ucf-dist",
+                          "swp");
 }
 
 bool is_device_path(const char *path) {
index 34d5cd1570b5135072227c12ca2884661da77fdd..a27c13fcc3a94cd0ae525d63dee7d1c6ec31fa86 100644 (file)
@@ -122,7 +122,6 @@ bool path_is_safe(const char *p) _pure_;
 
 char *file_in_same_dir(const char *path, const char *filename);
 
-bool hidden_file_allow_backup(const char *filename);
-bool hidden_file(const char *filename) _pure_;
+bool hidden_or_backup_file(const char *filename) _pure_;
 
 bool is_device_path(const char *path);
index b70c50047fb7c3d641f1d1b697174ca5e9155716..756c663be409cf7acace63b20fec3d38ef645688 100644 (file)
@@ -522,7 +522,7 @@ int on_ac_power(void) {
                 if (!de)
                         break;
 
-                if (hidden_file(de->d_name))
+                if (hidden_or_backup_file(de->d_name))
                         continue;
 
                 device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY);
index cc1acd6f235e1697f788776bbde19a8173bed91b..b9cd952ac8b80288d1bcd586a61748f772e79549 100644 (file)
@@ -160,7 +160,7 @@ static int iterate_dir(
                 if (!de)
                         break;
 
-                if (hidden_file(de->d_name))
+                if (hidden_or_backup_file(de->d_name))
                         continue;
 
                 f = strjoin(path, "/", de->d_name, NULL);
index 7b67831e540a93a9d9b5bdf3331c204f7d8fc2ed..c7ded451a2f409eb0f579818bbd7ef71ba920ae1 100644 (file)
@@ -481,7 +481,7 @@ static int show_passwords(void) {
                 if (de->d_type != DT_REG)
                         continue;
 
-                if (hidden_file(de->d_name))
+                if (hidden_or_backup_file(de->d_name))
                         continue;
 
                 if (!startswith(de->d_name, "ask."))