In the current remote/s3 implementation, the default {u,g}id for files
and directories is 0. Additionally, the --force-{u,g}id flag only
affects file ownership, leaving directories unchanged.

This patch fixes the behavior by explicitly setting permissions for the
root inode:

- If --force-{u,g}id is not specified, it now defaults to the current
  user's {u,g}id.
- If --force-{u,g}id is specified, it correctly updates the ownership
  for all files and directories.

Signed-off-by: Yifan Zhao <[email protected]>
---
 lib/remotes/s3.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/remotes/s3.c b/lib/remotes/s3.c
index 3426585..8351674 100644
--- a/lib/remotes/s3.c
+++ b/lib/remotes/s3.c
@@ -1050,8 +1050,8 @@ int s3erofs_build_trees(struct erofs_importer *im, struct 
erofs_s3 *s3,
        bool dumb;
        int ret;
 
-       st.st_uid = root->i_uid;
-       st.st_gid = root->i_gid;
+       root->i_uid = st.st_uid = im->params->fixed_uid == -1 ? getuid() : 
im->params->fixed_uid;
+       root->i_gid = st.st_gid = im->params->fixed_gid == -1 ? getgid() : 
im->params->fixed_gid;
 
        ret = s3erofs_curl_easy_init(s3);
        if (ret) {
-- 
2.47.3


Reply via email to