From: oetiker Date: Mon, 8 Mar 2010 17:10:02 +0000 (+0000) Subject: added --no-overwrite option to rrdtool create. It prevents rrdtool from clobbering... X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=commitdiff_plain;h=8f9c2c2b3c3f8a65e24dd9d8d612eafe48ccfb2e 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/program@2028 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/doc/rrdcreate.pod b/doc/rrdcreate.pod index a4d9651..b321de6 100644 --- a/doc/rrdcreate.pod +++ b/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/src/rrd_create.c b/src/rrd_create.c index 9a971cc..a1b4e5a 100644 --- a/src/rrd_create.c +++ b/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/src/rrd_open.c b/src/rrd_open.c index 7d6ddc9..0939e7c 100644 --- a/src/rrd_open.c +++ b/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/src/rrd_tool.c b/src/rrd_tool.c index 5a56a96..1b32396 100644 --- a/src/rrd_tool.c +++ b/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/src/rrd_tool.h b/src/rrd_tool.h index ef32758..86c4aa8 100644 --- a/src/rrd_tool.h +++ b/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);