directories: don't break on broken symlinks
authorDaniel Kochmański <daniel@turtleware.eu>
Fri, 18 Sep 2015 16:18:06 +0000 (18:18 +0200)
committerDaniel Kochmański <daniel@turtleware.eu>
Fri, 18 Sep 2015 16:18:06 +0000 (18:18 +0200)
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 <daniel@turtleware.eu>
src/c/unixfsys.d

index 2fef60e..36e6fd4 100644 (file)
@@ -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,