]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Allow RRA resize to absolutely specified row_count
authorPeter Stamfest <peter@stamfest.at>
Thu, 27 Feb 2014 10:01:33 +0000 (11:01 +0100)
committerPeter Stamfest <peter@stamfest.at>
Thu, 27 Feb 2014 10:01:33 +0000 (11:01 +0100)
src/rrd_modify.c

index f56899ed613d263b58058998f060abf7cb69b3cd..992ad27b89c0a18a25cfd462dbdf66b4a366fe77 100644 (file)
@@ -464,16 +464,35 @@ static int rrd_modify_r(const char *infilename,
         */
 
        if (rra_op) {
-           switch (rra_op->op) {
+           char op = rra_op->op;
+           unsigned int row_count = rra_op->row_count;
+           
+           // rewrite '=' ops into '-' or '+' for better code-reuse...
+           if (op == '=') {
+               if (row_count < in.rra_def[i].row_cnt) {
+                   row_count = in.rra_def[i].row_cnt - row_count;
+                   op = '-';
+               } else if (row_count > in.rra_def[i].row_cnt) {
+                   row_count = row_count - in.rra_def[i].row_cnt;
+                   op = '+';
+               } else {
+                   // equal - special case: nothing to do...
+               }
+           }
+
+           switch (op) {
+           case '=':
+               // no op
+               break;
            case '-':
                // remove rows: just skip the first couple of rows!
-               ii = rra_op->row_count;
+               ii = row_count;
                break;
            case '+':
                // add rows: insert the requested number of rows!
                // currently, just add the all as NaN values...
 
-               for ( ; oi < rra_op->row_count ; oi++) {
+               for ( ; oi < row_count ; oi++) {
                    for (j = 0 ; j < out.stat_head->ds_cnt ; j++) {
                        out.rrd_value[total_cnt_out + 
                                      oi * out.stat_head->ds_cnt +