Add support for a more useful resize method, that allows setting of the number of rows, instead of requiring manual calculation. Signed-off-by: Robin H. Johnson diff -Nuar --exclude '*~' --exclude '*.txt' --exclude '*.html' --exclude '*.1' --exclude autom4te.cache --exclude bindings /dev/shm/portage/rrdtool-1.2.15/work/rrdtool-1.2.15/doc/rrdresize.pod /dev/shm/portage/rrdtool-1.2.15-r1/work/rrdtool-1.2.15/doc/rrdresize.pod --- rrdtool-1.2.15.orig/doc/rrdresize.pod 2006-07-14 05:11:26.000000000 -0700 +++ rrdtool-1.2.15/doc/rrdresize.pod 2006-07-21 01:56:56.333392940 -0700 @@ -6,6 +6,8 @@ B B I I BI<|>B I +B B I I [B<+>B<->B<=>]I + =head1 DESCRIPTION The B function is used to modify the number of rows in @@ -23,17 +25,20 @@ =item B -used if you want to add extra rows to an RRA. The extra rows will be inserted -as the rows that are oldest. +(old style) used if you want to add extra rows to an RRA. The extra rows will +be inserted as the rows that are oldest. =item B -used if you want to remove rows from an RRA. The rows that will be removed -are the oldest rows. +(old style) used if you want to remove rows from an RRA. The rows that will be +removed are the oldest rows. -=item I +=item [B<+>B<->B<=>]I -the number of rows you want to add or remove. +the number of rows you want to add or remove. when prefixed with any of B<+>, +B<-> or B<=>, the BI<|>B argument is not required, and instead +the prefix specifies to add (B<+>) I, remove (B<->) I, or set to +exactly (B<=>) I. =back diff -Nuar --exclude '*~' --exclude '*.txt' --exclude '*.html' --exclude '*.1' --exclude autom4te.cache --exclude bindings /dev/shm/portage/rrdtool-1.2.15/work/rrdtool-1.2.15/src/rrd_resize.c /dev/shm/portage/rrdtool-1.2.15-r1/work/rrdtool-1.2.15/src/rrd_resize.c --- rrdtool-1.2.15.orig/src/rrd_resize.c 2006-07-14 05:11:26.000000000 -0700 +++ rrdtool-1.2.15/src/rrd_resize.c 2006-07-21 03:09:45.656705610 -0700 @@ -19,7 +19,7 @@ unsigned long l,rra; long modify; unsigned long target_rra; - int grow=0,shrink=0; + int grow=0,shrink=0,setsize=0,newstyle=0; char *endptr; infilename=argv[1]; @@ -27,7 +27,7 @@ rrd_set_error("resize.rrd is a reserved name"); return(-1); } - if (argc!=5) { + if (argc!=5 && argc != 4) { rrd_set_error("wrong number of parameters"); return(-1); } @@ -36,20 +36,39 @@ if (!strcmp(argv[3],"GROW")) grow=1; else if (!strcmp(argv[3],"SHRINK")) shrink=1; + else if (argv[3][0] == '=' || argv[3][0] == '-' || argv[3][0] == '+') newstyle=3; else { rrd_set_error("I can only GROW or SHRINK"); return(-1); } - modify=strtol(argv[4],&endptr,0); - - if ((modify<1)) { - rrd_set_error("Please grow or shrink with at least 1 row"); - return(-1); - } - - if (shrink) modify = -modify; + // if the size starts with a character (=-+) then it's the new style + // instead. This is an extra mode so we can allow + // rrdtool resize FOO.rrd 5 GROW =5 + if(argc == 5 && (argv[4][0] == '=' || argv[4][0] == '-' || argv[4][0] == '+')) { + newstyle = 4; + } + if(newstyle > 0) { + setsize = argv[newstyle][0] == '=' ? 1 : 0; + /* If we see a + or a -, then the codepath is simple */ + grow = argv[newstyle][0] == '+' ? 1 : 0; + shrink = argv[newstyle][0] == '-' ? 1 : 0; + modify=strtol(argv[newstyle]+1,&endptr,0); + if(modify == 0) { + rrd_set_error("Refusing to add/delete/set with 0 rows"); + return(-1); + } + } else { + /* this is the old code branch */ + modify=strtol(argv[4],&endptr,0); + + if ((modify<1)) { + rrd_set_error("Please grow or shrink with at least 1 row"); + return(-1); + } + if (shrink) modify = -modify; + } if (rrd_open(infilename, &infile, &rrdold, RRD_READWRITE)==-1) { rrd_set_error("could not open RRD"); @@ -68,6 +87,17 @@ fclose(infile); return(-1); } + /* if we are in setsize mode, we need to work out what modify factor to use */ + if(setsize > 0) { + long oldsize = rrdold.rra_def[target_rra].row_cnt; + long newsize = modify; + // old=5, new=5 => modify = 0 + if(newsize == oldsize) { + rrd_set_error("RRA is already set to that size!"); + return(-1); + } + modify = newsize-oldsize; + } if (modify < 0) if ((long)rrdold.rra_def[target_rra].row_cnt <= -modify) { diff -Nuar --exclude '*~' --exclude '*.txt' --exclude '*.html' --exclude '*.1' --exclude autom4te.cache --exclude bindings /dev/shm/portage/rrdtool-1.2.15/work/rrdtool-1.2.15/src/rrd_tool.c /dev/shm/portage/rrdtool-1.2.15-r1/work/rrdtool-1.2.15/src/rrd_tool.c --- rrdtool-1.2.15.orig/src/rrd_tool.c 2006-07-14 05:11:26.000000000 -0700 +++ rrdtool-1.2.15/src/rrd_tool.c 2006-07-21 03:07:41.862541464 -0700 @@ -152,6 +152,7 @@ char help_resize[] = " * resize - alter the length of one of the RRAs in an RRD\n\n" + "\trrdtool resize filename rranum <+|-|=>rows\n"; "\trrdtool resize filename rranum GROW|SHRINK rows\n\n"; char help_xport[] =