Skip to contentSkip to conversation

gc changes permissions of files

DISCUSSION Allan Wind 2 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#1 lore raw

Hi,

Quoted 7 lines · Allan Wind

Is anyone looking into fixing gc so it does not change permission on files? I would think it should consider current permissions of files before umask.

I believe Nigel reported this issue with:
http://thread.gmane.org/gmane.comp.version-control.git/79213/focus=79237
and still seeing issues with 1.5.5.4.

It would have been nice to briefly illustrate the problem again.

In the message you referred to, it seems to suggest that git-gc (in fact, git pack-refs) set the permissions wrong in a shared repository.

However, I cannot reproduce at all:

-- snip --
[PATCH] Verify that permissions for packed-refs are set correctly

---
 t/t1301-shared-repo.sh |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
t/t1301-shared-repo.sh +18 -0
index 5e4252a..c4d3239 100755
@@ -43,6 +43,24 @@ test_expect_success 'update-server-info honors core.sharedRepository' '
 	esac
 '
 
+test_expect_success 'pack-refs honors core.sharedRepository' '
+
+	(umask 0217 &&
+	 : > a2 &&
+	 git pack-refs) &&
+	actual="$(ls -l .git/packed-refs)" &&
+	case "$actual" in
+	-r--r--r--*)
+		: happy
+		;;
+	*)
+		echo Oops, .git/packed-refs is not 0444
+		false
+		;;
+	esac
+
+'
+
 for u in	0660:rw-rw---- \
 		0640:rw-r----- \
 		0600:rw------- \

-- snap --

This succeeds.

Indeed, it should succeed, since the relevant part in lockfile.c was fixed in version v1.4.0~4.

However, I suspect from the original message that the reflogs did not have the correct permissions. But again, a simple test succeeds:

-- snip --
[PATCH] Add a test for logrefs in bare repositories

---
 t/t1301-shared-repo.sh |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
t/t1301-shared-repo.sh +33 -0
index 5e4252a..8530a56 100755
@@ -24,6 +24,39 @@ test_expect_success 'shared=all' '
 	test 2 = $(git config core.sharedrepository)
 '
 
+test_expect_success 'reflogs honor core.sharedRepository' '
+	git config core.logAllRefUpdates true &&
+	echo 2 > a1 &&
+	git add a1 &&
+	test_tick &&
+	git commit -m a1 &&
+	actual="$(ls -l .git/logs/refs/heads/master)" &&
+	case "$actual" in
+	-rw-rw-r--*)
+		: happy
+		;;
+	*)
+		echo Oops, .git/logs/refs/heads/master is not 0664
+		false
+		;;
+	esac &&
+	(mkdir bare.git &&
+	 cd bare.git &&
+	 git --bare init --shared &&
+	 git config core.logAllRefUpdates true) &&
+	git push bare.git master:refs/heads/new &&
+	actual="$(ls -l bare.git/logs/refs/heads/new)" &&
+	case "$actual" in
+	-rw-rw-*)
+		: happy
+		;;
+	*)
+		echo Oops, bare.git/logs/refs/heads/new is not 0664
+		false
+		;;
+	esac
+'
+
 test_expect_success 'update-server-info honors core.sharedRepository' '
 	: > a1 &&
 	git add a1 &&
Signature · 12 lines
1.5.5.1.780.g346de
-- snap --

So now I got curious and tested it with v1.5.4.4, and indeed, it failed.

If you are curious who/what fixed it, go ahead, bisect it.

I wrote all this down so that the next time, you could verify yourself if 
the bug was fixed or not, instead of having to ask here.

Ciao,
Dscho
author
#2 lore raw
Quoted 11 lines · Johannes Schindelin
Quoted 7 lines · Allan Wind

Is anyone looking into fixing gc so it does not change permission on files? I would think it should consider current permissions of files before umask.

I believe Nigel reported this issue with:
http://thread.gmane.org/gmane.comp.version-control.git/79213/focus=79237
and still seeing issues with 1.5.5.4.

It would have been nice to briefly illustrate the problem again.

Of course.

# umask
umask 0022
# find . -ls > /tmp/before
# git gc
Counting objects: 1435, done.
Compressing objects: 100% (747/747), done.
Writing objects: 100% (1435/1435), done.
Total 1435 (delta 690), reused 1422 (delta 682)
# find . -ls > /tmp/after

