# [PATCH] Be more careful with objects directory permissions on clone

10 messages from 2008-05-04 to 2008-05-06. Participants: Mark Hills, Johannes Sixt, Junio C Hamano, Jakub Narebski.
Thread: https://gitlist.dev/t/13370

## Mark Hills, 2008-05-04 11:37

Subject: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <alpine.BSO.1.10.0805041234570.5819@zrgural.vwaro.pbz>
URL: https://gitlist.dev/e/alpine.BSO.1.10.0805041234570.5819%40zrgural.vwaro.pbz

```
Honour the setgid and umask when re-creating the objects directory
at the destination.

cpio in copy-pass mode aims to copy file permissions which causes this
problem and cannot be disabled. Be explicit by copying the directory
structure first, honouring the permissions at the destination, then copy
the files with their existing read-only permissions.

Signed-off-by: Mark Hills <mark@pogo.org.uk>
---
  git-clone.sh |    5 ++++-
  1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index 8c7fc7f..53c7e06 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -334,7 +334,10 @@ yes)
  			fi
  		fi &&
  		cd "$repo" &&
-		find objects -depth -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
+		# Create dirs using umask and permissions and destination
+		find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
+		# Copy 0444 permissions on files
+		find objects -type f -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
  			exit 1
  	fi
  	git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
-- 
1.5.5.1.126.g48d0c

```

## Johannes Sixt, 2008-05-05 09:01

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <481ECCF0.6080308@viscovery.net>
URL: https://gitlist.dev/e/481ECCF0.6080308%40viscovery.net
In-Reply-To: <alpine.BSO.1.10.0805041234570.5819@zrgural.vwaro.pbz>

```
Mark Hills schrieb:
> Honour the setgid and umask when re-creating the objects directory
> at the destination.
> 
> cpio in copy-pass mode aims to copy file permissions which causes this
> problem and cannot be disabled. Be explicit by copying the directory
> structure first, honouring the permissions at the destination, then copy
> the files with their existing read-only permissions.
...
>          cd "$repo" &&
> -        find objects -depth -print | cpio $cpio_quiet_flag -pumd$l
> "$GIT_DIR/" || \
> +        # Create dirs using umask and permissions and destination
> +        find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
> +        # Copy 0444 permissions on files
> +        find objects -type f -print | cpio $cpio_quiet_flag -pumd$l
> "$GIT_DIR/" || \

Wouldn't that be better:

	find objects ! -type d -print | cpio ...

?

-- Hannes

```

## Mark Hills, 2008-05-05 09:56

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <alpine.BSO.1.10.0805051047260.7723@zrgural.vwaro.pbz>
URL: https://gitlist.dev/e/alpine.BSO.1.10.0805051047260.7723%40zrgural.vwaro.pbz
In-Reply-To: <481ECCF0.6080308@viscovery.net>

```
On Mon, 5 May 2008, Johannes Sixt wrote:

> Mark Hills schrieb:
>> Honour the setgid and umask when re-creating the objects directory
>> at the destination.
>>
>> cpio in copy-pass mode aims to copy file permissions which causes this
>> problem and cannot be disabled. Be explicit by copying the directory
>> structure first, honouring the permissions at the destination, then copy
>> the files with their existing read-only permissions.
> ...
>>          cd "$repo" &&
>> -        find objects -depth -print | cpio $cpio_quiet_flag -pumd$l
>> "$GIT_DIR/" || \
>> +        # Create dirs using umask and permissions and destination
>> +        find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
>> +        # Copy 0444 permissions on files
>> +        find objects -type f -print | cpio $cpio_quiet_flag -pumd$l
>> "$GIT_DIR/" || \
>
> Wouldn't that be better:
>
> 	find objects ! -type d -print | cpio ...
>
> ?

This was my first suggestion, unfortunately it shows up broken behaviour 
in all but the latest version of cpio. It creates 0700 directory 
permissions which is even worse.

I didn't find the later versions of cpio to be widespread, so I wrote the 
patch to work in all cases.

See the thread 'git-clone file permissions and cpio'.

Mark

```

## Johannes Sixt, 2008-05-05 10:07

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <481EDC4B.2010105@viscovery.net>
URL: https://gitlist.dev/e/481EDC4B.2010105%40viscovery.net
In-Reply-To: <alpine.BSO.1.10.0805051047260.7723@zrgural.vwaro.pbz>

