chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Fri, 16 Jun 2017 08:12:58 +0000 (10:12 +0200)
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/util.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);
 
 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;
 
                 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;
                 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;                                          \
                                 on_error;                               \
                         }                                               \
                         break;                                          \
-                } else if (hidden_file((de)->d_name))                   \
+                } else if (hidden_or_backup_file((de)->d_name))         \
                         continue;                                       \
                 else
 
                         continue;                                       \
                 else
 
index 6c3063298b21e688bf6ff9cd722a628a9178764b..9c15b91c312dd5c8a90127cd3a941182f5b0e3c7 100644 (file)
@@ -231,7 +231,7 @@ int close_all_fds(const int except[], unsigned n_except) {
         while ((de = readdir(d))) {
                 int fd = -1;
 
         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)
                         continue;
 
                 if (safe_atoi(de->d_name, &fd) < 0)
index c6d3442c9fde8ca72c3af4cb22bef0c0465b7b41..68097b46a6885d8497963841f14bd24daad2b2b0 100644 (file)
@@ -527,7 +527,7 @@ int on_ac_power(void) {
                 if (!de)
                         break;
 
                 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);
                         continue;
 
                 device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY);