won't save uid/gid of root (uid.gid == 0.0)
Opened this issue · 3 comments
Hi Danny,
thank you for this nice script. While working with it i got some errors like this:
$ .git/hooks/git-store-meta.pl --store -d -f mode,uid,gid
storing metadata to `/tmp/gittests/trepo/.git_store_meta' ...
fields: file, type, mode, uid, gid; directory: yes
$ git add .git_store_meta
$ git commit -m "bla"
[master 82f97ac] bla
1 file changed, 4 insertions(+), 4 deletions(-)
$ .git/hooks/git-store-meta.pl --apply -d
applying metadata from `/tmp/gittests/trepo/.git_store_meta' ...
fields: file, type, mode, uid, gid; directory: yes
Use of uninitialized value $data{"uid"} in string ne at .git/hooks/git-store-meta.pl line 522, <GIT_STORE_META_FILE> line 3.
Use of uninitialized value $data{"gid"} in string ne at .git/hooks/git-store-meta.pl line 558, <GIT_STORE_META_FILE> line 3.
Use of uninitialized value $data{"uid"} in string ne at .git/hooks/git-store-meta.pl line 522, <GIT_STORE_META_FILE> line 4.
After reading some perl basics, i found this:
On line 300:
push(@rec, $data{$fields[$i]} || "");
if $data{$fields[$i]} eq "0"
(uid or gid == 0) it will insert the empty string "".
Nothing shiny, but i created a patch which i will attach here...
All the best
I cannot reproduce this issue, and all the code lines you mentioned cannot be found in the latest version (1.2.4). It seems that the issue you mention is not in the latest version. Could you check what your version is and whether it still happens in the latest version?
I have version 1.2.4 - it will still happen with 1.2.5.
The problematic code line is still there (in version 1.2.5 on line 319):
push(@rec, $data{$fields[$i]} || "");
for uid/gid == 0 this would be:
push(@rec, "0" || "")
and since "0" is FALSE in perl, the empty string "" will be saved to .git_store_meta
. Please see example below...
You mentioned code lines which cannot be found in the latest version... if you are referencing the error messages like Use of uninitialized value $data{"uid"} in string ne at .git/hooks/git-store-meta.pl line 522, <GIT_STORE_META_FILE> line 3.
- these are errors directly from perl-interpreter and not from your script. You will get them if you try to apply the stored information.
It will happen if you have some files owned by root (which have uid == 0) and try to store the uid/gid. Example:
[root@arch playpen]$ ls -la
total 12
drwxr-xr-x 3 root root 4096 May 14 13:45 .
drwxr-xr-x 4 root root 4096 May 14 13:35 ..
-rw-r--r-- 1 git git 0 May 14 13:42 file_NOT_owned_by_root
-rw-r--r-- 1 root root 0 May 14 13:35 file_owned_by_root
drwxr-xr-x 7 root root 4096 May 14 13:45 .git
[root@arch playpen]$ git add file_owned_by_root file_NOT_owned_by_root
[root@arch playpen]$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file_NOT_owned_by_root
new file: file_owned_by_root
[root@arch playpen]$ .git/hooks/git-store-meta.pl --store -d -f mode,uid,gid
storing metadata to `/root/git-meta-test/playpen/.git_store_meta' ...
fields: file, type, mode, uid, gid; directory: yes
[root@arch playpen]$ cat .git_store_meta
# generated by git-store-meta 1.2.5
<file> <type> <mode> <uid> <gid>
file_NOT_owned_by_root f 0644 992 992
file_owned_by_root f 0644
[root@arch playpen]$
In the file with the stored meta-information .git_store_meta
you will see that:
- there is no uid/gid saved for the file_owned_by_root
file_owned_by_root f 0644
- but for the file_NOT_owned_by_root there is
file_NOT_owned_by_root f 0644 992 992
The correct line should look like file_owned_by_root f 0644 0 0
HTH
Thank you for clarification. Implemented in 1.2.6.