danny0838 / git-store-meta

Simple file metadata storing and applying for git.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

user or group root (uid/gid 0) not restored

jnagler opened this issue · comments

Hi Danny,

I have config files for /etc/http in my repository which I maintain with scripts to belong to root and I use facl to give access within the repo. This way my installer can copy with --preserve=ownership, skips the facl and everything is as intended in /etc/http. I now added your script to keep this as part of the repository instead of maintaining the access rights with scripts. It correctly stores root as owner/group in .git_store_meta (using 1.3.0, I assume this is only working since #13), but restoring does not work. It gives a warning and ignores to set root as owner/group.

warn: root is not a valid user.
warn: root is not a valid user group.

I checked your perl code and found

set_user: {
    if ($fields_used{'user'} && $data{'user'} ne "") {
        my $uid = (getpwnam($data{'user'}))[2];
        my $gid = (lstat($file))[5];
        print "`$File' set user to '$data{'user'}'\n" if $argv{'verbose'};
        if ($uid) {
            ... do set it
        }
        else {
            warn "warn: $data{'user'} is not a valid user.\n";
        }
        ...
set_group: {
    if ($fields_used{'group'} && $data{'group'} ne "") {
        my $uid = (lstat($file))[4];
        my $gid = (getgrnam($data{'group'}))[2];
        print "`$File' set group to '$data{'group'}'\n" if $argv{'verbose'};
        if ($gid) {
            ... do set it
        }
        else {
            warn "warn: $data{'user'} is not a valid user group.\n";
        }

As uid/gid of root are 0 the warn is given instead of effectively setting user and/or group. A little research (my perl days are long ago) revealed https://www.perlmonks.org/bare/?node_id=157745 so I think you should not check by if ($uid) / (gid) but use if (defined $uid) / (defined $gid). Or did you by intention not allow uid/gid 0?

Thanks,
Jürgen

I face more or less the same problem...

No, it's not intended. Thank you for reporting.