clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name add.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/cvs/obj/src -resource-dir /usr/local/lib/clang/13.0.0 -D HAVE_CONFIG_H -I . -I /usr/src/gnu/usr.bin/cvs/src -I .. -I . -I /usr/src/gnu/usr.bin/cvs/lib -I /usr/src/gnu/usr.bin/cvs/diff -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/cvs/obj/src -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/gnu/usr.bin/cvs/src/add.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | #include "cvs.h" |
| 28 | #include "savecwd.h" |
| 29 | #include "fileattr.h" |
| 30 | |
| 31 | static int add_directory PROTO ((struct file_info *finfo)); |
| 32 | static int build_entry PROTO((char *repository, char *user, char *options, |
| 33 | char *message, List * entries, char *tag)); |
| 34 | |
| 35 | static const char *const add_usage[] = |
| 36 | { |
| 37 | "Usage: %s %s [-k rcs-kflag] [-m message] files...\n", |
| 38 | "\t-k\tUse \"rcs-kflag\" to add the file with the specified kflag.\n", |
| 39 | "\t-m\tUse \"message\" for the creation log.\n", |
| 40 | "(Specify the --help global option for a list of other help options)\n", |
| 41 | NULL |
| 42 | }; |
| 43 | |
| 44 | int |
| 45 | add (argc, argv) |
| 46 | int argc; |
| 47 | char **argv; |
| 48 | { |
| 49 | char *message = NULL; |
| 50 | int i; |
| 51 | char *repository; |
| 52 | int c; |
| 53 | int err = 0; |
| 54 | int added_files = 0; |
| 55 | char *options = NULL; |
| 56 | List *entries; |
| 57 | Vers_TS *vers; |
| 58 | struct saved_cwd cwd; |
| 59 | |
| 60 | |
| 61 | int found_slash = 0; |
| 62 | size_t cvsroot_len; |
| 63 | |
| 64 | if (argc == 1 || argc == -1) |
| 1 | Assuming 'argc' is not equal to 1 | |
|
| 2 | | Assuming the condition is false | |
|
| |
| 65 | usage (add_usage); |
| 66 | |
| 67 | wrap_setup (); |
| 68 | |
| 69 | |
| 70 | optind = 0; |
| 71 | while ((c = getopt (argc, argv, "+k:m:")) != -1) |
| 4 | | Assuming the condition is false | |
|
| 5 | | Loop condition is false. Execution continues on line 90 | |
|
| 72 | { |
| 73 | switch (c) |
| 74 | { |
| 75 | case 'k': |
| 76 | if (options) |
| 77 | free (options); |
| 78 | options = RCS_check_kflag (optarg); |
| 79 | break; |
| 80 | |
| 81 | case 'm': |
| 82 | message = xstrdup (optarg); |
| 83 | break; |
| 84 | case '?': |
| 85 | default: |
| 86 | usage (add_usage); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | argc -= optind; |
| 91 | argv += optind; |
| 92 | |
| 93 | if (argc <= 0) |
| |
| |
| 94 | usage (add_usage); |
| 95 | |
| 96 | cvsroot_len = strlen (current_parsed_root->directory); |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | for (i = 0; i < argc; i++) |
| 8 | | Loop condition is true. Entering loop body | |
|
| 16 | | Assuming 'i' is >= 'argc' | |
|
| 17 | | Loop condition is false. Execution continues on line 151 | |
|
| 102 | { |
| 103 | int skip_file = 0; |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | strip_trailing_slashes (argv[i]); |
| 110 | if (strcmp (argv[i], ".") == 0 |
| 9 | | Assuming the condition is false | |
|
| |
| 111 | || strcmp (argv[i], "..") == 0 |
| 10 | | Assuming the condition is false | |
|
| 112 | || fncmp (argv[i], CVSADM) == 0) |
| 11 | | Assuming the condition is false | |
|
| 113 | { |
| 114 | if (!quiet) |
| 115 | error (0, 0, "cannot add special file `%s'; skipping", argv[i]); |
| 116 | skip_file = 1; |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | char *p; |
| 121 | p = argv[i]; |
| 122 | while (*p != '\0') |
| 13 | | Assuming the condition is false | |
|
| 14 | | Loop condition is false. Execution continues on line 133 | |
|
| 123 | { |
| 124 | if (ISDIRSEP (*p)) |
| 125 | { |
| 126 | found_slash = 1; |
| 127 | break; |
| 128 | } |
| 129 | ++p; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (skip_file) |
| |
| 134 | { |
| 135 | int j; |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | for (j = i; j < argc - 1; ++j) |
| 142 | argv[j] = argv[j + 1]; |
| 143 | --argc; |
| 144 | |
| 145 | --i; |
| 146 | ++err; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | #ifdef CLIENT_SUPPORT |
| 151 | if (current_parsed_root->isremote) |
| 18 | | Assuming field 'isremote' is 0 | |
|
| |
| 152 | { |
| 153 | int i; |
| 154 | |
| 155 | if (argc == 0) |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | return err; |
| 161 | |
| 162 | start_server (); |
| 163 | ign_setup (); |
| 164 | if (options) |
| 165 | { |
| 166 | send_arg (options); |
| 167 | free (options); |
| 168 | } |
| 169 | option_with_arg ("-m", message); |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | if (found_slash) |
| 176 | { |
| 177 | repository = Name_Repository (NULL, NULL); |
| 178 | send_a_repository ("", repository, ""); |
| 179 | free (repository); |
| 180 | } |
| 181 | |
| 182 | for (i = 0; i < argc; ++i) |
| 183 | { |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | if (isdir (argv[i])) |
| 198 | { |
| 199 | char *tag; |
| 200 | char *date; |
| 201 | int nonbranch; |
| 202 | char *rcsdir; |
| 203 | char *p; |
| 204 | char *update_dir; |
| 205 | |
| 206 | |
| 207 | char *filedir; |
| 208 | |
| 209 | if (save_cwd (&cwd)) |
| 210 | error_exit (); |
| 211 | |
| 212 | filedir = xstrdup (argv[i]); |
| 213 | p = last_component (filedir); |
| 214 | if (p == filedir) |
| 215 | { |
| 216 | update_dir = ""; |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | p[-1] = '\0'; |
| 221 | update_dir = filedir; |
| 222 | if (CVS_CHDIR (update_dir) < 0) |
| 223 | error (1, errno, |
| 224 | "could not chdir to %s", update_dir); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | repository = Name_Repository (NULL, update_dir); |
| 229 | |
| 230 | |
| 231 | if (strncmp (repository, current_parsed_root->directory, cvsroot_len) == 0 |
| 232 | && ISDIRSEP (repository[cvsroot_len]) |
| 233 | && strncmp (repository + cvsroot_len + 1, |
| 234 | CVSROOTADM, |
| 235 | sizeof CVSROOTADM - 1) == 0 |
| 236 | && ISDIRSEP (repository[cvsroot_len + sizeof CVSROOTADM]) |
| 237 | && strcmp (repository + cvsroot_len + sizeof CVSROOTADM + 1, |
| 238 | CVSNULLREPOS) == 0) |
| 239 | error (1, 0, "cannot add to %s", repository); |
| 240 | |
| 241 | |
| 242 | |
| 243 | ParseTag (&tag, &date, &nonbranch); |
| 244 | |
| 245 | rcsdir = xmalloc (strlen (repository) + strlen (p) + 5); |
| 246 | sprintf (rcsdir, "%s/%s", repository, p); |
| 247 | |
| 248 | Create_Admin (p, argv[i], rcsdir, tag, date, |
| 249 | nonbranch, 0, 1); |
| 250 | |
| 251 | if (found_slash) |
| 252 | send_a_repository ("", repository, update_dir); |
| 253 | |
| 254 | if (restore_cwd (&cwd, NULL)) |
| 255 | error_exit (); |
| 256 | free_cwd (&cwd); |
| 257 | |
| 258 | if (tag) |
| 259 | free (tag); |
| 260 | if (date) |
| 261 | free (date); |
| 262 | free (rcsdir); |
| 263 | |
| 264 | if (p == filedir) |
| 265 | Subdir_Register ((List *) NULL, (char *) NULL, argv[i]); |
| 266 | else |
| 267 | { |
| 268 | Subdir_Register ((List *) NULL, update_dir, p); |
| 269 | } |
| 270 | free (repository); |
| 271 | free (filedir); |
| 272 | } |
| 273 | } |
| 274 | send_files (argc, argv, 0, 0, SEND_BUILD_DIRS | SEND_NO_CONTENTS); |
| 275 | send_file_names (argc, argv, SEND_EXPAND_WILD); |
| 276 | send_to_server ("add\012", 0); |
| 277 | if (message) |
| 278 | free (message); |
| 279 | return err + get_responses_and_close (); |
| 280 | } |
| 281 | #endif |
| 282 | |
| 283 | |
| 284 | for (i = 0; i < argc; i++) |
| 20 | | Loop condition is true. Entering loop body | |
|
| 285 | { |
| 286 | int begin_err = err; |
| 287 | #ifdef SERVER_SUPPORT |
| 288 | int begin_added_files = added_files; |
| 289 | #endif |
| 290 | struct file_info finfo; |
| 291 | char *p; |
| 292 | #if defined (SERVER_SUPPORT) && !defined (FILENAMES_CASE_INSENSITIVE) |
| 293 | char *found_name; |
| 21 | | 'found_name' declared without an initial value | |
|
| 294 | #endif |
| 295 | |
| 296 | memset (&finfo, 0, sizeof finfo); |
| 297 | |
| 298 | if (save_cwd (&cwd)) |
| 22 | | Assuming the condition is false | |
|
| |
| 299 | error_exit (); |
| 300 | |
| 301 | finfo.fullname = xstrdup (argv[i]); |
| 302 | p = last_component (argv[i]); |
| 303 | if (p == argv[i]) |
| 24 | | Assuming the condition is true | |
|
| |
| 304 | { |
| 305 | finfo.update_dir = ""; |
| 306 | finfo.file = p; |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | p[-1] = '\0'; |
| 311 | finfo.update_dir = argv[i]; |
| 312 | finfo.file = p; |
| 313 | if (CVS_CHDIR (finfo.update_dir) < 0) |
| 314 | error (1, errno, "could not chdir to %s", finfo.update_dir); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | |
| 319 | wrap_add_file (CVSDOTWRAPPER, 1); |
| 320 | |
| 321 | finfo.rcs = NULL; |
| 322 | |
| 323 | |
| 324 | repository = Name_Repository (NULL, finfo.update_dir); |
| 325 | |
| 326 | |
| 327 | if (strncmp (repository, current_parsed_root->directory, cvsroot_len) == 0 |
| 26 | | Assuming the condition is false | |
|
| 328 | && ISDIRSEP (repository[cvsroot_len]) |
| 329 | && strncmp (repository + cvsroot_len + 1, |
| 330 | CVSROOTADM, |
| 331 | sizeof CVSROOTADM - 1) == 0 |
| 332 | && ISDIRSEP (repository[cvsroot_len + sizeof CVSROOTADM]) |
| 333 | && strcmp (repository + cvsroot_len + sizeof CVSROOTADM + 1, |
| 334 | CVSNULLREPOS) == 0) |
| 335 | error (1, 0, "cannot add to %s", repository); |
| 336 | |
| 337 | entries = Entries_Open (0, NULL); |
| 338 | |
| 339 | finfo.repository = repository; |
| 340 | finfo.entries = entries; |
| 341 | |
| 342 | #if defined (SERVER_SUPPORT) && !defined (FILENAMES_CASE_INSENSITIVE) |
| 343 | if (ign_case) |
| 27 | | Assuming 'ign_case' is 0 | |
|
| |
| 344 | { |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | DIR *dirp; |
| 353 | struct dirent *dp; |
| 354 | |
| 355 | dirp = CVS_OPENDIR (finfo.repository); |
| 356 | if (dirp == NULL) |
| 357 | error (1, errno, "cannot read directory %s", finfo.repository); |
| 358 | found_name = NULL; |
| 359 | errno = 0; |
| 360 | while ((dp = CVS_READDIR (dirp)) != NULL) |
| 361 | { |
| 362 | if (cvs_casecmp (dp->d_name, finfo.file) == 0) |
| 363 | { |
| 364 | if (found_name != NULL) |
| 365 | error (1, 0, "%s is ambiguous; could mean %s or %s", |
| 366 | finfo.file, dp->d_name, found_name); |
| 367 | found_name = xstrdup (dp->d_name); |
| 368 | } |
| 369 | } |
| 370 | if (errno != 0) |
| 371 | error (1, errno, "cannot read directory %s", finfo.repository); |
| 372 | CVS_CLOSEDIR (dirp); |
| 373 | |
| 374 | if (found_name != NULL) |
| 375 | { |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | if (isdir (finfo.file)) |
| 382 | { |
| 383 | if (CVS_MKDIR (found_name, 0777) < 0 |
| 384 | && errno != EEXIST) |
| 385 | error (0, errno, "cannot create %s", finfo.file); |
| 386 | } |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | finfo.file = found_name; |
| 392 | } |
| 393 | } |
| 394 | #endif |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | vers = Version_TS (&finfo, options, NULL, NULL, 1, 0); |
| 401 | if (vers->vn_user == NULL) |
| 29 | | Assuming field 'vn_user' is not equal to NULL | |
|
| |
| 402 | { |
| 403 | |
| 404 | if (vers->vn_rcs == NULL) |
| 405 | { |
| 406 | |
| 407 | if (vers->ts_user == NULL) |
| 408 | { |
| 409 | |
| 410 | error (0, 0, "nothing known about %s", finfo.fullname); |
| 411 | err++; |
| 412 | } |
| 413 | else if (!isdir (finfo.file) |
| 414 | || wrap_name_has (finfo.file, WRAP_TOCVS)) |
| 415 | { |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | char *dname = xmalloc (strlen (repository) |
| 421 | + strlen (finfo.file) |
| 422 | + 10); |
| 423 | (void) sprintf (dname, "%s/%s", repository, finfo.file); |
| 424 | if (isdir (dname)) |
| 425 | { |
| 426 | error (0, 0, |
| 427 | "cannot add file `%s' since the directory", |
| 428 | finfo.fullname); |
| 429 | error (0, 0, "`%s' already exists in the repository", |
| 430 | dname); |
| 431 | error (1, 0, "illegal filename overlap"); |
| 432 | } |
| 433 | free (dname); |
| 434 | |
| 435 | if (vers->options == NULL || *vers->options == '\0') |
| 436 | { |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | if (wrap_name_has (finfo.file, WRAP_RCSOPTION)) |
| 442 | { |
| 443 | if (vers->options) |
| 444 | free (vers->options); |
| 445 | vers->options = wrap_rcsoption (finfo.file, 1); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | if (vers->nonbranch) |
| 450 | { |
| 451 | error (0, 0, |
| 452 | "cannot add file on non-branch tag %s", |
| 453 | vers->tag); |
| 454 | ++err; |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | |
| 459 | if (build_entry (repository, finfo.file, vers->options, |
| 460 | message, entries, vers->tag) != 0) |
| 461 | err++; |
| 462 | else |
| 463 | { |
| 464 | added_files++; |
| 465 | if (!quiet) |
| 466 | { |
| 467 | if (vers->tag) |
| 468 | error (0, 0, "\ |
| 469 | scheduling %s `%s' for addition on branch `%s'", |
| 470 | (wrap_name_has (finfo.file, |
| 471 | WRAP_TOCVS) |
| 472 | ? "wrapper" |
| 473 | : "file"), |
| 474 | finfo.fullname, vers->tag); |
| 475 | else |
| 476 | error (0, 0, |
| 477 | "scheduling %s `%s' for addition", |
| 478 | (wrap_name_has (finfo.file, |
| 479 | WRAP_TOCVS) |
| 480 | ? "wrapper" |
| 481 | : "file"), |
| 482 | finfo.fullname); |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | else if (RCS_isdead (vers->srcfile, vers->vn_rcs)) |
| 489 | { |
| 490 | if (isdir (finfo.file) |
| 491 | && !wrap_name_has (finfo.file, WRAP_TOCVS)) |
| 492 | { |
| 493 | error (0, 0, "\ |
| 494 | the directory `%s' cannot be added because a file of the", finfo.fullname); |
| 495 | error (1, 0, "\ |
| 496 | same name already exists in the repository."); |
| 497 | } |
| 498 | else |
| 499 | { |
| 500 | if (vers->nonbranch) |
| 501 | { |
| 502 | error (0, 0, |
| 503 | "cannot add file on non-branch tag %s", |
| 504 | vers->tag); |
| 505 | ++err; |
| 506 | } |
| 507 | else |
| 508 | { |
| 509 | if (!quiet) |
| 510 | { |
| 511 | if (vers->tag) |
| 512 | error (0, 0, "\ |
| 513 | file `%s' will be added on branch `%s' from version %s", |
| 514 | finfo.fullname, vers->tag, vers->vn_rcs); |
| 515 | else |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | error (0, 0, "\ |
| 521 | re-adding file %s (in place of dead revision %s)", |
| 522 | finfo.fullname, vers->vn_rcs); |
| 523 | } |
| 524 | Register (entries, finfo.file, "0", vers->ts_user, |
| 525 | vers->options, |
| 526 | vers->tag, NULL, NULL); |
| 527 | ++added_files; |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | error (0, 0, "%s added independently by second party", |
| 538 | finfo.fullname); |
| 539 | err++; |
| 540 | } |
| 541 | } |
| 542 | else if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0') |
| 31 | | Assuming the condition is false | |
|
| 543 | { |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | if (!quiet) |
| 550 | error (0, 0, "%s has already been entered", finfo.fullname); |
| 551 | err++; |
| 552 | } |
| 553 | else if (vers->vn_user[0] == '-') |
| 32 | | Assuming the condition is false | |
|
| |
| 554 | { |
| 555 | |
| 556 | if (vers->ts_user == NULL) |
| 557 | { |
| 558 | |
| 559 | if (vers->vn_rcs == NULL) |
| 560 | { |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | error (0, 0, "\ |
| 567 | cannot resurrect %s; RCS file removed by second party", finfo.fullname); |
| 568 | err++; |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | char *tmp = xmalloc (strlen (finfo.file) + 50); |
| 578 | |
| 579 | (void) strcpy (tmp, vers->vn_user + 1); |
| 580 | (void) strcpy (vers->vn_user, tmp); |
| 581 | (void) sprintf (tmp, "Resurrected %s", finfo.file); |
| 582 | Register (entries, finfo.file, vers->vn_user, tmp, |
| 583 | vers->options, |
| 584 | vers->tag, vers->date, vers->ts_conflict); |
| 585 | free (tmp); |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | if (update (2, argv + i - 1) == 0) |
| 592 | { |
| 593 | error (0, 0, "%s, version %s, resurrected", |
| 594 | finfo.fullname, |
| 595 | vers->vn_user); |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | error (0, 0, "could not resurrect %s", finfo.fullname); |
| 600 | err++; |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | else |
| 605 | { |
| 606 | |
| 607 | error (0, 0, "\ |
| 608 | %s should be removed and is still there (or is back again)", finfo.fullname); |
| 609 | err++; |
| 610 | } |
| 611 | } |
| 612 | else |
| 613 | { |
| 614 | |
| 615 | if (!quiet) |
| 34 | | Assuming 'quiet' is not equal to 0 | |
|
| |
| 616 | error (0, 0, "%s already exists, with version number %s", |
| 617 | finfo.fullname, |
| 618 | vers->vn_user); |
| 619 | err++; |
| 620 | } |
| 621 | freevers_ts (&vers); |
| 622 | |
| 623 | |
| 624 | if (begin_err == err |
| 625 | && isdir (finfo.file) |
| 626 | && !wrap_name_has (finfo.file, WRAP_TOCVS)) |
| 627 | { |
| 628 | err += add_directory (&finfo); |
| 629 | } |
| 630 | else |
| 631 | { |
| 632 | #ifdef SERVER_SUPPORT |
| 633 | if (server_active && begin_added_files != added_files) |
| 36 | | Assuming 'server_active' is 0 | |
|
| 634 | server_checked_in (finfo.file, finfo.update_dir, repository); |
| 635 | #endif |
| 636 | } |
| 637 | free (repository); |
| 638 | Entries_Close (entries); |
| 639 | |
| 640 | if (restore_cwd (&cwd, NULL)) |
| 37 | | Assuming the condition is false | |
|
| |
| 641 | error_exit (); |
| 642 | free_cwd (&cwd); |
| 643 | |
| 644 | free (finfo.fullname); |
| 645 | #if defined (SERVER_SUPPORT) && !defined (FILENAMES_CASE_INSENSITIVE) |
| 646 | if (ign_case && found_name != NULL) |
| 39 | | Assuming 'ign_case' is not equal to 0 | |
|
| 40 | | The left operand of '!=' is a garbage value |
|
| 647 | free (found_name); |
| 648 | #endif |
| 649 | } |
| 650 | if (added_files && !really_quiet) |
| 651 | error (0, 0, "use '%s commit' to add %s permanently", |
| 652 | program_name, |
| 653 | (added_files == 1) ? "this file" : "these files"); |
| 654 | |
| 655 | if (message) |
| 656 | free (message); |
| 657 | if (options) |
| 658 | free (options); |
| 659 | |
| 660 | return (err); |
| 661 | } |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | static int |
| 671 | add_directory (finfo) |
| 672 | struct file_info *finfo; |
| 673 | { |
| 674 | char *repository = finfo->repository; |
| 675 | List *entries = finfo->entries; |
| 676 | char *dir = finfo->file; |
| 677 | |
| 678 | char *rcsdir = NULL; |
| 679 | struct saved_cwd cwd; |
| 680 | char *message = NULL; |
| 681 | char *tag, *date; |
| 682 | int nonbranch; |
| 683 | char *attrs; |
| 684 | |
| 685 | if (strchr (dir, '/') != NULL) |
| 686 | { |
| 687 | |
| 688 | error (0, 0, |
| 689 | "directory %s not added; must be a direct sub-directory", dir); |
| 690 | return (1); |
| 691 | } |
| 692 | if (fncmp (dir, CVSADM) == 0) |
| 693 | { |
| 694 | error (0, 0, "cannot add a `%s' directory", CVSADM); |
| 695 | return (1); |
| 696 | } |
| 697 | |
| 698 | |
| 699 | ParseTag (&tag, &date, &nonbranch); |
| 700 | |
| 701 | |
| 702 | |
| 703 | fileattr_startdir (repository); |
| 704 | attrs = fileattr_getall (NULL); |
| 705 | fileattr_free (); |
| 706 | |
| 707 | |
| 708 | if (save_cwd (&cwd)) |
| 709 | return (1); |
| 710 | if ( CVS_CHDIR (dir) < 0) |
| 711 | { |
| 712 | error (0, errno, "cannot chdir to %s", finfo->fullname); |
| 713 | return (1); |
| 714 | } |
| 715 | #ifdef SERVER_SUPPORT |
| 716 | if (!server_active && isfile (CVSADM)) |
| 717 | #else |
| 718 | if (isfile (CVSADM)) |
| 719 | #endif |
| 720 | { |
| 721 | error (0, 0, "%s/%s already exists", finfo->fullname, CVSADM); |
| 722 | goto out; |
| 723 | } |
| 724 | |
| 725 | rcsdir = xmalloc (strlen (repository) + strlen (dir) + 5); |
| 726 | sprintf (rcsdir, "%s/%s", repository, dir); |
| 727 | if (isfile (rcsdir) && !isdir (rcsdir)) |
| 728 | { |
| 729 | error (0, 0, "%s is not a directory; %s not added", rcsdir, |
| 730 | finfo->fullname); |
| 731 | goto out; |
| 732 | } |
| 733 | |
| 734 | |
| 735 | message = xmalloc (strlen (rcsdir) |
| 736 | + 80 |
| 737 | + (tag == NULL ? 0 : strlen (tag) + 80) |
| 738 | + (date == NULL ? 0 : strlen (date) + 80)); |
| 739 | (void) sprintf (message, "Directory %s added to the repository\n", rcsdir); |
| 740 | if (tag) |
| 741 | { |
| 742 | (void) strcat (message, "--> Using per-directory sticky tag `"); |
| 743 | (void) strcat (message, tag); |
| 744 | (void) strcat (message, "'\n"); |
| 745 | } |
| 746 | if (date) |
| 747 | { |
| 748 | (void) strcat (message, "--> Using per-directory sticky date `"); |
| 749 | (void) strcat (message, date); |
| 750 | (void) strcat (message, "'\n"); |
| 751 | } |
| 752 | |
| 753 | if (!isdir (rcsdir)) |
| 754 | { |
| 755 | mode_t omask; |
| 756 | Node *p; |
| 757 | List *ulist; |
| 758 | struct logfile_info *li; |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | if (!noexec) |
| 769 | { |
| 770 | omask = umask (cvsumask); |
| 771 | if (CVS_MKDIR (rcsdir, 0777) < 0) |
| 772 | { |
| 773 | error (0, errno, "cannot mkdir %s", rcsdir); |
| 774 | (void) umask (omask); |
| 775 | goto out; |
| 776 | } |
| 777 | (void) umask (omask); |
| 778 | } |
| 779 | |
| 780 | |
| 781 | |
| 782 | fileattr_startdir (rcsdir); |
| 783 | fileattr_setall (NULL, attrs); |
| 784 | fileattr_write (); |
| 785 | fileattr_free (); |
| 786 | if (attrs != NULL) |
| 787 | free (attrs); |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | ulist = getlist (); |
| 793 | p = getnode (); |
| 794 | p->type = UPDATE; |
| 795 | p->delproc = update_delproc; |
| 796 | p->key = xstrdup ("- New directory"); |
| 797 | li = (struct logfile_info *) xmalloc (sizeof (struct logfile_info)); |
| 798 | li->type = T_TITLE; |
| 799 | li->tag = xstrdup (tag); |
| 800 | li->rev_old = li->rev_new = NULL; |
| 801 | p->data = (char *) li; |
| 802 | (void) addnode (ulist, p); |
| 803 | Update_Logfile (rcsdir, message, (FILE *) NULL, ulist); |
| 804 | dellist (&ulist); |
| 805 | } |
| 806 | |
| 807 | #ifdef SERVER_SUPPORT |
| 808 | if (!server_active) |
| 809 | #endif |
| 810 | Create_Admin (".", finfo->fullname, rcsdir, tag, date, nonbranch, 0, 1); |
| 811 | if (tag) |
| 812 | free (tag); |
| 813 | if (date) |
| 814 | free (date); |
| 815 | |
| 816 | if (restore_cwd (&cwd, NULL)) |
| 817 | error_exit (); |
| 818 | free_cwd (&cwd); |
| 819 | |
| 820 | Subdir_Register (entries, (char *) NULL, dir); |
| 821 | |
| 822 | cvs_output (message, 0); |
| 823 | |
| 824 | free (rcsdir); |
| 825 | free (message); |
| 826 | |
| 827 | return (0); |
| 828 | |
| 829 | out: |
| 830 | if (restore_cwd (&cwd, NULL)) |
| 831 | error_exit (); |
| 832 | free_cwd (&cwd); |
| 833 | if (rcsdir != NULL) |
| 834 | free (rcsdir); |
| 835 | return (0); |
| 836 | } |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | static int |
| 843 | build_entry (repository, user, options, message, entries, tag) |
| 844 | char *repository; |
| 845 | char *user; |
| 846 | char *options; |
| 847 | char *message; |
| 848 | List *entries; |
| 849 | char *tag; |
| 850 | { |
| 851 | char *fname; |
| 852 | char *line; |
| 853 | FILE *fp; |
| 854 | |
| 855 | if (noexec) |
| 856 | return (0); |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | fname = xmalloc (strlen (user) + 80); |
| 864 | (void) sprintf (fname, "%s/%s%s", CVSADM, user, CVSEXT_LOG); |
| 865 | fp = open_file (fname, "w+"); |
| 866 | if (message && fputs (message, fp) == EOF) |
| 867 | error (1, errno, "cannot write to %s", fname); |
| 868 | if (fclose(fp) == EOF) |
| 869 | error(1, errno, "cannot close %s", fname); |
| 870 | free (fname); |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | line = xmalloc (strlen (user) + 20); |
| 878 | (void) sprintf (line, "Initial %s", user); |
| 879 | Register (entries, user, "0", line, options, tag, (char *) 0, (char *) 0); |
| 880 | free (line); |
| 881 | return (0); |
| 882 | } |