src/graph_{ident,instance}.[ch]: Implement getting the mtime from instances.
authorFlorian Forster <ff@octo.it>
Fri, 18 Jun 2010 18:46:27 +0000 (20:46 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 18 Jun 2010 18:46:27 +0000 (20:46 +0200)
src/graph_ident.c
src/graph_ident.h
src/graph_instance.c
src/graph_instance.h

index b008a56..905e73d 100644 (file)
@@ -1,13 +1,20 @@
 #include <stdlib.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
 #include <string.h>
 #include <strings.h>
 #include <errno.h>
 #include <limits.h> /* PATH_MAX */
 #include <string.h>
 #include <strings.h>
 #include <errno.h>
 #include <limits.h> /* PATH_MAX */
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "graph_ident.h"
 #include "common.h"
 #include "filesystem.h"
 
 
 #include "graph_ident.h"
 #include "common.h"
 #include "filesystem.h"
 
+#include <fcgiapp.h>
+#include <fcgi_stdio.h>
+
 /*
  * Data types
  */
 /*
  * Data types
  */
@@ -451,5 +458,31 @@ char *ident_to_json (const graph_ident_t *ident) /* {{{ */
   return (strdup (buffer));
 } /* }}} char *ident_to_json */
 
   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 : */
 
 /* vim: set sw=2 sts=2 et fdm=marker : */
 
index 5107011..af86c9d 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef GRAPH_IDENT_H
 #define GRAPH_IDENT_H 1
 
 #ifndef GRAPH_IDENT_H
 #define GRAPH_IDENT_H 1
 
+#include <time.h>
+
 #define ANY_TOKEN "/any/"
 #define ALL_TOKEN "/all/"
 
 #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);
 
 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 */
 /* vim: set sw=2 sts=2 et fdm=marker : */
 #endif /* GRAPH_IDENT_H */
index 103be23..bad0bcd 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <time.h>
 
 #include "graph_instance.h"
 #include "graph_ident.h"
 
 #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 */
 
   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 : */
 /* vim: set sw=2 sts=2 et fdm=marker : */
index b90f984..72ab66a 100644 (file)
@@ -9,6 +9,8 @@ typedef struct graph_instance_s graph_instance_t;
 
 typedef int (*inst_callback_t) (graph_instance_t *inst, void *user_data);
 
 
 typedef int (*inst_callback_t) (graph_instance_t *inst, void *user_data);
 
+#include <time.h>
+
 #include "graph.h"
 #include "utils_array.h"
 
 #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);
 
 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 : */
 #endif /* GRAPH_INSTANCE_H */
 /* vim: set sw=2 sts=2 et fdm=marker : */