Rewrite the specified configuration option with the new "line". * It progressively uses lines of the file that were already used for the same * configuration option in the old version of the file, removing that line from * the map of options -> line numbers. * * If there are lines associated with a given configuration option and * "force" is non-zero, the line is appended to the configuratio
| 1477 | * "line" is either used, or freed, so the caller does not need to free it |
| 1478 | * in any way. */ |
| 1479 | void rewriteConfigRewriteLine(struct rewriteConfigState *state, const char *option, sds line, int force) { |
| 1480 | sds o = sdsnew(option); |
| 1481 | list *l = (list*)dictFetchValue(state->option_to_line,o); |
| 1482 | |
| 1483 | rewriteConfigMarkAsProcessed(state,option); |
| 1484 | |
| 1485 | if (!l && !force && !state->force_all) { |
| 1486 | /* Option not used previously, and we are not forced to use it. */ |
| 1487 | sdsfree(line); |
| 1488 | sdsfree(o); |
| 1489 | return; |
| 1490 | } |
| 1491 | |
| 1492 | if (l) { |
| 1493 | listNode *ln = listFirst(l); |
| 1494 | int linenum = (long) ln->value; |
| 1495 | |
| 1496 | /* There are still lines in the old configuration file we can reuse |
| 1497 | * for this option. Replace the line with the new one. */ |
| 1498 | listDelNode(l,ln); |
| 1499 | if (listLength(l) == 0) dictDelete(state->option_to_line,o); |
| 1500 | sdsfree(state->lines[linenum]); |
| 1501 | state->lines[linenum] = line; |
| 1502 | } else { |
| 1503 | /* Append a new line. */ |
| 1504 | if (!state->has_tail) { |
| 1505 | rewriteConfigAppendLine(state, |
| 1506 | sdsnew(REDIS_CONFIG_REWRITE_SIGNATURE)); |
| 1507 | state->has_tail = 1; |
| 1508 | } |
| 1509 | rewriteConfigAppendLine(state,line); |
| 1510 | } |
| 1511 | sdsfree(o); |
| 1512 | } |
| 1513 | |
| 1514 | /* Write the long long 'bytes' value as a string in a way that is parsable |
| 1515 | * inside keydb.conf. If possible uses the GB, MB, KB notation. */ |
no test coverage detected