From b1bcf246743386bba9704d5619c5c197b5544057 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/branches/1.3/program@2028 a5681a0c-68f1-0310-ab6d-d61299d08faa --- doc/rrdcreate.pod | 5 +++++ src/rrd_create.c | 13 ++++++++++++- src/rrd_tool.c | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/rrdcreate.pod b/doc/rrdcreate.pod index abb42fc..d4390b9 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 75c3722..4e98d53 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 @@ -42,6 +43,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; @@ -57,7 +59,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; @@ -93,6 +95,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); @@ -687,6 +693,11 @@ int rrd_create_fn( flags |= O_BINARY; #endif + /* with O_CREAT (above) causes open to fail with EEXIST when if exists */ + if (opt_no_overwrite) { + flags |= O_EXCL; + } + if ((rrd_file = open(file_name, flags, 0666)) < 0) { rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno)); rrd_free2(rrd); diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 03b018a..2e59b8e 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -66,6 +66,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\n"); -- 2.30.2