MCPcopy Create free account
hub / github.com/ElementsProject/lightning / promote_missing_files

Function promote_missing_files

lightningd/options.c:1228–1291  ·  view source on GitHub ↗

We are in ld->config_netdir when this is run! */

Source from the content-addressed store, hash-verified

1226
1227/* We are in ld->config_netdir when this is run! */
1228static void promote_missing_files(struct lightningd *ld)
1229{
1230#ifdef COMPAT_V073
1231 DIR *d_from;
1232 struct dirent *d;
1233 struct stat st;
1234
1235 /* If hsm_secret already exists, we assume we're ugpraded */
1236 if (stat("hsm_secret", &st) == 0)
1237 return;
1238
1239 if (errno != ENOENT)
1240 err(1, "Looking for hsm_secret in lightning dir");
1241
1242 /* If hsm doesn't exist in basedir, we've nothing to upgrade. */
1243 if (stat(path_join(tmpctx, ld->config_basedir, "hsm_secret"), &st) != 0)
1244 return;
1245
1246 d_from = opendir(ld->config_basedir);
1247 if (!d_from)
1248 err(1, "Opening %s", ld->config_basedir);
1249
1250 while ((d = readdir(d_from)) != NULL) {
1251 const char *fullname;
1252
1253 /* Ignore this directory and upper one, and leave
1254 * config and pid files */
1255 if (streq(d->d_name, ".")
1256 || streq(d->d_name, "..")
1257 || streq(d->d_name, "config")
1258 || strends(d->d_name, ".pid"))
1259 continue;
1260
1261 fullname = path_join(tmpctx, ld->config_basedir, d->d_name);
1262
1263 /* Simply remove rpc file: if they use --rpc-file to place it
1264 * here explicitly it will get recreated, but moving it would
1265 * be confusing as it would be unused. */
1266 if (streq(d->d_name, "lightning-rpc")) {
1267 if (unlink(fullname) != 0)
1268 log_unusual(ld->log, "Could not unlink %s: %s",
1269 fullname, strerror(errno));
1270 continue;
1271 }
1272
1273 /* Ignore any directories. */
1274 if (lstat(fullname, &st) != 0)
1275 errx(1, "Could not stat %s", fullname);
1276 if ((st.st_mode & S_IFMT) == S_IFDIR)
1277 continue;
1278
1279 /* Check we don't overwrite something in this dir! */
1280 if (lstat(d->d_name, &st) != -1)
1281 errx(1, "Refusing to overwrite %s into %s/",
1282 fullname, ld->config_netdir);
1283 log_unusual(ld->log, "Moving %s into %s/",
1284 d->d_name, ld->config_netdir);
1285 if (rename(fullname, d->d_name) != 0)

Callers 1

handle_early_optsFunction · 0.85

Calls 5

errFunction · 0.85
path_joinFunction · 0.85
strendsFunction · 0.85
errxFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected