support recursion in dir_stat

This commit is contained in:
Doug MacEachern 2005-12-14 01:57:54 +00:00
parent 7eb8286364
commit 6f6f92fb42
1 changed files with 16 additions and 2 deletions

View File

@ -591,8 +591,11 @@ int sigar_link_attrs_get(sigar_t *sigar,
static int dir_stat_get(sigar_t *sigar, static int dir_stat_get(sigar_t *sigar,
const char *dir, const char *dir,
sigar_dir_stat_t *dirstats) sigar_dir_stat_t *dirstats,
int recurse)
{ {
int status;
int do_log = SIGAR_LOG_IS_WARN(sigar);
char name[SIGAR_PATH_MAX+1]; char name[SIGAR_PATH_MAX+1];
int len = strlen(dir); int len = strlen(dir);
int max = sizeof(name)-len-1; int max = sizeof(name)-len-1;
@ -644,6 +647,17 @@ static int dir_stat_get(sigar_t *sigar,
break; break;
case SIGAR_FILETYPE_DIR: case SIGAR_FILETYPE_DIR:
++dirstats->subdirs; ++dirstats->subdirs;
if (recurse) {
status =
dir_stat_get(sigar, name,
dirstats, recurse);
if ((status != SIGAR_OK) && do_log) {
sigar_log_printf(sigar, SIGAR_LOG_WARN,
"dir_stat: %s: %s\n",
name,
sigar_strerror(sigar, status));
}
}
break; break;
case SIGAR_FILETYPE_LNK: case SIGAR_FILETYPE_LNK:
++dirstats->symlinks; ++dirstats->symlinks;
@ -680,7 +694,7 @@ int sigar_dir_stat_get(sigar_t *sigar,
sigar_dir_stat_t *dirstats) sigar_dir_stat_t *dirstats)
{ {
SIGAR_ZERO(dirstats); SIGAR_ZERO(dirstats);
return dir_stat_get(sigar, dir, dirstats); return dir_stat_get(sigar, dir, dirstats, 0);
} }
#endif #endif