[pacman-dev] [PATCH] makepkg: refactor checking for write permissions into a utility function

Eli Schwartz eschwartz at archlinux.org
Mon Oct 9 04:07:40 UTC 2017


On 10/08/2017 11:12 AM, Allan McRae wrote:
> On 08/10/17 17:05, Eli Schwartz wrote:
>> Additionally provide a separate error for the confusing if unlikely
>> event that the user tries to use an existing file as a package output
>> directory.
>>
>> This also means we now consistently try to create any nonexistent *DEST
>> directories as needed before aborting with E_FS_PERMISSIONS. Previously
>> only $BUILDDIR received that kindness.
>>
>> In the process, move the handling of $extra_environment[@] to where it
>> always belonged, above $BUILDDIR.
>>
> 
> This is a separate change and should be a separate patch.
> (Does it need to go even higher?)

In fact it does. Actually, I reworked the order altogether, since it
used to happen after BUILDDIR permissions was checked and before
anything else was either restored or checked, but really should happen
after all variables are restored and before checking anything.

>> Fixes FS#43537
>>
>> Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
>> ---
>>
>> Am I trying to do way, way too much here? mkdir will hopefully already
>> provide a somewhat useful error message in the case of an existing file,
>> as we don't quiet it.
> 
> (added after review below).
> The more I look at this, the more I think the patch is doing too much.
> Letting mkdir error and then giving the makepkg error afterward is
> probably enough here.  The extra may be error prone.
> 
> Although mkdir gives a really bad error when a file exists that
> conflicts with the path to be created...

That really bad error is the only real reason I bothered, and I'm
anyways okay with being convinced to drop that logic altogether.

But that mkdir error really is kind of gross.

>> And this will need to be rebased on top of escondida's error codes patch
>>
>>  scripts/libmakepkg/util/util.sh.in | 19 +++++++++++++++++++
>>  scripts/makepkg.sh.in              | 29 +++++++++++------------------
>>  2 files changed, 30 insertions(+), 18 deletions(-)
>>
>> diff --git a/scripts/libmakepkg/util/util.sh.in b/scripts/libmakepkg/util/util.sh.in
>> index d676249d..a8813338 100644
>> --- a/scripts/libmakepkg/util/util.sh.in
>> +++ b/scripts/libmakepkg/util/util.sh.in
>> @@ -83,3 +83,22 @@ cd_safe() {
>>  		exit 1
>>  	fi
>>  }
>> +
>> +# Try to create directory if one does not yet exist. Fails if the directory
>> +# exists but has no write permissions, or if there is an existing file with
>> +# the same name.
>> +ensure_dir() {
> 
> ensure_writable_dir()
> 
> Every time I read "ensure_dir", I had to think what was ensured!

That there *is* one :p though I guess I see your confusion. What I
regard as logical may not be readily apparent to the rest of the world,
so I guess I will humor the rest of the world and change this. :)

>> +	local parent=$1 dirname=$1
>> +
>> +	until [[ -e $parent ]]; do
>> +		parent="${parent%/*}"
>> +	done
>> +	if [[ -f $parent ]]; then
> 
> Is that a strong enough test? Isn't "! -d $parent" what is really
> wanted?  This might be too strong (symlink to directory would fail).

```
$ ln -s /tmp tmp
$ if [[ -f tmp ]]; then echo "symlink to dir is recognized as a file";
else echo "symlink to dir is not recognized as a file"; fi
symlink to dir is not recognized as a file
```

Seems to work fine???

-- 
Eli Schwartz

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.archlinux.org/pipermail/pacman-dev/attachments/20171009/9a0a1163/attachment.asc>


More information about the pacman-dev mailing list