Skip to content
Snippets Groups Projects
Commit 407ef801 authored by Natanael Copa's avatar Natanael Copa
Browse files

db: check if target exist before renaming tempfile

do not overwrite target if we have --never-overwrite and target exists.

ref #197
parent 98de5353
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment