Cleanup failed fixed-size add attempts properly 64/321964/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 1 Apr 2025 12:09:46 +0000 (14:09 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 2 Apr 2025 17:51:35 +0000 (19:51 +0200)
Change-Id: I624fd935c4f1a795503004befc54dd99a15aa06f
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/service/src/dir_backend_fixed_size.cpp

index 40fe4c9192c69a8be5d90105567aa75f982ab8d5..c79c7b70c89ef21f43d0e59c7e10a290e69eb135 100644 (file)
@@ -145,24 +145,26 @@ fs::path DirBackendAddFixedSize::AddSubsessionPrepare (const fs::path& subsessio
        return tmp_subsession_path;
 }
 
+static void umount_and_remove (const fs::path& path) try {
+       do_umount(path);
+       fs::remove(path);
+} catch (const std::exception& ex) {
+       LOGE("umount & rmdir (%s) failed!", path.c_str());
+       throw;
+}
+
 void DirBackendAddFixedSize::AddSubsessionCleanupFailure (const fs::path& tmpdir_path, const fs::path& subsession_path) const
 {
        auto tmp_image_path = DirBackendFixedSize::GetImagePathFromSubsessionPath(subsession_path);
        tmp_image_path.replace_filename(TMP_NEW_PREFIX + tmp_image_path.filename().native());
 
-       fs::remove(tmpdir_path);
        fs::remove(tmp_image_path);
+       umount_and_remove(tmpdir_path);
 }
 
 void DirBackendAddFixedSize::AddSubsessionFinalize (const fs::path& tmpdir_path, const fs::path& subsession_path, int uid, int gid) const
 {
-       try {
-               do_umount(tmpdir_path);
-               fs::remove(tmpdir_path);
-       } catch (const std::exception& ex) {
-               LOGE("umount & rmdir (%s) failed!", tmpdir_path.c_str());
-               throw;
-       }
+       umount_and_remove(tmpdir_path);
 
        const auto image_path = DirBackendFixedSize::GetImagePathFromSubsessionPath(subsession_path);
        auto temp_image_path = image_path;