--- /dev/null
+/* MIT License
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#include "dir_backend_regular_dir.hpp"
+
+namespace fs = std::filesystem;
+using namespace std::string_literals;
+
+void DirBackendRegularDir::RemoveSubsession (const fs::path& subsession_path)
+{
+ /* We are going to rename the subsession dir before deleting it,
+ * because that makes the removal appear atomic. The temporary
+ * 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. */
+ auto tmp_subsession_path = subsession_path;
+ tmp_subsession_path.replace_filename(".tmpremove"s + subsession_path.filename().native());
+
+ /* Ensure that any possible residue from previously
+ * failed subsession deletion is cleaned up. */
+ if (fs::exists(tmp_subsession_path))
+ fs::remove_all(tmp_subsession_path);
+
+ /* Renaming also removes whatever was under the tmp path, which
+ * could be residue left over from an earlier failed removal attempt. */
+ fs::rename(subsession_path, tmp_subsession_path);
+ fs::remove_all(tmp_subsession_path);
+}
#include "os_ops.hpp"
#include "fs_helpers.hpp"
+#include "dir_backend_regular_dir.hpp"
+namespace SubsessionDirBackend = DirBackendRegularDir;
+
namespace fs = std::filesystem;
using namespace std::string_literals;
throw std::system_error(ENOENT, std::generic_category(),
"Subsession directory does not exist");
- /* We are going to rename the subsession dir before deleting it,
- * because that makes the removal appear atomic. The temporary
- * 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. */
- 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. */
- if (fs::exists(tmp_subsession_path))
- fs::remove_all(tmp_subsession_path);
-
- /* Perform the rename-and-delete. */
- fs::rename(subsession_path, tmp_subsession_path);
- fs::remove_all(tmp_subsession_path);
+ SubsessionDirBackend::RemoveSubsession(subsession_path);
}
catch (std::system_error const &ex) {
LOGE("Logic exception %s\nwhile removing user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());