Changeset 2476 in kBuild
- Timestamp:
- Jul 20, 2011 12:52:30 AM (13 years ago)
- Location:
- trunk/src/kmk/kmkbuiltin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/install.c
r2113 r2476 123 123 static gid_t gid; 124 124 static uid_t uid; 125 static int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose ;125 static int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose, mode_given; 126 126 static mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; 127 127 static const char *suffix = BACKUP_SUFFIX; 128 128 static int ignore_perm_errors; 129 static int hard_link_files_when_possible; 129 130 130 131 static struct option long_options[] = … … 134 135 { "ignore-perm-errors", no_argument, 0, 263 }, 135 136 { "no-ignore-perm-errors", no_argument, 0, 264 }, 137 { "hard-link-files-when-possible", no_argument, 0, 265 }, 138 { "no-hard-link-files-when-possible", no_argument, 0, 266 }, 136 139 { 0, 0, 0, 0 }, 137 140 }; … … 169 172 gid = 0; 170 173 uid = 0; 171 dobackup = docompare = dodir = dopreserve = dostrip = nommap = safecopy = verbose = 0;174 dobackup = docompare = dodir = dopreserve = dostrip = nommap = safecopy = verbose = mode_given = 0; 172 175 ignore_perm_errors = geteuid() != 0; 176 hard_link_files_when_possible = 0; 173 177 174 178 /* reset getopt and set progname. */ … … 220 224 mode = bsd_getmode(set, 0); 221 225 free(set); 226 mode_given = 1; 222 227 break; 223 228 case 'o': … … 247 252 ignore_perm_errors = 0; 248 253 break; 254 case 265: 255 hard_link_files_when_possible = 1; 256 break; 257 case 266: 258 hard_link_files_when_possible = 0; 259 break; 249 260 case '?': 250 261 default: … … 385 396 || ( stricmp(from_name, _PATH_DEVNULL) 386 397 && stricmp(from_name, "nul") 387 # ifdef __EMX__398 # ifdef __EMX__ 388 399 && stricmp(from_name, "/dev/nul") 389 # endif400 # endif 390 401 ) 391 402 #else … … 422 433 /* Only copy safe if the target exists. */ 423 434 tempcopy = safecopy && target; 435 436 /* Try hard linking if wanted and possible. */ 437 if (hard_link_files_when_possible) 438 { 439 const char *why_not = NULL; 440 if (devnull) { 441 why_not = "/dev/null"; 442 } else if (dostrip) { 443 why_not = "strip (-s)"; 444 } else if (docompare) { 445 why_not = "compare (-C)"; 446 } else if (dobackup) { 447 why_not = "backup (-b/-B)"; 448 } else if (safecopy) { 449 why_not = "safe copy (-S)"; 450 } else if (mode_given && mode != (from_sb.st_mode & ALLPERMS)) { 451 why_not = "mode mismatch"; 452 } else if (uid != (uid_t)-1 && gid != from_sb.st_uid) { 453 why_not = "uid mismatch"; 454 } else if (gid != (gid_t)-1 && gid != from_sb.st_gid) { 455 why_not = "gid mismatch"; 456 } else { 457 int rcLink = link(from_name, to_name); 458 if (rcLink != 0 && errno == EEXIST) { 459 unlink(to_name); 460 rcLink = link(from_name, to_name); 461 } 462 if (rcLink == 0) { 463 if (verbose) 464 printf("install: %s -> %s (hardlinked)\n", from_name, to_name); 465 goto l_done; 466 } 467 if (verbose) 468 printf("install: hard linking '%s' to '%s' failed: %s\n", 469 to_name, from_name, strerror(errno)); 470 why_not = NULL; 471 } 472 if (verbose && why_not) 473 printf("install: not hard linking '%s' to '%s' because: %s\n", 474 to_name, from_name, why_not); 475 476 /* Can't hard link or we failed, continue as nothing happend. */ 477 } 424 478 425 479 if (!devnull && (from_fd = open(from_name, O_RDONLY | O_BINARY, 0)) < 0) … … 973 1027 { 974 1028 fprintf(pf, 975 "usage: %s [-bCcpSsv] [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n" 1029 "usage: %s [-bCcpSsv] [--[no-]hard-link-files-when-possible]\n" 1030 " [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n" 976 1031 " [-g group] [-m mode] [-o owner] file1 file2\n" 977 1032 " or: %s [-bCcpSsv] [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n" -
trunk/src/kmk/kmkbuiltin/mscfakes.c
r2413 r2476 158 158 case ERROR_FILENAME_EXCED_RANGE: errno = ENOENT; break; 159 159 case ERROR_NESTING_NOT_ALLOWED: errno = EAGAIN; break; 160 #ifdef EMLINK 161 case ERROR_TOO_MANY_LINKS: errno = EMLINK; break; 162 #endif 160 163 } 161 164 … … 258 261 int link(const char *pszDst, const char *pszLink) 259 262 { 260 errno = ENOSYS;261 err(1, "link() is not implemented on windows!");262 return -1;263 if (CreateHardLink(pszDst, pszLink, NULL)) 264 return 0; 265 return msc_set_errno(GetLastError()); 263 266 } 264 267
Note:
See TracChangeset
for help on using the changeset viewer.