+ if (arg_template) {
+ r = btrfs_subvol_snapshot(arg_template, arg_directory, arg_read_only, true);
+ if (r == -EEXIST) {
+ if (!arg_quiet)
+ log_info("Directory %s already exists, not populating from template %s.", arg_directory, arg_template);
+ } else if (r < 0) {
+ log_error_errno(r, "Couldn't create snapshort %s from %s: %m", arg_directory, arg_template);
+ goto finish;
+ } else {
+ if (!arg_quiet)
+ log_info("Populated %s from template %s.", arg_directory, arg_template);
+ }
+
+ } else if (arg_ephemeral) {
+ char *np;
+
+ r = tempfn_random(arg_directory, &np);
+ if (r < 0) {
+ log_error_errno(r, "Failed to generate name for snapshot: %m");
+ goto finish;
+ }
+
+ r = btrfs_subvol_snapshot(arg_directory, np, arg_read_only, true);
+ if (r < 0) {
+ free(np);
+ log_error_errno(r, "Failed to create snapshot %s from %s: %m", np, arg_directory);
+ goto finish;
+ }
+
+ free(arg_directory);
+ arg_directory = np;
+
+ remove_subvol = true;
+ }
+