From 90b967c8d37dcb7d47010d2e4cac24e783e142fe Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 18 Mar 2022 18:20:35 -0700 Subject: [PATCH] Implement DELFILE for (empty) directories on the {unix} device (#409) If the argument to DELFILE represents a directory on the {unix} device either directly or through resolving to a full pathname via the connected host/directory, and the directory is empty, then the directory will be deleted and the deleted directory name will be returned. Will error if the directory is not empty, and return NIL if the argument does not name a directory or file. --- src/ufs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ufs.c b/src/ufs.c index 766c3d6..a701a12 100644 --- a/src/ufs.c +++ b/src/ufs.c @@ -244,6 +244,7 @@ LispPTR UFS_getfilename(LispPTR *args) LispPTR UFS_deletefile(LispPTR *args) { char file[MAXPATHLEN], fbuf[MAXPATHLEN]; + struct stat sbuf; register int len, rval; ERRSETJMP(NIL); @@ -260,11 +261,21 @@ LispPTR UFS_deletefile(LispPTR *args) #else if (unixpathname(fbuf, file, 0, 0) == 0) return (NIL); #endif /* DOS */ - + /* check if we're operating on directory or file */ + TIMEOUT(rval = stat(file, &sbuf)); + if (rval == -1) { + *Lisp_errno = errno; + return (NIL); + } /* - * On UNIX device, all we have to do is just to unlink the file. + * On UNIX device, all we have to do is just to unlink the file + * or directory */ - TIMEOUT(rval = unlink(file)); + if ((sbuf.st_mode & S_IFMT) == S_IFDIR) { + TIMEOUT(rval = rmdir(file)); + } else { + TIMEOUT(rval = unlink(file)); + } if (rval == -1) { *Lisp_errno = errno; return (NIL);