diff --git a/lib/package_script.c b/lib/package_script.c index a902761b..738cc99a 100644 --- a/lib/package_script.c +++ b/lib/package_script.c @@ -60,6 +60,12 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, fpath = strdup(".xbps-script-XXXXXX"); } + /* change cwd to rootdir to exec the script */ + if (chdir(xhp->rootdir) == -1) { + rv = errno; + goto out; + } + /* Create temp file to run script */ if ((fd = mkstemp(fpath)) == -1) { xbps_dbg_printf(xhp, "%s: mkstemp %s\n", @@ -80,12 +86,6 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, fdatasync(fd); close(fd); - /* change cwd to rootdir to exec the script */ - if (chdir(xhp->rootdir) == -1) { - rv = errno; - goto out; - } - /* exec script */ rv = xbps_file_exec(xhp, fpath, action, pkgname, version, update ? "yes" : "no",