Skip to content

Commit 92e80b4

Browse files
committed
cli: fix copy to missing startup-config file
Fixes #981 Signed-off-by: Joachim Wiberg <[email protected]>
1 parent e6a04fb commit 92e80b4

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/bin/copy.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,18 @@ static int copy(const char *src, const char *dst, const char *remote_user)
286286
} else {
287287
/* Direct copy for other datastores (no callbacks needed) */
288288
rc = sr_copy_config(sess, NULL, srcds->datastore, timeout * 1000);
289-
if (rc)
289+
if (rc) {
290290
emsg(sess, ERRMSG "unable to copy configuration, err %d: %s\n", rc, sr_strerror(rc));
291-
else
292-
set_owner(dstds->path, user);
291+
} else {
292+
/* Export datastore to backing file if it has one */
293+
if (dstds->path) {
294+
rc = systemf("sysrepocfg -d %s -X%s -f json", dstds->sysrepocfg, dstds->path);
295+
if (rc)
296+
fprintf(stderr, ERRMSG "failed saving %s to %s\n", srcds->name, dstds->path);
297+
else
298+
set_owner(dstds->path, user);
299+
}
300+
}
293301
}
294302
}
295303
rc = sr_disconnect(conn);
@@ -397,7 +405,15 @@ static int copy(const char *src, const char *dst, const char *remote_user)
397405
} else {
398406
rc = systemf("sysrepocfg -d %s -I%s -f json", dstds->sysrepocfg, fn);
399407
if (rc)
400-
fprintf(stderr, ERRMSG "failed loading %s from %s", dst, src);
408+
fprintf(stderr, ERRMSG "failed loading %s from %s\n", dst, src);
409+
else if (dstds->path) {
410+
rc = systemf("sysrepocfg -d %s -X%s -f json", dstds->sysrepocfg, dstds->path);
411+
if (rc)
412+
fprintf(stderr, ERRMSG "failed saving %s\n", dstds->path);
413+
else
414+
set_owner(dstds->path, user);
415+
}
416+
401417
}
402418
}
403419
} else {

0 commit comments

Comments
 (0)