std::string source_dir = "/etc/skel/apps_rw";
auto const source_dir_len = source_dir.length();
+ /* N.B. Removing temporary destination directory needs some explanation.
+ * We need to consider the case of partial copying of subsession data
+ * due to failure. In such a case at least some files will remain in the
+ * filesystem in the temporary directory (e.g., `.tmpnewsubsession1`).
+ * The default behaviour of `fs::copy` is to report an error when it
+ * encounters existing files/directories in the destination directory.
+ * This in turn would result in the inability to create a subsession
+ * with a previously chosen name. One might think the simplest remedy
+ * would be to add the `copy_options::overwrite_existing` flag to the
+ * `fs::copy` call below. Unfortunately, it acts weird when there are
+ * symlinks in the destination directory: instead of just replacing them,
+ * it fails with an `Invalid argument` exception. Refer to the
+ * `std::filesystem` documentation for details.
+ */
+ if (fs::exists(apps_rw_path))
+ fs::remove_all(apps_rw_path);
+
fs::copy
( fs::path{ source_dir }
, apps_rw_path