```
Mark Hills schrieb:
> On Mon, 5 May 2008, Johannes Sixt wrote:
> 
>> Mark Hills schrieb:
>>>          cd "$repo" &&
>>> -        find objects -depth -print | cpio $cpio_quiet_flag -pumd$l
>>> "$GIT_DIR/" || \
>>> +        # Create dirs using umask and permissions and destination
>>> +        find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir
>>> -p) &&
>>> +        # Copy 0444 permissions on files
>>> +        find objects -type f -print | cpio $cpio_quiet_flag -pumd$l
>>> "$GIT_DIR/" || \
>>
>> Wouldn't that be better:
>>
>>     find objects ! -type d -print | cpio ...
>>
>> ?
> 
> This was my first suggestion, unfortunately it shows up broken behaviour
> in all but the latest version of cpio. It creates 0700 directory
> permissions which is even worse.

Sorry, I should have mentioned that I meant to keep the 'find | xargs
mkdir' and replace only the second 'find | cpio'.

-- Hannes

```

## Mark Hills, 2008-05-05 10:25

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <alpine.BSO.1.10.0805051121090.32248@zrgural.vwaro.pbz>
URL: https://gitlist.dev/e/alpine.BSO.1.10.0805051121090.32248%40zrgural.vwaro.pbz
In-Reply-To: <481EDC4B.2010105@viscovery.net>

```
On Mon, 5 May 2008, Johannes Sixt wrote:

> Mark Hills schrieb:
>> On Mon, 5 May 2008, Johannes Sixt wrote:
>>
>>> Mark Hills schrieb:
>>>>          cd "$repo" &&
>>>> -        find objects -depth -print | cpio $cpio_quiet_flag -pumd$l
>>>> "$GIT_DIR/" || \
>>>> +        # Create dirs using umask and permissions and destination
>>>> +        find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir
>>>> -p) &&
>>>> +        # Copy 0444 permissions on files
>>>> +        find objects -type f -print | cpio $cpio_quiet_flag -pumd$l
>>>> "$GIT_DIR/" || \
>>>
>>> Wouldn't that be better:
>>>
>>>     find objects ! -type d -print | cpio ...
>>>
>>> ?
>>
>> This was my first suggestion, unfortunately it shows up broken behaviour
>> in all but the latest version of cpio. It creates 0700 directory
>> permissions which is even worse.
>
> Sorry, I should have mentioned that I meant to keep the 'find | xargs
> mkdir' and replace only the second 'find | cpio'.

Ah, I see.

I tend to think that an inclusive match has less scope for future bad 
behaviour than an exclusive match. Have I missed the possiblity that there 
may be content in the objects directory which is not a directory or file?

Mark

```

## Johannes Sixt, 2008-05-05 10:42

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <481EE478.9000704@viscovery.net>
URL: https://gitlist.dev/e/481EE478.9000704%40viscovery.net
In-Reply-To: <alpine.BSO.1.10.0805051121090.32248@zrgural.vwaro.pbz>

```
Mark Hills schrieb:
> On Mon, 5 May 2008, Johannes Sixt wrote:
> 
>> Mark Hills schrieb:
>>> On Mon, 5 May 2008, Johannes Sixt wrote:
>>>
>>>> Mark Hills schrieb:
>>>>>          cd "$repo" &&
>>>>> -        find objects -depth -print | cpio $cpio_quiet_flag -pumd$l
>>>>> "$GIT_DIR/" || \
>>>>> +        # Create dirs using umask and permissions and destination
>>>>> +        find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir
>>>>> -p) &&
>>>>> +        # Copy 0444 permissions on files
>>>>> +        find objects -type f -print | cpio $cpio_quiet_flag -pumd$l
>>>>> "$GIT_DIR/" || \
>>>>
>>>> Wouldn't that be better:
>>>>
>>>>     find objects ! -type d -print | cpio ...
>>>>
>>>> ?
>>>
>>> This was my first suggestion, unfortunately it shows up broken behaviour
>>> in all but the latest version of cpio. It creates 0700 directory
>>> permissions which is even worse.
>>
>> Sorry, I should have mentioned that I meant to keep the 'find | xargs
>> mkdir' and replace only the second 'find | cpio'.
> 
> Ah, I see.
> 
> I tend to think that an inclusive match has less scope for future bad
> behaviour than an exclusive match. Have I missed the possiblity that
> there may be content in the objects directory which is not a directory
> or file?

Theoretically, you could have symbolic links to loose objects or packs.

Generally, you shouldn't change the behavior of a program more than necessary.

-- Hannes

```

