From 22b647144c295fef6cb4f1ef24aa5205c2b5a6a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kochma=C5=84ski?= Date: Fri, 18 Sep 2015 18:18:06 +0200 Subject: [PATCH] directories: don't break on broken symlinks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ECL when asked for a truename of a broken symbolic link signalled an `file-error'. This isn't non-conformity, because spec doesn't specify such situation, but lead to annoying errors with DIRECTORIES when even irrelevant files were broken symlinks. New behavior is as follows - broken symlinks are treated as regular files (of :LINK kind) and no error is signalled. They aren't ignored due to a few corner cases related to PROBE-FILE, OPEN and such. Signed-off-by: Daniel Kochmański --- src/c/unixfsys.d | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/c/unixfsys.d b/src/c/unixfsys.d index 2fef60e..36e6fd4 100644 --- a/src/c/unixfsys.d +++ b/src/c/unixfsys.d @@ -361,8 +361,13 @@ file_truename(cl_object pathname, cl_object filename, int flags) FEcannot_open(filename); #ifdef HAVE_LSTAT } else if (kind == @':link' && (flags & FOLLOW_SYMLINKS)) { - /* The link might be a relative pathname. In that case we have - * to merge with the original pathname */ + /* The link might be a relative pathname. In that case + * we have to merge with the original pathname. On + * the other hand, if the link is broken – return file + * truename "as is". */ + struct stat filestatus; + if (safe_stat(filename->base_string.self, &filestatus) < 0) + @(return pathname kind); filename = si_readlink(filename); pathname = ecl_make_pathname(pathname->pathname.host, pathname->pathname.device, -- 2.9.0