Use fs::path in `remove_user_subsession` 76/318776/3
authorMichal Bloch <m.bloch@samsung.com>
Wed, 22 Jan 2025 11:30:13 +0000 (12:30 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Tue, 4 Feb 2025 11:51:10 +0000 (12:51 +0100)
Instead of processing raw strings manually.

Change-Id: I188432ac5e0cb24ecac24c8aedff2fb6134b0c96

src/service/src/fs_helpers.cpp

index 8486be4a890e03035c7e8c220bacbeea2b541509..f06cdf6f6010730723cae2a08fabbd2e0f2f073e 100644 (file)
@@ -392,10 +392,8 @@ void add_user_subsession(const int session_uid, const std::string_view subsessio
 void remove_user_subsession(const int session_uid, const std::string_view subsession_id)
 {
        try {
-               std::string main_dir = get_main_dir_by_user_id(session_uid);
+               const auto subsession_path = fs::path(get_main_dir_by_user_id(session_uid)) / subsession_id;
 
-               std::string subsession_dir = main_dir + "/" + subsession_id.data();
-               const fs::path subsession_path { std::move(subsession_dir) };
                if (!fs::exists(subsession_path))
                        throw std::system_error(ENOENT, std::generic_category(),
                                "Subsession directory does not exist");
@@ -405,8 +403,8 @@ void remove_user_subsession(const int session_uid, const std::string_view subses
                 * name is different than the one for adding a subsession to avoid
                 * a possible collision with `add_user_subsession` which also uses
                 * a temporary dir. */
-               std::string tmp_subsession_dir = std::move(main_dir) + "/.tmpremove" + subsession_id.data();
-               const fs::path tmp_subsession_path { std::move(tmp_subsession_dir) };
+               const auto tmp_subsession_path = fs::path(subsession_path)
+                       .replace_filename(".tmpremove"s + subsession_path.filename().native());
 
                /* Ensure that any possible residue from previously
                 * failed subsession deletion is cleaned up. */