summaryrefslogtreecommitdiff
path: root/lib/libalpm/add.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-04-08 18:38:54 -0500
committerDan McGee <dan@archlinux.org>2008-04-08 18:55:22 -0500
commit4b7f7e2a59457aa881ae883b6d102f9fc62e2ed8 (patch)
treeec123b965246d538ef8c9e6ce37f2baee81df298 /lib/libalpm/add.c
parentbec2ba5b4005053ce8f7048fa825ed58e3adfdc2 (diff)
downloadpacman-4b7f7e2a59457aa881ae883b6d102f9fc62e2ed8.tar.xz
Correctly use the fd returned my mkstemp()
There were a few issues with this code: 1. We already had an open fd to a file, but never used it to our benefit. Use the libarchive convienence method to write the current file contents straight to a file descriptor. 2. The real problem cropped up on Windows where the locking semantics caused the old way of extraction to fail because we had an open file descriptor. By using the file descriptor and closing it ASAP, we prevent these failures. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/add.c')
-rw-r--r--lib/libalpm/add.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 42015224..0a1a1924 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -446,7 +446,7 @@ static int extract_single_file(struct archive *archive,
}
if(needbackup) {
- char *tempfile = NULL;
+ char *tempfile;
char *hash_local = NULL, *hash_pkg = NULL;
int fd;
@@ -454,9 +454,8 @@ static int extract_single_file(struct archive *archive,
tempfile = strdup("/tmp/alpm_XXXXXX");
fd = mkstemp(tempfile);
- archive_entry_set_pathname(entry, tempfile);
-
- int ret = archive_read_extract(archive, entry, archive_flags);
+ int ret = archive_read_data_into_fd(archive, fd);
+ close(fd);
if(ret == ARCHIVE_WARN) {
/* operation succeeded but a non-critical error was encountered */
_alpm_log(PM_LOG_DEBUG, "warning extracting %s (%s)\n",
@@ -467,8 +466,8 @@ static int extract_single_file(struct archive *archive,
alpm_logaction("error: could not extract %s (%s)\n",
entryname, archive_error_string(archive));
unlink(tempfile);
+ FREE(tempfile);
FREE(hash_orig);
- close(fd);
return(1);
}
@@ -578,7 +577,6 @@ static int extract_single_file(struct archive *archive,
FREE(hash_orig);
unlink(tempfile);
FREE(tempfile);
- close(fd);
} else {
/* we didn't need a backup */
if(notouch) {