Decouple set_ownership from "dir class" logic 68/318568/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 14 Jan 2025 15:23:31 +0000 (16:23 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 22 Jan 2025 11:49:44 +0000 (12:49 +0100)
Putting business logic outside it turns set_ownership
into strictly a filesystem helper.

Change-Id: Ibdfdc4cdaed9c183b542846e0320627aab046847

src/service/src/fs_helpers.cpp

index 4b0b9333644be8bdd65ddfc588b428bf73f7e635..7780d8550fcceee7c5459351dc8839ef13fe6b74 100644 (file)
@@ -101,7 +101,7 @@ static inline bool should_copy_perms_from_skel(Directory_Class type) {
 }
 
 static void set_ownership_and_perms(std::string_view src_path, std::string_view dest_path, const mode_t mode,
-       const int session_uid, const int gid, Directory_Class type)
+       const int session_uid, const int gid, bool copy_perms_from_skel)
 {
        struct stat info;
        int ret = lstat(src_path.data(), &info);
@@ -117,7 +117,7 @@ static void set_ownership_and_perms(std::string_view src_path, std::string_view
        /* Symlinks don't have permissions, and we
         * don't want to change the underlying file's. */
        if (!S_ISLNK(info.st_mode))
-               change_permissions(dest_path, should_copy_perms_from_skel(type) ? info.st_mode : mode);
+               change_permissions(dest_path, copy_perms_from_skel ? info.st_mode : mode);
 }
 
 static std::string get_smack_label(std::string_view src_path, smack_label_type type)
@@ -365,7 +365,7 @@ void add_user_subsession(const int session_uid, const std::string_view subsessio
                                break;
                        }
 
-                       set_ownership_and_perms(s_path, d_path, mode, session_uid, gid, dir_type);
+                       set_ownership_and_perms(s_path, d_path, mode, session_uid, gid, should_copy_perms_from_skel(dir_type));
                        copy_smack_attributes(s_path, d_path);
                }