summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2009-11-24 08:18:58 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2009-11-24 08:25:24 +0000
commit407ef801d9b10b535e13fa26f12396b0476dd825 (patch)
tree367253cfc11f4d20693e6b1eab80f76368384fff /src/database.c
parent98de5353550b1750591d4469429563f5537519ed (diff)
downloadapk-tools-407ef801d9b10b535e13fa26f12396b0476dd825.tar.gz
apk-tools-407ef801d9b10b535e13fa26f12396b0476dd825.tar.bz2
apk-tools-407ef801d9b10b535e13fa26f12396b0476dd825.tar.xz
apk-tools-407ef801d9b10b535e13fa26f12396b0476dd825.zip
db: check if target exist before renaming tempfile
do not overwrite target if we have --never-overwrite and target exists. ref #197
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/database.c b/src/database.c
index 5b1d6bb..f06eba4 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1890,9 +1890,16 @@ static void apk_db_migrate_files(struct apk_database *db,
apk_checksum_compare(&file->csum, &fi.csum) == 0))
unlinkat(db->root_fd, tmpname, 0);
} else {
- /* Overwrite the old file */
- renameat(db->root_fd, tmpname,
- db->root_fd, name);
+ /* check if want keep existing files */
+ if ((apk_flags & APK_NEVER_OVERWRITE) &&
+ (faccessat(db->root_fd, name, F_OK,
+ AT_SYMLINK_NOFOLLOW) == 0)) {
+ unlinkat(db->root_fd, tmpname, 0);
+ } else {
+ /* Overwrite the old file */
+ renameat(db->root_fd, tmpname,
+ db->root_fd, name);
+ }
}
/* Claim ownership of the file in db */