mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
lightningd: automatically move files for existing deployments.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
aab83e729b
commit
d512bcb85f
2
Makefile
2
Makefile
@ -47,7 +47,7 @@ endif
|
||||
|
||||
ifeq ($(COMPAT),1)
|
||||
# We support compatibility with pre-0.6.
|
||||
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1 -DCOMPAT_V062=1 -DCOMPAT_V070=1
|
||||
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1 -DCOMPAT_V062=1 -DCOMPAT_V070=1 -DCOMPAT_V073=1
|
||||
endif
|
||||
|
||||
# Timeout shortly before the 600 second travis silence timeout
|
||||
|
@ -848,6 +848,60 @@ static void register_opts(struct lightningd *ld)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We are in ld->config_netdir when this is run! */
|
||||
static void promote_missing_files(struct lightningd *ld)
|
||||
{
|
||||
#ifdef COMPAT_V073
|
||||
DIR *d_from;
|
||||
struct dirent *d;
|
||||
struct stat st;
|
||||
|
||||
/* If hsm_secret already exists, we assume we're ugpraded */
|
||||
if (stat("hsm_secret", &st) == 0)
|
||||
return;
|
||||
|
||||
if (errno != ENOENT)
|
||||
err(1, "Looking for hsm_secret in lightning dir");
|
||||
|
||||
/* If hsm doesn't exist in basedir, we've nothing to upgrade. */
|
||||
if (stat(path_join(tmpctx, ld->config_basedir, "hsm_secret"), &st) != 0)
|
||||
return;
|
||||
|
||||
d_from = opendir(ld->config_basedir);
|
||||
if (!d_from)
|
||||
err(1, "Opening %s", ld->config_basedir);
|
||||
|
||||
while ((d = readdir(d_from)) != NULL) {
|
||||
const char *fullname;
|
||||
|
||||
/* Ignore this directory and upper one, and leave config */
|
||||
if (streq(d->d_name, ".")
|
||||
|| streq(d->d_name, "..")
|
||||
|| streq(d->d_name, "config"))
|
||||
continue;
|
||||
|
||||
fullname = path_join(tmpctx, ld->config_basedir, d->d_name);
|
||||
|
||||
/* Ignore any directories. */
|
||||
if (lstat(fullname, &st) != 0)
|
||||
errx(1, "Could not stat %s", fullname);
|
||||
if ((st.st_mode & S_IFMT) == S_IFDIR)
|
||||
continue;
|
||||
|
||||
/* Check we don't overwrite something in this dir! */
|
||||
if (lstat(d->d_name, &st) != -1)
|
||||
errx(1, "Refusing to overwrite %s into %s/",
|
||||
fullname, ld->config_netdir);
|
||||
log_unusual(ld->log, "Moving %s into %s/",
|
||||
d->d_name, ld->config_netdir);
|
||||
if (rename(fullname, d->d_name) != 0)
|
||||
err(1, "Could not move %s/%s to %s",
|
||||
ld->config_basedir, d->d_name, ld->config_netdir);
|
||||
}
|
||||
closedir(d_from);
|
||||
#endif /* COMPAT_V073 */
|
||||
}
|
||||
|
||||
/* Names stolen from https://github.com/ternus/nsaproductgenerator/blob/master/nsa.js */
|
||||
static const char *codename_adjective[]
|
||||
= { "LOUD", "RED", "BLUE", "GREEN", "YELLOW", "IRATE", "ANGRY", "PEEVED",
|
||||
@ -948,6 +1002,9 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[])
|
||||
ld->config_netdir, strerror(errno));
|
||||
}
|
||||
|
||||
/*~ We move files from old locations on first upgrade. */
|
||||
promote_missing_files(ld);
|
||||
|
||||
/*~ The ccan/opt code requires registration then parsing; we
|
||||
* mimic this API here, even though they're on separate lines.*/
|
||||
register_opts(ld);
|
||||
|
Loading…
Reference in New Issue
Block a user