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
| 1226 | * "line" is either used, or freed, so the caller does not need to free it |
| 1227 | * in any way. */ |
| 1228 | void rewriteConfigRewriteLine(struct rewriteConfigState *state, const char *option, sds line, int force) { |
| 1229 | sds o = sdsnew(option); |
| 1230 | list *l = dictFetchValue(state->option_to_line,o); |
| 1231 | |
| 1232 | rewriteConfigMarkAsProcessed(state,option); |
| 1233 | |
| 1234 | if (!l && !force && !state->force_all) { |
| 1235 | /* Option not used previously, and we are not forced to use it. */ |
| 1236 | sdsfree(line); |
| 1237 | sdsfree(o); |
| 1238 | return; |
| 1239 | } |
| 1240 | |
| 1241 | if (l) { |
| 1242 | listNode *ln = listFirst(l); |
| 1243 | int linenum = (long) ln->value; |
| 1244 | |
| 1245 | /* There are still lines in the old configuration file we can reuse |
| 1246 | * for this option. Replace the line with the new one. */ |
| 1247 | listDelNode(l,ln); |
| 1248 | if (listLength(l) == 0) dictDelete(state->option_to_line,o); |
| 1249 | sdsfree(state->lines[linenum]); |
| 1250 | state->lines[linenum] = line; |
| 1251 | } else { |
| 1252 | /* Append a new line. */ |
| 1253 | if (!state->has_tail) { |
| 1254 | rewriteConfigAppendLine(state, |
| 1255 | sdsnew(REDIS_CONFIG_REWRITE_SIGNATURE)); |
| 1256 | state->has_tail = 1; |
| 1257 | } |
| 1258 | rewriteConfigAppendLine(state,line); |
| 1259 | } |
| 1260 | sdsfree(o); |
| 1261 | } |
| 1262 | |
| 1263 | /* Write the long long 'bytes' value as a string in a way that is parsable |
| 1264 | * inside redis.conf. If possible uses the GB, MB, KB notation. */ |
no test coverage detected