diff options
author | Niall O'Higgins <niallo@cvs.openbsd.org> | 2005-10-10 13:20:21 +0000 |
---|---|---|
committer | Niall O'Higgins <niallo@cvs.openbsd.org> | 2005-10-10 13:20:21 +0000 |
commit | 31d5e78960fbe152f666d598fcee6c464b81381a (patch) | |
tree | c27e4b514b8bd96c263d46af64ced6a9d1352dab /usr.bin | |
parent | c151662310f91158b80f0d78196f66159ce21292 (diff) |
- set permissions on checked out files correctly
- support bare `-u' and `-l' options which will check out HEAD.
note that with OpenRCS you must do `co -l -- <file>' and `co -u -- <file>'
when using bare arguments because our getopt(3) is POSIX compliant.
ok joris@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rcs/co.c | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c index b0d3a81f92e..4e7e283d909 100644 --- a/usr.bin/rcs/co.c +++ b/usr.bin/rcs/co.c @@ -1,4 +1,4 @@ -/* $OpenBSD: co.c,v 1.7 2005/10/05 12:06:23 joris Exp $ */ +/* $OpenBSD: co.c,v 1.8 2005/10/10 13:20:20 niallo Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -52,6 +52,7 @@ checkout_main(int argc, char **argv) char buf[16]; char fpath[MAXPATHLEN]; char *username; + mode_t mode = 0444; lock = 0; rev = RCS_HEAD_REV; @@ -62,18 +63,18 @@ checkout_main(int argc, char **argv) exit (1); } - while ((ch = getopt(argc, argv, "l:qr:u:V")) != -1) { + while ((ch = getopt(argc, argv, "l::qr::u::V")) != -1) { switch (ch) { case 'l': if (rev != RCS_HEAD_REV) cvs_log(LP_WARN, "redefinition of revision number"); - - if ((rev = rcsnum_parse(optarg)) == NULL) { - cvs_log(LP_ERR, "bad revision number"); - exit (1); + if (optarg != NULL) { + if ((rev = rcsnum_parse(optarg)) == NULL) { + cvs_log(LP_ERR, "bad revision number"); + exit (1); + } } - lock = LOCK_LOCK; break; case 'q': @@ -83,24 +84,24 @@ checkout_main(int argc, char **argv) if (rev != RCS_HEAD_REV) cvs_log(LP_WARN, "redefinition of revision number"); - - if ((rev = rcsnum_parse(optarg)) == NULL) { - cvs_log(LP_ERR, "bad revision number"); - exit(1); + if (optarg != NULL) { + if ((rev = rcsnum_parse(optarg)) == NULL) { + cvs_log(LP_ERR, "bad revision number"); + exit (1); + } } - break; case 'u': - lock = LOCK_UNLOCK; if (rev != RCS_HEAD_REV) cvs_log(LP_WARN, "redefinition of revision number"); - - if ((rev = rcsnum_parse(optarg)) == NULL) { - cvs_log(LP_ERR, "bad revision number"); - exit (1); + if (optarg != NULL) { + if ((rev = rcsnum_parse(optarg)) == NULL) { + cvs_log(LP_ERR, "bad revision number"); + exit (1); + } } - + lock = LOCK_UNLOCK; break; case 'V': printf("%s\n", rcs_version); @@ -140,15 +141,6 @@ checkout_main(int argc, char **argv) continue; } - if (cvs_buf_write(bp, argv[i], 0644) < 0) { - cvs_log(LP_ERR, "failed to write revision to file"); - cvs_buf_free(bp); - rcs_close(file); - continue; - } - - cvs_buf_free(bp); - if (lock == LOCK_LOCK) { if (rcs_lock_add(file, username, frev) < 0) { if (rcs_errno != RCS_ERR_DUPENT) @@ -156,13 +148,23 @@ checkout_main(int argc, char **argv) else cvs_log(LP_WARN, "you already have a lock"); } - } else if (lock == LOCK_UNLOCK) { + mode = 0644; + } else if (lock == LOCK_UNLOCK) { if (rcs_lock_remove(file, frev) < 0) { if (rcs_errno != RCS_ERR_NOENT) cvs_log(LP_ERR, "failed to remove lock '%s'", buf); } + mode = 0444; } + if (cvs_buf_write(bp, argv[i], mode) < 0) { + cvs_log(LP_ERR, "failed to write revision to file"); + cvs_buf_free(bp); + rcs_close(file); + continue; + } + + cvs_buf_free(bp); rcs_close(file); if (verbose) { |