From 6b3375c53f5e3f7bc88b16d667d7b773b7f4445f Mon Sep 17 00:00:00 2001 From: oetiker Date: Mon, 8 Mar 2010 17:10:02 +0000 Subject: [PATCH] added --no-overwrite option to rrdtool create. It prevents rrdtool from clobbering existing rrd files. -- Chris - LINX git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@2028 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/doc/rrdcreate.pod | 5 +++++ program/src/rrd_create.c | 12 +++++++++++- program/src/rrd_open.c | 3 +++ program/src/rrd_tool.c | 1 + program/src/rrd_tool.h | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/program/doc/rrdcreate.pod b/program/doc/rrdcreate.pod index a4d9651a..b321de63 100644 --- a/program/doc/rrdcreate.pod +++ b/program/doc/rrdcreate.pod @@ -7,6 +7,7 @@ rrdcreate - Set up a new Round Robin Database B B I S<[B<--start>|B<-b> I]> S<[B<--step>|B<-s> I]> +S<[B<--no-overwrite>]> S<[BIB<:>IB<:>I]> S<[BIB<:>I]> @@ -36,6 +37,10 @@ I documentation for other ways to specify time. Specifies the base interval in seconds with which data will be fed into the B. +=head2 B<--no-overwrite> + +Do not clobber an existing file of the same name. + =head2 BIB<:>IB<:>I A single B can accept input from several data sources (B), diff --git a/program/src/rrd_create.c b/program/src/rrd_create.c index 9a971cc4..a1b4e5a4 100644 --- a/program/src/rrd_create.c +++ b/program/src/rrd_create.c @@ -13,6 +13,7 @@ #include "rrd_hw.h" #include "rrd_is_thread_safe.h" +static int opt_no_overwrite = 0; #ifdef WIN32 # include @@ -39,6 +40,7 @@ int rrd_create( struct option long_options[] = { {"start", required_argument, 0, 'b'}, {"step", required_argument, 0, 's'}, + {"no-overwrite", no_argument, 0, 'O'}, {0, 0, 0, 0} }; int option_index = 0; @@ -54,7 +56,7 @@ int rrd_create( opterr = 0; /* initialize getopt */ while (1) { - opt = getopt_long(argc, argv, "b:s:", long_options, &option_index); + opt = getopt_long(argc, argv, "Ob:s:", long_options, &option_index); if (opt == EOF) break; @@ -90,6 +92,10 @@ int rrd_create( pdp_step = long_tmp; break; + case 'O': + opt_no_overwrite = 1; + break; + case '?': if (optopt != 0) rrd_set_error("unknown option '%c'", optopt); @@ -679,6 +685,10 @@ int rrd_create_fn( rrd_t rrd_dn; unsigned rrd_flags = RRD_READWRITE | RRD_CREAT; + if (opt_no_overwrite) { + rrd_flags |= RRD_EXCL ; + } + unkn_cnt = 0; for (i = 0; i < rrd->stat_head->rra_cnt; i++) unkn_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[i].row_cnt; diff --git a/program/src/rrd_open.c b/program/src/rrd_open.c index 7d6ddc9b..0939e7c2 100644 --- a/program/src/rrd_open.c +++ b/program/src/rrd_open.c @@ -172,6 +172,9 @@ rrd_file_t *rrd_open( if (rdwr & RRD_CREAT) { flags |= (O_CREAT | O_TRUNC); } + if (rdwr & RRD_EXCL) { + flags |= O_EXCL; + } } if (rdwr & RRD_READAHEAD) { #ifdef MAP_POPULATE diff --git a/program/src/rrd_tool.c b/program/src/rrd_tool.c index 5a56a96d..1b32396b 100644 --- a/program/src/rrd_tool.c +++ b/program/src/rrd_tool.c @@ -65,6 +65,7 @@ void PrintUsage( N_("* create - create a new RRD\n\n" "\trrdtool create filename [--start|-b start time]\n" "\t\t[--step|-s step]\n" + "\t\t[--no-overwrite|-O]\n" "\t\t[DS:ds-name:DST:dst arguments]\n" "\t\t[RRA:CF:cf arguments]\n"); diff --git a/program/src/rrd_tool.h b/program/src/rrd_tool.h index ef327586..86c4aa8c 100644 --- a/program/src/rrd_tool.h +++ b/program/src/rrd_tool.h @@ -107,6 +107,7 @@ int rrd_fetch_fn_libdbi(const char *filename, enum cf_en cf_idx, #define RRD_CREAT (1<<2) #define RRD_READAHEAD (1<<3) #define RRD_COPY (1<<4) +#define RRD_EXCL (1<<5) enum cf_en cf_conv( const char *string); -- 2.30.2