From 558f7e76cc334e85bc30bf5dd9b62fa8038832ef Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 27 Jan 2020 06:04:25 -0800 Subject: ensure-dir: return nil when exists. * sysif.c (mkdir_nothrow_exists): Return nil in the existence case, when the object is a directory or a symlink to one. * txr.1: Updated. --- sysif.c | 3 ++- txr.1 | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sysif.c b/sysif.c index 369f1890..a12d625f 100644 --- a/sysif.c +++ b/sysif.c @@ -339,6 +339,7 @@ static val mkdir_nothrow_exists(val path, val mode) ret = num(errno); break; case EEXIST: + ret = nil; #if HAVE_SYS_STAT { struct stat st; @@ -384,7 +385,7 @@ static val ensure_dir(val path, val mode) partial_path, sep, pop(&split_path), nao); } - if (ret != t) { + if (integerp(ret)) { int eno = c_num(ret); uw_throwf(errno_to_file_error(eno), lit("ensure-dir: ~a: ~d/~s"), path, ret, diff --git a/txr.1 b/txr.1 index ebee463c..bcbc1520 100644 --- a/txr.1 +++ b/txr.1 @@ -57494,13 +57494,18 @@ are subject to the system The function .code ensure-dir -is similar to -.code mkdir -except that it attempts to create all the missing parent directories -as necessary, and does not throw an error if +also creates a directory named +.metn path . +Unlike +.codn mkdir , +it also attempt to create all the necessary parent directories, +and does not throw an error if .meta path refers to an existing object, if that object is a directory or a symbolic -link to a directory. +link to a directory. Rather, in that case it returns +.code nil +instead of +.codn t . .coNP Function @ chdir .synb -- cgit v1.2.3