On these files group write is revoked when running gc (g-w). /tmp/before:

16420 662752 -rw-rw---- 1 root users 677990209 Jun 15 01:49 ./objects/pack/pack-f962a3321392570
5b321ad2ba6ccb0037114f92d.pack
16432 36 -rw-rw---- 1 root users 35504 Jun 15 01:49 ./objects/pack/pack-f962a33213925705b3
21ad2ba6ccb0037114f92d.idx
...

 18258    4 drwxrwx---   2 allan    users        4096 Jun 15 01:47 ./logs/refs/heads
 16481    8 -rw-rw----   1 root     users        6100 Jun 15 01:47 ./logs/refs/heads/master

and /tmp/after:

16401 662752 -r--r--r-- 1 root root 677990209 Jun 15 01:59 ./objects/pack/pack-f962a3321392570
5b321ad2ba6ccb0037114f92d.pack
16404 36 -r--r--r-- 1 root root 35504 Jun 15 01:59 ./objects/pack/pack-f962a33213925705b3
21ad2ba6ccb0037114f92d.idx
...

 16402    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/refs/heads/master
 16403    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/HEAD

and these on these other read permissions (o+r) is added. /tmp/before:

 16394    4 -rw-rw----   1 root     users          54 Jun 15 01:49 ./objects/info/packs
 16481    8 -rw-rw----   1 root     users        6100 Jun 15 01:47 ./logs/refs/heads/master
 16475    8 -rw-rw----   1 root     users        6100 Jun 15 01:47 ./logs/HEAD
 16485   16 -rw-rw----   1 root     users       14773 Jun 15 01:47 ./packed-refs

and /tmp/after:

 16393    4 -rw-rw-r--   1 root     root           54 Jun 15 01:59 ./objects/info/packs
 16402    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/refs/heads/master
 16403    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/HEAD
 16386   16 -rw-rw-r--   1 root     root        14773 Jun 15 01:57 ./packed-refs

I seem to recall that push to the repository also introduces files without group write permission. Unfortunately it looks something broke when I ran gc. Any help in getting my repository back up would be appreciated:

allan@vent:~/var/git/www2$ git clone ssh://pawan.localnet./var/lib/git/www.git
Initialized empty Git repository in /home/allan/var/git/www2/www/.git/
fatal: git-upload-pack: cannot find object 56032c4f35fd39fe4151fca2d010d299a8901101:
fatal: The remote end hung up unexpectedly
fetch-pack from 'ssh://pawan.localnet./var/lib/git/www.git' failed.

/Allan

author
#3 lore raw
Quoted 9 lines · Allan Wind

I seem to recall that push to the repository also introduces files without group write permission. Unfortunately it looks something broke when I ran gc. Any help in getting my repository back up would be appreciated:

allan@vent:~/var/git/www2$ git clone ssh://pawan.localnet./var/lib/git/www.git
Initialized empty Git repository in /home/allan/var/git/www2/www/.git/
fatal: git-upload-pack: cannot find object 56032c4f35fd39fe4151fca2d010d299a8901101:
fatal: The remote end hung up unexpectedly
fetch-pack from 'ssh://pawan.localnet./var/lib/git/www.git' failed.
# git fsck
dangling commit 2b0da4aabfba6c61baf9f351b2dfbd5a88a8a999

Re-running this returns the same dangling commit, so fsck does not seem to fix anything.

/Allan

author
#4 lore raw
Quoted 11 lines · Allan Wind
Quoted 9 lines · Allan Wind

I seem to recall that push to the repository also introduces files without group write permission. Unfortunately it looks something broke when I ran gc. Any help in getting my repository back up would be appreciated:

allan@vent:~/var/git/www2$ git clone ssh://pawan.localnet./var/lib/git/www.git
Initialized empty Git repository in /home/allan/var/git/www2/www/.git/
fatal: git-upload-pack: cannot find object 56032c4f35fd39fe4151fca2d010d299a8901101:
fatal: The remote end hung up unexpectedly
fetch-pack from 'ssh://pawan.localnet./var/lib/git/www.git' failed.
Quoted 5 lines
# git fsck
dangling commit 2b0da4aabfba6c61baf9f351b2dfbd5a88a8a999

Re-running this returns the same dangling commit, so fsck does not seem to fix anything.

