Date: Sun, 12 Jul 1998 18:55:03 -0500 (CDT) From: Joel Ray Holveck <detlev!joelh@mail.camalott.com> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/7265: [patch] Improvement of ln(1) Message-ID: <199807122355.SAA03409@detlev.UUCP>
next in thread | raw e-mail | index | archive | help
>Number: 7265 >Category: bin >Synopsis: A warning flag is added to ln(1). >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Jul 12 17:00:01 PDT 1998 >Last-Modified: >Originator: Joel Ray Holveck >Organization: Little to none. >Release: FreeBSD 3.0-CURRENT i386 >Environment: June 28 3.0-current. >Description: It is easy at 4:00 AM to give, to ln -s, a target relative to the current path rather than the source's path. (source and target are here used as in the source, ie, the source and target of the eventual resulting symlink.) No facilities are provided to allow for warnings. (For more information, please see the flamefest^H^H^H^H^H^H^H^H^H^H thread in freebsd-current entitled 'Improvemnet of ln(1).' Note that the fix proposed here is markedly different than what was originally proposed by the originator of said thread, as well as my own proposal.) >How-To-Repeat: # cd /usr # ln -s src/sys /sys # cd /sys /sys: No such file or directory. (Emit the anguished wails of a tired sysadmin who thinks he's just lost his kernel source. Repeating this last step is optional.) >Fix: A new flag, -w, is proposed. If the symlink created would be invalid, and the -w flag is specified, a warning is emitted to stderr. ----- cut here ----- *** ln.1-orig Sun Jul 12 18:02:09 1998 --- ln.1 Sun Jul 12 18:36:43 1998 *************** *** 72,77 **** --- 72,79 ---- Unlink any already existing file, permitting the link to occur. .It Fl s Create a symbolic link. + .It Fl w + Warn if the target of a symbolic link does not currently exist. .El .Pp By default *** ln.c-orig Sun Jul 12 18:02:06 1998 --- ln.c Sun Jul 12 18:42:42 1998 *************** *** 57,62 **** --- 57,63 ---- int fflag; /* Unlink existing files. */ int sflag; /* Symbolic, not hard, link. */ + int wflag; /* Warn if dest does not exist. */ /* System link call. */ int (*linkf) __P((const char *, const char *)); *************** *** 73,79 **** int ch, exitval; char *sourcedir; ! while ((ch = getopt(argc, argv, "fs")) != -1) switch (ch) { case 'f': fflag = 1; --- 74,80 ---- int ch, exitval; char *sourcedir; ! while ((ch = getopt(argc, argv, "fsw")) != -1) switch (ch) { case 'f': fflag = 1; *************** *** 81,86 **** --- 82,90 ---- case 's': sflag = 1; break; + case 'w': + wflag = 1; + break; case '?': default: usage(); *************** *** 117,123 **** { struct stat sb; int exists; ! char *p, path[MAXPATHLEN]; if (!sflag) { /* If target doesn't exist, quit now. */ --- 121,127 ---- { struct stat sb; int exists; ! char *p, path[MAXPATHLEN], *st, wbuf[MAXPATHLEN]; if (!sflag) { /* If target doesn't exist, quit now. */ *************** *** 146,151 **** --- 150,183 ---- exists = !lstat(source, &sb); /* + * If the target doesn't exist, and a symbolic link was + * requested, and -w was specified, give a warning. + */ + if (sflag && wflag) { + if (*target == '/') + /* Absolute target */ + st = target; + else { + /* Relative target */ + st = strdup(source); + if (!st) { + warnx("-w: Cannot allocate memory (continuing)"); + goto nowarn; + } + p = strrchr(st, '/'); + * (p ? p+1 : st) = '\0'; + (void)snprintf(wbuf, sizeof(wbuf), "%s%s", st, + target); + free(st); + st = wbuf; + } + if (stat(st, &sb)) + warn("warning: %s inaccessible relative to %s", + target, source); + } + nowarn: + + /* * If the file exists, and -f was specified, unlink it. * Attempt the link. */ *************** *** 160,166 **** usage() { (void)fprintf(stderr, "%s\n%s\n", ! "usage: ln [-fs] file1 file2", ! " ln [-fs] file ... directory"); exit(1); } --- 192,198 ---- usage() { (void)fprintf(stderr, "%s\n%s\n", ! "usage: ln [-fsw] file1 file2", ! " ln [-fsw] file ... directory"); exit(1); } ----- cut here ----- >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199807122355.SAA03409>