tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg_add: save and restore the working directory around pkg extraction



Hey folks,

I'd like to apply the patch below, which fixes PR bin/58809 for me
(once we import the updated pkgsrc version into NetBSD base).

Any comments/objections?

Martin


Save and restore current working directory around chdir() and
pkg extraction.

Index: perform.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/perform.c,v
retrieving revision 1.126
diff -u -r1.126 perform.c
--- perform.c	1 Nov 2024 11:26:46 -0000	1.126
+++ perform.c	5 Nov 2024 06:24:22 -0000
@@ -692,7 +692,7 @@
 	int r;
 	plist_t *p;
 	const char *last_file;
-	char *fullpath;
+	char *fullpath, orig_cwd[PATH_MAX];
 
 	if (Fake)
 		return 0;
@@ -707,6 +707,11 @@
 		return -1;
 	}
 
+	if (getcwd(orig_cwd, sizeof(orig_cwd)) == NULL) {
+		warn("Can't get current working directory");
+		return -1;
+	}
+
 	if (chdir(pkg->install_prefix) == -1) {
 		warn("Can't change into prefix: %s", pkg->install_prefix);
 		return -1;
@@ -833,6 +838,8 @@
 		pkgdb_close();
 	archive_write_free(writer);
 
+	chdir(orig_cwd);
+
 	return r;
 }
 


Home | Main Index | Thread Index | Old Index