Looking at the log I see that 56032c4f35fd39fe4151fca2d010d299a8901101 is HEAD on orgin, and 2b0da4aabfba6c61baf9f351b2dfbd5a88a8a999 is what I tried to commit when I got the initially error. I will catch the howto when git.or.cz
is back online. If anyone wants some data before I try to fix my repository please let me know soon.

/Allan

author
#5 lore raw
In reply to Allan Wind
Quoted 54 lines · Allan Wind
Quoted 11 lines · Johannes Schindelin
Quoted 7 lines · Allan Wind

Is anyone looking into fixing gc so it does not change permission on files? I would think it should consider current permissions of files before umask.

I believe Nigel reported this issue with:
http://thread.gmane.org/gmane.comp.version-control.git/79213/focus=79237
and still seeing issues with 1.5.5.4.

It would have been nice to briefly illustrate the problem again.

Of course.

# umask
umask 0022
# find . -ls > /tmp/before
# git gc
Counting objects: 1435, done.
Compressing objects: 100% (747/747), done.
Writing objects: 100% (1435/1435), done.
Total 1435 (delta 690), reused 1422 (delta 682)
# find . -ls > /tmp/after

On these files group write is revoked when running gc (g-w). /tmp/before:

16420 662752 -rw-rw---- 1 root users 677990209 Jun 15 01:49 ./objects/pack/pack-f962a3321392570
5b321ad2ba6ccb0037114f92d.pack
16432 36 -rw-rw---- 1 root users 35504 Jun 15 01:49 ./objects/pack/pack-f962a33213925705b3
21ad2ba6ccb0037114f92d.idx
...

 18258    4 drwxrwx---   2 allan    users        4096 Jun 15 01:47 ./logs/refs/heads
 16481    8 -rw-rw----   1 root     users        6100 Jun 15 01:47 ./logs/refs/heads/master

and /tmp/after:

16401 662752 -r--r--r-- 1 root root 677990209 Jun 15 01:59 ./objects/pack/pack-f962a3321392570
5b321ad2ba6ccb0037114f92d.pack
16404 36 -r--r--r-- 1 root root 35504 Jun 15 01:59 ./objects/pack/pack-f962a33213925705b3
21ad2ba6ccb0037114f92d.idx
...

 16402    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/refs/heads/master
 16403    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/HEAD

and these on these other read permissions (o+r) is added. /tmp/before:

 16394    4 -rw-rw----   1 root     users          54 Jun 15 01:49 ./objects/info/packs
 16481    8 -rw-rw----   1 root     users        6100 Jun 15 01:47 ./logs/refs/heads/master
 16475    8 -rw-rw----   1 root     users        6100 Jun 15 01:47 ./logs/HEAD
 16485   16 -rw-rw----   1 root     users       14773 Jun 15 01:47 ./packed-refs

and /tmp/after:

Quoted 8 lines
 16393    4 -rw-rw-r--   1 root     root           54 Jun 15 01:59 ./objects/info/packs
 16402    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/refs/heads/master
 16403    8 -rw-r--r--   1 root     root         6100 Jun 15 01:57 ./logs/HEAD
 16386   16 -rw-rw-r--   1 root     root        14773 Jun 15 01:57 ./packed-refs

I seem to recall that push to the repository also introduces files without group write permission. Unfortunately it looks something broke when I ran gc. Any help in getting my repository back up would be appreciated:

This above was without core.sharedrepository set. Setting core.sharedrepository to true, and repeating the experiment I get the following changes (starting out with files being 660):

245865    0 -rw-rw-r--   1 allan    users           0 Jun 15 18:25 ./info/refs
245883    4 -rw-rw-r--   1 allan    users          54 Jun 15 18:25 ./objects/info/packs
245882 662464 -r--r--r--   1 allan    users    677691559 Jun 15 18:25 ./objects/pack/pack-7d2c630cc2bf7621e14487fdde5907765ebb5d4d.pack
245886   36 -r--r--r--   1 allan    users       36128 Jun 15 18:25 ./objects/pack/pack-7d2c630cc2bf7621e14487fdde5907765ebb5d4d.idx
245885    4 -rw-rw-r--   1 allan    users          26 Jun 15 18:24 ./packed-refs

write permission is removed from the two pack files, and read permissions is granted for the other files which did not have them before.

/Allan