tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: pkg_add: save and restore the working directory around pkg extraction
Now that the freeze is over and we have branched, I'd like to commit a
fix for PR 58809 soonish.
Below is the proposed (updated) patch.
Martin
Index: perform.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/perform.c,v
retrieving revision 1.128
diff -u -p -r1.128 perform.c
--- perform.c 7 Dec 2024 13:56:46 -0000 1.128
+++ perform.c 27 Dec 2024 17:22:29 -0000
@@ -693,6 +693,13 @@ extract_files(struct pkg_task *pkg)
plist_t *p;
const char *last_file;
char *fullpath;
+#ifdef O_DIRECTORY
+ int workdir;
+#define NO_WORK_DIR -1
+#else
+ char *workdir;
+#define NO_WORK_DIR NULL
+#endif
if (Fake)
return 0;
@@ -707,6 +714,16 @@ extract_files(struct pkg_task *pkg)
return -1;
}
+#ifdef O_DIRECTORY
+ workdir = open(".", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
+#else
+ workdir = getcwd(NULL, 0);
+#endif
+ if (workdir == NO_WORK_DIR) {
+ warn("Can't open 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 +850,14 @@ out:
pkgdb_close();
archive_write_free(writer);
+#ifdef O_DIRECTORY
+ fchdir(workdir);
+ close(workdir);
+#else
+ chdir(workdir);
+ free(workdir);
+#endif
+
return r;
}
Home |
Main Index |
Thread Index |
Old Index