From owner-p4-projects@FreeBSD.ORG Sun Jul 10 06:55:20 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3D0CE16A420; Sun, 10 Jul 2005 06:55:20 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F28D916A41C for ; Sun, 10 Jul 2005 06:55:19 +0000 (GMT) (envelope-from soc-cjones@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id B19CD43D46 for ; Sun, 10 Jul 2005 06:55:19 +0000 (GMT) (envelope-from soc-cjones@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j6A6tJ5j034885 for ; Sun, 10 Jul 2005 06:55:19 GMT (envelope-from soc-cjones@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6A6tJQl034882 for perforce@freebsd.org; Sun, 10 Jul 2005 06:55:19 GMT (envelope-from soc-cjones@freebsd.org) Date: Sun, 10 Jul 2005 06:55:19 GMT Message-Id: <200507100655.j6A6tJQl034882@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-cjones@freebsd.org using -f From: soc-cjones To: Perforce Change Reviews Cc: Subject: PERFORCE change 79897 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jul 2005 06:55:21 -0000 http://perforce.freebsd.org/chv.cgi?CH=79897 Change 79897 by soc-cjones@soc-cjones_ides on 2005/07/10 06:54:19 Userland for 'rename', plus simplification of error handling for 'move'. Affected files ... .. //depot/projects/soc2005/gvinum/src/sbin/gvinum/gvinum.c#4 edit Differences ... ==== //depot/projects/soc2005/gvinum/src/sbin/gvinum/gvinum.c#4 (text+ko) ==== @@ -617,10 +617,10 @@ optreset = 1; optind = 1; cmd = argv[0]; - while ((j = getopt(argc, argv, "r")) != -1) { + while ((j = getopt(argc, argv, "f")) != -1) { switch (j) { - case 'r': - flags |= GV_FLAG_R; + case 'f': + flags |= GV_FLAG_F; break; case '?': default: @@ -631,6 +631,17 @@ argv += optind; } + switch (argc) { + case 0: + warnx("no destination or object(s) to move specified"); + return; + case 1: + warnx("no object(s) to move specified"); + return; + default: + break; + } + req = gctl_get_handle(); gctl_ro_param(req, "class", -1, "VINUM"); gctl_ro_param(req, "verb", -1, "move"); @@ -641,26 +652,14 @@ for (i = 0; i < argc; i++) { snprintf(buf, sizeof(buf), "argv%d", i); gctl_ro_param(req, buf, -1, argv[i]); + if (i > 1) { /* argv[1..$] are objects to move */ + snprintf(buf, sizeof(buf), "object%d", i - 1); + gctl_ro_param(req, buf, -1, argv[i]); + } } - } else { - warnx("no destination or object(s) to move specified"); - gctl_free(req); - return; } - /* We incremented argv such that the 0th argument is - the destination, and arguments 1..$ are the objects. */ gctl_ro_param(req, "destination", -1, argv[0]); - if (argc > 1) { - for (i = 1; i < argc; i++) { - snprintf(buf, sizeof(buf), "object%d", i - 1); - gctl_ro_param(req, buf, -1, argv[i]); - } - } else { /* There isn't at least one object specified! */ - warnx("no object(s) to move specified"); - gctl_free(req); - return; - } errstr = gctl_issue(req); if (errstr != NULL) { warnx("can't move object(s): %s", errstr); @@ -763,7 +762,68 @@ void gvinum_rename(int argc, char **argv) { - /* NOP */ + struct gctl_req *req; + int flags = 0, i, j; + const char *errstr; + char buf[20], *cmd; + + if (argc) { + optreset = 1; + optind = 1; + cmd = argv[0]; + while ((j = getopt(argc, argv, "r")) != -1) { + switch (j) { + case 'r': + flags |= GV_FLAG_R; + break; + case '?': + default: + return; + } + } + argc -= optind; + argv += optind; + } + + switch (argc) { + case 0: + warnx("no object to rename specified"); + return; + case 1: + warnx("no new name specified"); + return; + case 2: + break; + default: + warnx("more than one new name specified"); + return; + } + + req = gctl_get_handle(); + gctl_ro_param(req, "class", -1, "VINUM"); + gctl_ro_param(req, "verb", -1, "move"); + gctl_ro_param(req, "cmd", -1, cmd); + gctl_ro_param(req, "argc", sizeof(int), &argc); + gctl_ro_param(req, "flags", sizeof(int), &flags); + + if (argc) { + for (i = 0; i < argc; i++) { + snprintf(buf, sizeof(buf), "argv%d", i); + gctl_ro_param(req, buf, -1, argv[i]); + } + } + + gctl_ro_param(req, "object", -1, argv[0]); + gctl_ro_param(req, "newname", -1, argv[1]); + + errstr = gctl_issue(req); + if (errstr != NULL) { + warnx("can't rename object: %s", errstr); + gctl_free(req); + return; + } + gctl_free(req); + return; } void