From: Florian Forster Date: Fri, 18 Jun 2010 18:46:27 +0000 (+0200) Subject: src/graph_{ident,instance}.[ch]: Implement getting the mtime from instances. X-Git-Tag: v4.0.0~245 X-Git-Url: https://git.octo.it/?p=collection4.git;a=commitdiff_plain;h=580d18370af2cf4feb48d46ff7e50c0231323349 src/graph_{ident,instance}.[ch]: Implement getting the mtime from instances. --- diff --git a/src/graph_ident.c b/src/graph_ident.c index b008a56..905e73d 100644 --- a/src/graph_ident.c +++ b/src/graph_ident.c @@ -1,13 +1,20 @@ #include +#include +#include #include #include #include #include /* PATH_MAX */ +#include +#include #include "graph_ident.h" #include "common.h" #include "filesystem.h" +#include +#include + /* * Data types */ @@ -451,5 +458,31 @@ char *ident_to_json (const graph_ident_t *ident) /* {{{ */ return (strdup (buffer)); } /* }}} char *ident_to_json */ +time_t ident_get_mtime (const graph_ident_t *ident) /* {{{ */ +{ + char *file; + struct stat statbuf; + int status; + + if (ident == NULL) + return (0); + + file = ident_to_file (ident); + if (file == NULL) + return (0); + + memset (&statbuf, 0, sizeof (statbuf)); + status = stat (file, &statbuf); + if (status != 0) + { + fprintf (stderr, "ident_get_mtime: stat'ing file \"%s\" failed: %s\n", + file, strerror (errno)); + return (0); + } + + free (file); + return (statbuf.st_mtime); +} /* }}} time_t ident_get_mtime */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/graph_ident.h b/src/graph_ident.h index 5107011..af86c9d 100644 --- a/src/graph_ident.h +++ b/src/graph_ident.h @@ -1,6 +1,8 @@ #ifndef GRAPH_IDENT_H #define GRAPH_IDENT_H 1 +#include + #define ANY_TOKEN "/any/" #define ALL_TOKEN "/all/" @@ -46,5 +48,7 @@ char *ident_to_string (const graph_ident_t *ident); char *ident_to_file (const graph_ident_t *ident); char *ident_to_json (const graph_ident_t *ident); +time_t ident_get_mtime (const graph_ident_t *ident); + /* vim: set sw=2 sts=2 et fdm=marker : */ #endif /* GRAPH_IDENT_H */ diff --git a/src/graph_instance.c b/src/graph_instance.c index 103be23..bad0bcd 100644 --- a/src/graph_instance.c +++ b/src/graph_instance.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "graph_instance.h" #include "graph_ident.h" @@ -472,4 +473,25 @@ int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */ return (0); } /* }}} int inst_describe */ +time_t inst_get_mtime (graph_instance_t *inst) /* {{{ */ +{ + size_t i; + time_t mtime; + + if (inst == NULL) + return (0); + + mtime = 0; + for (i = 0; i < inst->files_num; i++) + { + time_t tmp; + + tmp = ident_get_mtime (inst->files[i]); + if (mtime < tmp) + mtime = tmp; + } + + return (mtime); +} /* }}} time_t inst_get_mtime */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/graph_instance.h b/src/graph_instance.h index b90f984..72ab66a 100644 --- a/src/graph_instance.h +++ b/src/graph_instance.h @@ -9,6 +9,8 @@ typedef struct graph_instance_s graph_instance_t; typedef int (*inst_callback_t) (graph_instance_t *inst, void *user_data); +#include + #include "graph.h" #include "utils_array.h" @@ -46,5 +48,7 @@ graph_instance_t *inst_find_matching (graph_instance_t *inst, int inst_describe (graph_config_t *cfg, graph_instance_t *inst, char *buffer, size_t buffer_size); +time_t inst_get_mtime (graph_instance_t *inst); + #endif /* GRAPH_INSTANCE_H */ /* vim: set sw=2 sts=2 et fdm=marker : */