## Mark Hills, 2008-05-05 16:46

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <alpine.BSO.1.10.0805051742020.10940@zrgural.vwaro.pbz>
URL: https://gitlist.dev/e/alpine.BSO.1.10.0805051742020.10940%40zrgural.vwaro.pbz
In-Reply-To: <481EE478.9000704@viscovery.net>

```
On Mon, 5 May 2008, Johannes Sixt wrote:

> Mark Hills schrieb:

>> I tend to think that an inclusive match has less scope for future bad 
>> behaviour than an exclusive match. Have I missed the possiblity that 
>> there may be content in the objects directory which is not a directory 
>> or file?
>
> Theoretically, you could have symbolic links to loose objects or packs.
>
> Generally, you shouldn't change the behavior of a program more than 
> necessary.

Okay, here's a revised patch (I made a note about the cpio bug in the 
commit message too).

Thanks,

Mark



Be more careful with objects directory permissions on clone

Honour the setgid and umask when re-creating the objects directory
at the destination.

cpio in copy-pass mode aims to copy file permissions which causes this
problem and cannot be disabled. Be explicit by copying the directory
structure first, honouring the permissions at the destination, then copy
the files with 0444 permissions. This also avoids bugs in some versions
of cpio.

Signed-off-by: Mark Hills <mark@pogo.org.uk>
---
  git-clone.sh |    5 ++++-
  1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index 8c7fc7f..9d88d1c 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -334,7 +334,10 @@ yes)
  			fi
  		fi &&
  		cd "$repo" &&
-		find objects -depth -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
+		# Create dirs using umask and permissions and destination
+		find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
+		# Copy existing 0444 permissions on content
+		find objects ! -type d -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
  			exit 1
  	fi
  	git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
-- 
1.5.5.1.126.geeac

```

## Junio C Hamano, 2008-05-06 06:53

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <7vprrzhqk3.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vprrzhqk3.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <alpine.BSO.1.10.0805051742020.10940@zrgural.vwaro.pbz>

```
Mark Hills <mark@pogo.org.uk> writes:

> diff --git a/git-clone.sh b/git-clone.sh
> index 8c7fc7f..9d88d1c 100755
> --- a/git-clone.sh
> +++ b/git-clone.sh
> @@ -334,7 +334,10 @@ yes)
>  			fi
>  		fi &&
>  		cd "$repo" &&
> -		find objects -depth -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
> +		# Create dirs using umask and permissions and destination
> +		find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
> +		# Copy existing 0444 permissions on content
> +		find objects ! -type d -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
>  			exit 1

Looks much better.  Thanks.

```

## Jakub Narebski, 2008-05-06 07:25

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <fvp14f$8v0$1@ger.gmane.org>
URL: https://gitlist.dev/e/fvp14f%248v0%241%40ger.gmane.org
In-Reply-To: <alpine.BSO.1.10.0805051742020.10940@zrgural.vwaro.pbz>

```
Mark Hills wrote:

> -               find objects -depth -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
> +               # Create dirs using umask and permissions and destination
> +               find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
> +               # Copy existing 0444 permissions on content
> +               find objects ! -type d -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \

By the way, it is important that previous version had -depth, and
proposed one doesn't? Was it about creating directories before files?

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

```

## Johannes Sixt, 2008-05-06 08:08

Subject: Re: [PATCH] Be more careful with objects directory permissions on clone
Message-ID: <4820121A.9090606@viscovery.net>
URL: https://gitlist.dev/e/4820121A.9090606%40viscovery.net
In-Reply-To: <fvp14f$8v0$1@ger.gmane.org>

```
Jakub Narebski schrieb:
> Mark Hills wrote:
> 
>> -               find objects -depth -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
>> +               # Create dirs using umask and permissions and destination
>> +               find objects -type d -print | (cd "$GIT_DIR" && xargs mkdir -p) &&
>> +               # Copy existing 0444 permissions on content
>> +               find objects ! -type d -print | cpio $cpio_quiet_flag -pumd$l "$GIT_DIR/" || \
> 
> By the way, it is important that previous version had -depth, and
> proposed one doesn't? Was it about creating directories before files?

-depth means that directory names are listed *after* their content.
Consequently, it was about setting modification times and permissions on
directories *after* all of their content is created at the destination.

The intent of the new version is to not copy permissions of directories;
and since the modification times don't matter, the absence of -depth is ok.

-- Hannes

```
