Changeset 1627 in kBuild
- Timestamp:
- May 12, 2008 11:23:21 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/cp.c
r1597 r1627 79 79 #include "cp_extern.h" 80 80 #include "kmkbuiltin.h" 81 #include "kbuild_protection.h" 81 82 82 83 … … 112 113 /* have wrappers for globals in cp_extern! */ 113 114 115 static KBUILDPROTECTION g_ProtData; 114 116 const char *cp_argv0; 115 117 static char emptystring[] = ""; … … 141 143 { "ignore-non-existing", no_argument, 0, CP_OPT_IGNORE_NON_EXISTING }, 142 144 { "changed", no_argument, 0, CP_OPT_CHANGED }, 143 /*144 145 { "disable-protection", no_argument, 0, CP_OPT_DISABLE_PROTECTION }, 145 146 { "enable-protection", no_argument, 0, CP_OPT_ENABLE_PROTECTION }, … … 147 148 { "disable-full-protection", no_argument, 0, CP_OPT_DISABLE_FULL_PROTECTION }, 148 149 { "protection-depth", required_argument, 0, CP_OPT_PROTECTION_DEPTH }, 149 */150 150 { 0, 0, 0, 0 }, 151 151 }; … … 153 153 154 154 static int copy(char *[], enum op, int); 155 static int mastercmp(const FTSENT * const *, const FTSENT * const*);155 static int mastercmp(const FTSENT **, const FTSENT **); 156 156 #ifdef SIGINFO 157 157 static void siginfo(int __unused); … … 164 164 struct stat to_stat, tmp_stat; 165 165 enum op type; 166 int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash ;166 int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash, rc; 167 167 char *target; 168 168 … … 175 175 info = 0; 176 176 cp_ignore_non_existing = cp_changed_only = 0; 177 kBuildProtectionInit(&g_ProtData); 177 178 178 179 /* reset getopt and set progname. */ … … 199 200 break; 200 201 case 'R': 201 #ifdef DO_CP_TREE202 202 Rflag = 1; 203 203 break; 204 #else205 return errx(1, "recursive copy is not implemented!");206 #endif207 204 case 'f': 208 205 fflag = 1; … … 220 217 pflag = 1; 221 218 break; 219 #if 0 /* only one -R */ 222 220 case 'r': 223 #ifdef DO_CP_TREE224 221 rflag = 1; 225 222 break; 226 #else227 return errx(1, "recursive copy is not implemented!");228 223 #endif 229 224 case 'v': … … 232 227 case CP_OPT_HELP: 233 228 usage(stdout); 229 kBuildProtectionTerm(&g_ProtData); 234 230 return 0; 235 231 case CP_OPT_VERSION: 232 kBuildProtectionTerm(&g_ProtData); 236 233 return kbuild_version(argv[0]); 237 234 case CP_OPT_IGNORE_NON_EXISTING: … … 241 238 cp_changed_only = 1; 242 239 break; 240 case CP_OPT_DISABLE_PROTECTION: 241 kBuildProtectionDisable(&g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE); 242 break; 243 case CP_OPT_ENABLE_PROTECTION: 244 kBuildProtectionEnable(&g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE); 245 break; 246 case CP_OPT_ENABLE_FULL_PROTECTION: 247 kBuildProtectionEnable(&g_ProtData, KBUILDPROTECTIONTYPE_FULL); 248 break; 249 case CP_OPT_DISABLE_FULL_PROTECTION: 250 kBuildProtectionDisable(&g_ProtData, KBUILDPROTECTIONTYPE_FULL); 251 break; 252 case CP_OPT_PROTECTION_DEPTH: 253 if (kBuildProtectionSetDepth(&g_ProtData, optarg)) { 254 kBuildProtectionTerm(&g_ProtData); 255 return 1; 256 } 257 break; 243 258 default: 259 kBuildProtectionTerm(&g_ProtData); 244 260 return usage(stderr); 245 261 } … … 247 263 argv += optind; 248 264 249 if (argc < 2) 265 if (argc < 2) { 266 kBuildProtectionTerm(&g_ProtData); 250 267 return usage(stderr); 268 } 251 269 252 270 fts_options = FTS_NOCHDIR | FTS_PHYSICAL; 253 271 if (rflag) { 254 if (Rflag) 272 if (Rflag) { 273 kBuildProtectionTerm(&g_ProtData); 255 274 return errx(1, 256 275 "the -R and -r options may not be specified together."); 276 } 257 277 if (Hflag || Lflag || Pflag) 258 278 errx(1, 259 279 "the -H, -L, and -P options may not be specified with the -r option."); 260 #ifdef DO_CP_TREE261 280 fts_options &= ~FTS_PHYSICAL; 262 281 fts_options |= FTS_LOGICAL; 263 #endif 264 } 265 #ifdef DO_CP_TREE 282 } 266 283 if (Rflag) { 267 284 if (Hflag) … … 271 288 fts_options |= FTS_LOGICAL; 272 289 } 273 } else 274 #endif 275 { 290 } else { 276 291 fts_options &= ~FTS_PHYSICAL; 277 292 fts_options |= FTS_LOGICAL | FTS_COMFOLLOW; … … 283 298 /* Save the target base in "to". */ 284 299 target = argv[--argc]; 285 if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path)) 300 if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path)) { 301 kBuildProtectionTerm(&g_ProtData); 286 302 return errx(1, "%s: name too long", target); 303 } 287 304 to.p_end = to.p_path + strlen(to.p_path); 288 305 if (to.p_path == to.p_end) { … … 313 330 */ 314 331 r = stat(to.p_path, &to_stat); 315 if (r == -1 && errno != ENOENT) 332 if (r == -1 && errno != ENOENT) { 333 kBuildProtectionTerm(&g_ProtData); 316 334 return err(1, "%s", to.p_path); 335 } 317 336 if (r == -1 || !S_ISDIR(to_stat.st_mode)) { 318 337 /* 319 338 * Case (1). Target is not a directory. 320 339 */ 321 if (argc > 1) 340 if (argc > 1) { 341 kBuildProtectionTerm(&g_ProtData); 322 342 return usage(stderr); 343 } 323 344 /* 324 345 * Need to detect the case: … … 342 363 343 364 if (have_trailing_slash && type == FILE_TO_FILE) { 365 kBuildProtectionTerm(&g_ProtData); 344 366 if (r == -1) 345 367 return errx(1, "directory %s does not exist", … … 354 376 type = FILE_TO_DIR; 355 377 356 return copy(argv, type, fts_options); 378 /* Finally, check that the "to" directory isn't protected. */ 379 if (kBuildProtectionEnforce(&g_ProtData, 380 Rflag || rflag 381 ? KBUILDPROTECTIONTYPE_RECURSIVE 382 : KBUILDPROTECTIONTYPE_FULL, 383 to.p_path)) { 384 kBuildProtectionTerm(&g_ProtData); 385 return 1; 386 } 387 388 rc = copy(argv, type, fts_options); 389 kBuildProtectionTerm(&g_ProtData); 390 return rc; 357 391 } 358 392 … … 613 647 */ 614 648 static int 615 mastercmp(const FTSENT * const *a, const FTSENT * const*b)649 mastercmp(const FTSENT **a, const FTSENT **b) 616 650 { 617 651 int a_info, b_info; … … 643 677 usage(FILE *fp) 644 678 { 645 fprintf(fp, "usage: %s [options] src target\n" 646 " or: %s [options] src1 ... srcN directory\n" 647 " or: %s --help\n" 648 " or: %s --version\n" 649 "\n" 650 "Options:\n" 651 " -R Recursive copy.\n" 652 " -H Follow symbolic links on the commandline. Only valid with -R.\n" 653 " -L Follow all symbolic links. Only valid with -R.\n" 654 " -P Do not follow symbolic links. Default. Only valid with -R\n" 655 " -f Force. Overrides -i and -n.\n" 656 " -i Iteractive. Overrides -n and -f.\n" 657 " -n Don't overwrite any files. Overrides -i and -f.\n" 658 " --ignore-non-existing\n" 659 " Don't fail if the specified source file doesn't exist.\n" 660 " --changed\n" 661 " Only copy if changed (i.e. compare first). TODO.\n" 662 , 663 g_progname, g_progname, g_progname, g_progname); 679 fprintf(fp, 680 "usage: %s [options] src target\n" 681 " or: %s [options] src1 ... srcN directory\n" 682 " or: %s --help\n" 683 " or: %s --version\n" 684 "\n" 685 "Options:\n" 686 " -R Recursive copy.\n" 687 " -H Follow symbolic links on the commandline. Only valid with -R.\n" 688 " -L Follow all symbolic links. Only valid with -R.\n" 689 " -P Do not follow symbolic links. Default. Only valid with -R\n" 690 " -f Force. Overrides -i and -n.\n" 691 " -i Iteractive. Overrides -n and -f.\n" 692 " -n Don't overwrite any files. Overrides -i and -f.\n" 693 " --ignore-non-existing\n" 694 " Don't fail if the specified source file doesn't exist.\n" 695 " --changed\n" 696 " Only copy if changed (i.e. compare first).\n" 697 " --disable-protection\n" 698 " Will disable the protection file protection applied with -R.\n" 699 " --enable-protection\n" 700 " Will enable the protection file protection applied with -R.\n" 701 " --enable-full-protection\n" 702 " Will enable the protection file protection for all operations.\n" 703 " --disable-full-protection\n" 704 " Will disable the protection file protection for all operations.\n" 705 " --protection-depth\n" 706 " Number or path indicating the file protection depth. Default: %d\n" 707 "\n" 708 "Environment:\n" 709 " KMK_CP_DISABLE_PROTECTION\n" 710 " Same as --disable-protection. Overrides command line.\n" 711 " KMK_CP_ENABLE_PROTECTION\n" 712 " Same as --enable-protection. Overrides everyone else.\n" 713 " KMK_CP_ENABLE_FULL_PROTECTION\n" 714 " Same as --enable-full-protection. Overrides everyone else.\n" 715 " KMK_CP_DISABLE_FULL_PROTECTION\n" 716 " Same as --disable-full-protection. Overrides command line.\n" 717 " KMK_CP_PROTECTION_DEPTH\n" 718 " Same as --protection-depth. Overrides command line.\n" 719 "\n" 720 "The file protection of the top %d layers of the file hierarchy is there\n" 721 "to try prevent makefiles from doing bad things to your system. This\n" 722 "protection is not bulletproof, but should help prevent you from shooting\n" 723 "yourself in the foot.\n" 724 , 725 g_progname, g_progname, g_progname, g_progname, 726 kBuildProtectionDefaultDepth(), kBuildProtectionDefaultDepth()); 664 727 return 1; 665 728 }
Note:
See TracChangeset
for help on using the changeset viewer.