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.tokkee.org/?a=commitdiff_plain;h=4ca85630de6db829e6e9b43bb8e07f79c7ca223a;p=rrdtool-all.git 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@2028 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/doc/rrdcreate.pod b/program/doc/rrdcreate.pod index abb42fc9..d4390b90 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 75c3722f..4e98d53c 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 @@ -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/program/src/rrd_tool.c b/program/src/rrd_tool.c index 03b018ae..2e59b8e0 100644 --- a/program/src/rrd_tool.c +++ b/program/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");