In dired mode, if you try to copy a file without giving the new path a file name, similar to:
cp /xdir/ydir/filname /xdir/ mg fails silently and doesn't copy the file into 'xdir' by using the existing filename as the copied filename. This diff uses the existing filename as the new filename if none is specified. Comments/ok? Mark Index: dired.c =================================================================== RCS file: /cvs/src/usr.bin/mg/dired.c,v retrieving revision 1.85 diff -u -p -u -p -r1.85 dired.c --- dired.c 25 Jun 2019 13:51:47 -0000 1.85 +++ dired.c 25 Jun 2019 15:22:19 -0000 @@ -445,6 +445,7 @@ d_expunge(int f, int n) int d_copy(int f, int n) { + struct stat statbuf; char frname[NFILEN], toname[NFILEN], sname[NFILEN]; char *topath, *bufp; int ret; @@ -471,6 +472,18 @@ d_copy(int f, int n) return (FALSE); topath = adjustname(toname, TRUE); + if (stat(topath, &statbuf) == 0) { + if (S_ISDIR(statbuf.st_mode)) { + off = snprintf(toname, sizeof(toname), "%s/%s", + topath, sname); + if (off < 0 || off >= sizeof(toname) - 1) { + dobeep(); + ewprintf("Directory name too long"); + return (FALSE); + } + topath = adjustname(toname, TRUE); + } + } ret = (copy(frname, topath) >= 0) ? TRUE : FALSE; if (ret != TRUE) return (ret);