From: Vaclav Malek Date: Fri, 25 Dec 2009 09:50:37 +0000 (+0100) Subject: src/common.[ch]: walk_directory: Add "include hidden" argument. X-Git-Tag: collectd-4.10.0~84 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f7a6c5e8ec8912d750b2c666a6bcb8581091f90f;p=collectd.git src/common.[ch]: walk_directory: Add "include hidden" argument. --- diff --git a/src/battery.c b/src/battery.c index b62ad81d..4178d8b5 100644 --- a/src/battery.c +++ b/src/battery.c @@ -514,7 +514,8 @@ static int battery_read (void) if (0 == access (battery_acpi_dir, R_OK)) walk_directory (battery_acpi_dir, battery_read_acpi, - /* user_data = */ NULL); + /* user_data = */ NULL, + /* include hidden */ 0); else { char errbuf[1024]; diff --git a/src/common.c b/src/common.c index c6a651dc..3695a9b7 100644 --- a/src/common.c +++ b/src/common.c @@ -1008,7 +1008,7 @@ int notification_init (notification_t *n, int severity, const char *message, } /* int notification_init */ int walk_directory (const char *dir, dirwalk_callback_f callback, - void *user_data) + void *user_data, int include_hidden) { struct dirent *ent; DIR *dh; @@ -1029,9 +1029,18 @@ int walk_directory (const char *dir, dirwalk_callback_f callback, while ((ent = readdir (dh)) != NULL) { int status; - - if (ent->d_name[0] == '.') - continue; + + if (include_hidden) + { + if ((strcmp (".", ent->d_name) == 0) + || (strcmp ("..", ent->d_name) == 0)) + continue; + } + else /* if (!include_hidden) */ + { + if (ent->d_name[0]=='.') + continue; + } status = (*callback) (dir, ent->d_name, user_data); if (status != 0) diff --git a/src/common.h b/src/common.h index 019e8b69..2d5c7945 100644 --- a/src/common.h +++ b/src/common.h @@ -280,7 +280,7 @@ int notification_init (notification_t *n, int severity, const char *message, typedef int (*dirwalk_callback_f)(const char *dirname, const char *filename, void *user_data); int walk_directory (const char *dir, dirwalk_callback_f callback, - void *user_data); + void *user_data, int hidden); int read_file_contents (const char *filename, char *buf, int bufsize); counter_t counter_diff (counter_t old_value, counter_t new_value); diff --git a/src/filecount.c b/src/filecount.c index 05bb4b37..6899d509 100644 --- a/src/filecount.c +++ b/src/filecount.c @@ -475,7 +475,8 @@ static int fc_read_dir_callback (const char *dirname, const char *filename, if (S_ISDIR (statbuf.st_mode) && (dir->options & FC_RECURSIVE)) { - status = walk_directory (abs_path, fc_read_dir_callback, dir); + status = walk_directory (abs_path, fc_read_dir_callback, dir, + /* include hidden = */ 0); return (status); } else if (!S_ISREG (statbuf.st_mode)) @@ -538,7 +539,8 @@ static int fc_read_dir (fc_directory_conf_t *dir) if (dir->mtime != 0) dir->now = time (NULL); - status = walk_directory (dir->path, fc_read_dir_callback, dir); + status = walk_directory (dir->path, fc_read_dir_callback, dir, + /* include hidden = */ 0); if (status != 0) { WARNING ("filecount plugin: walk_directory (%s) failed.", dir->path); diff --git a/src/thermal.c b/src/thermal.c index 2b708052..b9d07bf5 100644 --- a/src/thermal.c +++ b/src/thermal.c @@ -218,13 +218,13 @@ static int thermal_config (const char *key, const char *value) static int thermal_sysfs_read (void) { return walk_directory (dirname_sysfs, thermal_sysfs_device_read, - /* user_data = */ NULL); + /* user_data = */ NULL, /* include hidden */ 0); } static int thermal_procfs_read (void) { return walk_directory (dirname_procfs, thermal_procfs_device_read, - /* user_data = */ NULL); + /* user_data = */ NULL, /* include hidden */ 0); } static int thermal_init (void)