You've already forked macports-base
mirror of
https://github.com/macports/macports-base.git
synced 2026-07-12 18:18:43 -07:00
Update vendor/install to file_cmds-457.100.3
This commit is contained in:
+339
-173
File diff suppressed because it is too large
Load Diff
Vendored
+1205
-409
File diff suppressed because it is too large
Load Diff
+107
-141
@@ -1,79 +1,108 @@
|
||||
Applied to original from file_cmds-430.140.2
|
||||
Add clonefile() support. Applies to original from file_cmds-457.100.3.
|
||||
|
||||
--- xinstall.c.orig 2024-08-20 16:07:42
|
||||
+++ xinstall.c 2025-08-18 10:03:32
|
||||
@@ -70,9 +70,9 @@ __used static const char rcsid[] =
|
||||
--- xinstall.c.orig 2025-08-23 16:18:09
|
||||
+++ xinstall.c 2025-08-23 18:22:31
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#ifdef __APPLE__
|
||||
#ifdef TARGET_OS_OSX
|
||||
-#define WITH_DIGESTS
|
||||
+/*#define WITH_DIGESTS*/
|
||||
#endif
|
||||
#include <sys/param.h>
|
||||
#endif /* __APPLE__ */
|
||||
@@ -72,7 +72,8 @@
|
||||
#ifdef __APPLE__
|
||||
#include <TargetConditionals.h>
|
||||
#include <copyfile.h>
|
||||
-#include "pathnames.h"
|
||||
+#include <sys/attr.h>
|
||||
+#include <sys/clonefile.h>
|
||||
#endif /* __APPLE__ */
|
||||
-
|
||||
-#include "pathnames.h"
|
||||
|
||||
/* Bootstrap aid - this doesn't exist in most older releases */
|
||||
#ifndef MAP_FAILED
|
||||
@@ -92,6 +92,8 @@ char *suffix = BACKUP_SUFFIX;
|
||||
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
char *suffix = BACKUP_SUFFIX;
|
||||
#define st_atim st_atimespec
|
||||
#define st_mtim st_mtimespec
|
||||
@@ -165,6 +166,7 @@ static char *destdir, *fflags, *metafile, *tags;
|
||||
static char *destdir, *fflags, *metafile, *tags;
|
||||
#endif
|
||||
|
||||
+static int clone __P((const char *, const char *, int, char *, size_t));
|
||||
+static void handle_existing_file __P((char *path, struct stat *sbp));
|
||||
void copy __P((int, char *, int, char *, off_t));
|
||||
int compare __P((int, const char *, size_t, int, const char *, size_t));
|
||||
int create_newfile __P((char *, int, struct stat *));
|
||||
@@ -100,6 +102,7 @@ void strip __P((char *));
|
||||
void install_dir __P((char *));
|
||||
u_long numeric_id __P((char *, char *));
|
||||
void strip __P((char *));
|
||||
+static void tempfile_template __P((const char *, char *, size_t));
|
||||
int trymmap __P((int));
|
||||
void usage __P((void));
|
||||
+static int clone(const char *, const char *, int, char *, size_t);
|
||||
static int compare(int, const char *, size_t, int, const char *, size_t,
|
||||
char **);
|
||||
static char *copy(int, const char *, int, const char *, off_t);
|
||||
@@ -196,6 +198,7 @@ static int strip(const char *, int, const char *, char
|
||||
const char *, const char *, off_t);
|
||||
static int parseid(const char *, id_t *);
|
||||
static int strip(const char *, int, const char *, char **);
|
||||
+static void tempfile_template (const char *, char *, size_t);
|
||||
static void usage(void);
|
||||
|
||||
@@ -276,9 +279,10 @@ install(char *from_name, char *to_name,
|
||||
{
|
||||
struct stat from_sb, temp_sb, to_sb;
|
||||
struct utimbuf utb;
|
||||
- int devnull, files_match, from_fd=0, serrno, target;
|
||||
- int tempcopy, temp_fd, to_fd=0;
|
||||
+ int devnull, files_match, from_fd=-1, serrno, target;
|
||||
+ int tempcopy, temp_fd=-1, to_fd=-1;
|
||||
char backup[MAXPATHLEN], *p, pathbuf[MAXPATHLEN], tempfile[MAXPATHLEN];
|
||||
+ const int tryclone = 1;
|
||||
|
||||
files_match = 0;
|
||||
|
||||
@@ -334,6 +338,20 @@ install(char *from_name, char *to_name,
|
||||
#ifdef __APPLE__
|
||||
@@ -959,6 +962,16 @@ install(const char *from_name, const char *to_name, u_
|
||||
}
|
||||
|
||||
if (!files_match) {
|
||||
+ int done_clone = 0;
|
||||
+ if (tryclone && !devnull && !dostrip) {
|
||||
+ if (!tempcopy && target) {
|
||||
+ handle_existing_file(to_name, &to_sb);
|
||||
+ }
|
||||
+ done_clone = (clone(from_name, to_name, tempcopy, tempfile, sizeof(tempfile)) == 0);
|
||||
+ }
|
||||
+ if (done_clone &&
|
||||
+ (((to_fd = open(tempcopy ? tempfile : to_name, O_RDONLY, 0)) < 0)
|
||||
+ || (!tempcopy && fstat(to_fd, &to_sb) == -1))) {
|
||||
+ (void)unlink(tempcopy ? tempfile : to_name);
|
||||
+ done_clone = 0;
|
||||
+ if (!devnull && !dostrip) {
|
||||
+ done_clone = (clone(from_name, to_name, 1, tempfile, sizeof(tempfile)) == 0);
|
||||
+ }
|
||||
+ if (done_clone &&
|
||||
+ (((to_fd = open(tempfile, O_RDONLY, 0)) < 0))) {
|
||||
+ (void)unlink(tempfile);
|
||||
+ done_clone = 0;
|
||||
+ }
|
||||
+ if (!done_clone) {
|
||||
if (tempcopy) {
|
||||
to_fd = create_tempfile(to_name, tempfile,
|
||||
sizeof(tempfile));
|
||||
@@ -350,6 +368,7 @@ install(char *from_name, char *to_name,
|
||||
if (!devnull)
|
||||
copy(from_fd, from_name, to_fd,
|
||||
tempcopy ? tempfile : to_name, from_sb.st_size);
|
||||
to_fd = create_tempfile(to_name, tempfile,
|
||||
sizeof(tempfile));
|
||||
if (to_fd < 0)
|
||||
@@ -976,17 +989,29 @@ install(const char *from_name, const char *to_name, u_
|
||||
*/
|
||||
if (errno == EPERM) {
|
||||
warnx("sandbox detected, falling back to direct copy");
|
||||
- if ((!target || unlink(to_name) == 0 || errno == ENOENT) &&
|
||||
- (to_fd = open(to_name, O_RDWR|O_CREAT|O_EXCL, mode)) >= 0) {
|
||||
- if (dostrip) {
|
||||
- stripped = strip(to_name, to_fd, from_name,
|
||||
- &digestresult);
|
||||
- }
|
||||
- if (!stripped) {
|
||||
- digestresult = copy(from_fd, from_name, to_fd,
|
||||
- to_name, from_sb.st_size);
|
||||
+ if (!target || unlink(to_name) == 0 || errno == ENOENT) {
|
||||
+ if (!devnull && !dostrip) {
|
||||
+ done_clone = (clone(from_name, to_name, 0, NULL, 0) == 0);
|
||||
+ if (done_clone) {
|
||||
+ if ((to_fd = open(to_name, O_RDONLY, 0)) < 0) {
|
||||
+ (void)unlink(to_name);
|
||||
+ } else {
|
||||
+ digestresult = digest_file(to_name);
|
||||
+ goto copied;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ if ((to_fd = open(to_name, O_RDWR|O_CREAT|O_EXCL, mode)) >= 0) {
|
||||
+ if (dostrip) {
|
||||
+ stripped = strip(to_name, to_fd, from_name,
|
||||
+ &digestresult);
|
||||
+ }
|
||||
+ if (!stripped) {
|
||||
+ digestresult = copy(from_fd, from_name, to_fd,
|
||||
+ to_name, from_sb.st_size);
|
||||
+ }
|
||||
+ goto copied;
|
||||
}
|
||||
- goto copied;
|
||||
}
|
||||
errno = EPERM;
|
||||
/* fall through to err() below */
|
||||
@@ -1006,6 +1031,7 @@ install(const char *from_name, const char *to_name, u_
|
||||
tempfile, from_sb.st_size);
|
||||
}
|
||||
}
|
||||
+ } /* !done_clone */
|
||||
}
|
||||
|
||||
if (dostrip) {
|
||||
@@ -592,11 +611,11 @@ compare(int from_fd, const char *from_name, size_t fro
|
||||
@@ -1292,11 +1318,11 @@ compare(int from_fd, const char *from_name __unused, s
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -82,16 +111,16 @@ Applied to original from file_cmds-430.140.2
|
||||
+ * tempfile_template --
|
||||
+ * prepare a template filename for use with mktemp/mkstemp.
|
||||
*/
|
||||
-int
|
||||
-create_tempfile(char *path,
|
||||
-static int
|
||||
-create_tempfile(const char *path, char *temp, size_t tsize)
|
||||
+static void
|
||||
+tempfile_template(const char *path,
|
||||
char *temp,
|
||||
size_t tsize)
|
||||
+tempfile_template(const char *path, char *temp, size_t tsize)
|
||||
{
|
||||
@@ -610,7 +629,49 @@ create_tempfile(char *path,
|
||||
char *p;
|
||||
|
||||
@@ -1308,6 +1334,16 @@ create_tempfile(const char *path, char *temp, size_t t
|
||||
p = temp;
|
||||
(void)strncpy(p, "INS@XXXX", &temp[tsize - 1] - p);
|
||||
(void)strncpy(p, "INS@XXXXXX", &temp[tsize - 1] - p);
|
||||
temp[tsize - 1] = '\0';
|
||||
+}
|
||||
+
|
||||
@@ -99,83 +128,20 @@ Applied to original from file_cmds-430.140.2
|
||||
+ * create_tempfile --
|
||||
+ * create a temporary file based on path and open it
|
||||
+ */
|
||||
+int
|
||||
+create_tempfile(char *path,
|
||||
+ char *temp,
|
||||
+ size_t tsize)
|
||||
+static int
|
||||
+create_tempfile(const char *path, char *temp, size_t tsize)
|
||||
+{
|
||||
+ tempfile_template(path, temp, tsize);
|
||||
return (mkstemp(temp));
|
||||
}
|
||||
|
||||
@@ -1408,8 +1444,25 @@ done:
|
||||
err(EX_OSERR, "fsync failed for %s", to_name);
|
||||
}
|
||||
return (digest_end(&ctx, NULL));
|
||||
+}
|
||||
+
|
||||
+/* unlink or move (backup) an existing file */
|
||||
+static void
|
||||
+handle_existing_file(char *path, struct stat *sbp)
|
||||
+{
|
||||
+ char backup[MAXPATHLEN];
|
||||
+ /*
|
||||
+ * Unlink now... avoid ETXTBSY errors later. Try to turn
|
||||
+ * off the append/immutable bits -- if we fail, go ahead,
|
||||
+ * it might work.
|
||||
+ */
|
||||
+ if (sbp->st_flags & NOCHANGEBITS)
|
||||
+ (void)chflags(path, sbp->st_flags & ~NOCHANGEBITS);
|
||||
+
|
||||
+ if (dobackup) {
|
||||
+ if (snprintf(backup, MAXPATHLEN, "%s%s",
|
||||
+ path, suffix) != strlen(path) + strlen(suffix))
|
||||
+ errx(EX_OSERR, "%s: backup filename too long",
|
||||
+ path);
|
||||
+ (void)snprintf(backup, MAXPATHLEN, "%s%s",
|
||||
+ path, suffix);
|
||||
+ if (verbose)
|
||||
+ (void)printf("install: %s -> %s\n",
|
||||
+ path, backup);
|
||||
+ if (rename(path, backup) < 0)
|
||||
+ err(EX_OSERR, "rename: %s to %s", path, backup);
|
||||
+ } else {
|
||||
+ (void)unlink(path);
|
||||
+ }
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -622,31 +683,8 @@ create_newfile(char *path,
|
||||
int target,
|
||||
struct stat *sbp)
|
||||
{
|
||||
- char backup[MAXPATHLEN];
|
||||
-
|
||||
if (target) {
|
||||
- /*
|
||||
- * Unlink now... avoid ETXTBSY errors later. Try to turn
|
||||
- * off the append/immutable bits -- if we fail, go ahead,
|
||||
- * it might work.
|
||||
- */
|
||||
- if (sbp->st_flags & NOCHANGEBITS)
|
||||
- (void)chflags(path, sbp->st_flags & ~NOCHANGEBITS);
|
||||
-
|
||||
- if (dobackup) {
|
||||
- if (snprintf(backup, MAXPATHLEN, "%s%s",
|
||||
- path, suffix) != strlen(path) + strlen(suffix))
|
||||
- errx(EX_OSERR, "%s: backup filename too long",
|
||||
- path);
|
||||
- (void)snprintf(backup, MAXPATHLEN, "%s%s",
|
||||
- path, suffix);
|
||||
- if (verbose)
|
||||
- (void)printf("install: %s -> %s\n",
|
||||
- path, backup);
|
||||
- if (rename(path, backup) < 0)
|
||||
- err(EX_OSERR, "rename: %s to %s", path, backup);
|
||||
- } else
|
||||
- (void)unlink(path);
|
||||
+ handle_existing_file(path, sbp);
|
||||
}
|
||||
|
||||
return (open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR));
|
||||
@@ -736,6 +774,22 @@ copy(int from_fd, char *from_name,
|
||||
}
|
||||
|
||||
/*
|
||||
+/*
|
||||
+ * clone --
|
||||
+ * create a clone of a file
|
||||
+ */
|
||||
@@ -185,13 +151,13 @@ Applied to original from file_cmds-430.140.2
|
||||
+{
|
||||
+ if (use_temp) {
|
||||
+ tempfile_template(to_name, temp_name, tsize);
|
||||
+ mktemp(temp_name);
|
||||
+ quiet_mktemp(temp_name);
|
||||
+ to_name = temp_name;
|
||||
+ }
|
||||
+ return clonefile(from_name, to_name, CLONE_NOOWNERCOPY);
|
||||
+}
|
||||
}
|
||||
|
||||
+
|
||||
+/*
|
||||
/*
|
||||
* strip --
|
||||
* use strip(1) to strip the target file
|
||||
*/
|
||||
* Use strip(1) to strip the target file.
|
||||
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
Avoid race condition with concurrent directory creation.
|
||||
--- xinstall.c.orig
|
||||
+++ xinstall.c
|
||||
@@ -831,8 +831,13 @@ install_dir(char *path)
|
||||
*p = '\0';
|
||||
if (stat(path, &sb)) {
|
||||
if (errno != ENOENT || mkdir(path, 0755) < 0) {
|
||||
- err(EX_OSERR, "mkdir %s", path);
|
||||
- /* NOTREACHED */
|
||||
+ /* Check if the dir was created between
|
||||
+ * our stat and mkdir calls. */
|
||||
+ int saved_errno = errno;
|
||||
+ if (errno != EEXIST || stat(path, &sb) < 0 || !S_ISDIR(sb.st_mode)) {
|
||||
+ errc(EX_OSERR, saved_errno, "mkdir %s", path);
|
||||
+ /* NOTREACHED */
|
||||
+ }
|
||||
} else if (verbose)
|
||||
(void)printf("install: mkdir %s\n",
|
||||
path);
|
||||
Reference in New Issue
Block a user