[pacman-dev] [PATCH 2/6] repo-add: fail early if repo can not be created

Allan McRae allan at archlinux.org
Sun Mar 1 00:57:53 EST 2009


Dan McGee wrote:
> On Thu, Feb 26, 2009 at 2:06 PM, Xavier Chantry <shiningxc at gmail.com> wrote:
>   
>> Before this commit, the repo creation could fail after all packages have
>> been added to the database. Now this will be detected before adding
>> anything.
>>
>> Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
>> ---
>>  scripts/repo-add.sh.in |   18 +++++++++++++++---
>>  1 files changed, 15 insertions(+), 3 deletions(-)
>>
>> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
>> index b12188c..a967506 100644
>> --- a/scripts/repo-add.sh.in
>> +++ b/scripts/repo-add.sh.in
>> @@ -326,9 +326,21 @@ for arg in "$@"; do
>>                        fi
>>                        msg "$(gettext "Extracting database to a temporary location...")"
>>                        bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
>> -               elif [ "$cmd" == "repo-remove" ]; then
>> -                       error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE"
>> -                       exit 1
>> +               else
>> +                       case "$cmd" in
>> +                               repo-remove)
>> +                               error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE"
>> +                               exit 1
>> +                               ;;
>> +                               repo-add)
>> +                               # check if the file can be created (write permission, directory existence, etc)
>> +                               if ! touch "$REPO_DB_FILE"; then
>> +                                       error "$(gettext "Repository file '%s' could not be created.")" "$REPO_DB_FILE"
>> +                                       exit 1
>> +                               fi
>> +                               rm -f "$REPO_DB_FILE"
>>     
> This seems scary to me- is there any reason to blow it away like this?
> It also makes the repo-add process non-atomic- someone could access
> the database and fail while you are adding 10 packages, correct?
>
>   

I thought about this too but I was less scared when I noticed that this 
is only done when the db file is not found.  So you are only removing 
the db file created in the touch statement.






More information about the pacman-dev mailing list