[pacman-dev] [PATCH 1/6] repo-add: print warning if same version already exists
Simple fix for FS#13414
Signed-off-by: Xavier Chantry
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
Refactor the main loop, which was difficult to read.
Use case instead of if when appropriate.
Signed-off-by: Xavier Chantry
* report when a package entry to be removed is not found
* backup and restore eventual "deltas" files
* slight optimization when looking for an entry : only look at the entries
starting with $pkgname
Signed-off-by: Xavier Chantry
The current implementation has several problems :
Wrong database format
All the info is taken from the filename, which is a bit ugly
It looks for .delta files in the current directory when adding a package,
which is not very flexible
Signed-off-by: Xavier Chantry
Use the correct database format
Use xdelta3 to get the source and destination files from the delta itself
Allow delta files to be added with repo-add just like package files. delta
files can also be removed with repo-remove. This is simply done by looking
for a .delta extension in the arguments, and calling the appropriate
db_write_delta or db_remove_delta functions.
Example usage:
repo-add repo/test.db.tar.gz repo/libx11-1.1.99.2-2-x86_64.pkg.tar.gz
repo-add repo/test.db.tar.gz repo/libx11-1.1.5-2_to_1.1.99.2-2-x86_64.delta
repo-remove repo/test.db.tar.gz libx11-1.1.5-2_to_1.1.99.2-2-x86_64.delta
Signed-off-by: Xavier Chantry
On Thu, Feb 26, 2009 at 2:06 PM, Xavier Chantry
Refactor the main loop, which was difficult to read.
Use case instead of if when appropriate.
Signed-off-by: Xavier Chantry
The idea is good, but make sure comments from previous patches make it into this reorg (formatting and the rm -f thing). -Dan
Xavier Chantry 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
Patch looks good. Minor stylistic comments below
--- 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)
indent the lines within this block some more:
+ error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE" + exit 1 + ;; + repo-add)
and these
+ # 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" + ;; + esac fi else if [ "$cmd" == "repo-add" ]; then
Allan
On Fri, Feb 27, 2009 at 1:56 AM, Allan McRae
Xavier Chantry 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
Patch looks good. Minor stylistic comments below
--- 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)
indent the lines within this block some more:
+ error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE" + exit 1 + ;; + repo-add)
and these
+ # 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" + ;; + esac fi else if [ "$cmd" == "repo-add" ]; then
Yeah, I don't know why vim indent the blocks inside case like that... It is quite annoying. Is there a way to write case blocks more vim friendly, or some options / tricks I could use?
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
--- 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
On Thu, Feb 26, 2009 at 2:06 PM, Xavier Chantry
+ ;; + esac fi else if [ "$cmd" == "repo-add" ]; then -- 1.6.1.3
Also agree with Allan's style comments, and I am not sure why vim indents like it does. -Dan
Dan McGee wrote:
On Thu, Feb 26, 2009 at 2:06 PM, Xavier Chantry
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
--- 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.
On Sun, Mar 1, 2009 at 6:57 AM, Allan McRae
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.
Indeed. However when the db file is found, I didn't even check it was also writable in that case. And we have a race condition huge like a mountain here. There can be several minutes spent between this write/creation check is made, and the actual write of the new database. It would probably be a good idea to write a lock file for each database ($REPO.lck) so that there is never more than one repo-add instance running for one given db. For these reasons, I will just drop that patch for now, for rewriting it later.
On Sat, Feb 28, 2009 at 10:37 PM, Dan McGee
Also agree with Allan's style comments, and I am not sure why vim indents like it does.
I guess vim considers case blocks just like any other blocks : " Add a 'shiftwidth' after if, while, else, case, until, for, function() So it indents all the lines inside a case/esac at the same level. And it apparently does not consider case statements as blocks. That indentation is made even worse by the fact that I didn't even put a newline between the different case statements, so it is even harder to see them. Anyway my updated patches have manual indentation now.
On Thu, Feb 26, 2009 at 2:06 PM, Xavier Chantry
Simple fix for FS#13414
Signed-off-by: Xavier Chantry
Signed-off-by: Dan McGee
participants (4)
-
Allan McRae
-
Dan McGee
-
Xavier
-
Xavier Chantry