sbcl 确定符号是否 link

sbcl determine if symbolic link

如何测试路径名是否是 sbcl 中的符号链接?

CL-USER> (apropos "syml" )
:CLASSIFY-SYMLINKS (bound)
:RESOLVE-SYMLINKS (bound)
:SYMLINK (bound)
SB-IMPL::CLASSIFY-SYMLINKS
SB-IMPL::RESOLVE-PROBLEMATIC-SYMLINK
SB-IMPL::RESOLVE-SYMLINKS
SB-POSIX:SYMLINK (fbound)
UIOP/FILESYSTEM:*RESOLVE-SYMLINKS* (bound)
UIOP/FILESYSTEM:RESOLVE-SYMLINKS (fbound)
UIOP/FILESYSTEM:RESOLVE-SYMLINKS* (fbound)
UTIL::CLASSIFY-SYMLINKS
UTIL::SYMLINK
; No value

None 这些看起来很有用。 classify-symlinks 似乎是一个关键字。

TL;DR

(defun symlinkp (pathname)
  (sb-posix:s-islnk (sb-posix:stat-mode (sb-posix:lstat pathname))))

要回答必须首先问的问题,如何确定某物(我假设是文件描述符)是否是 posix 中的符号链接。 man 2 stat 来拯救。来自手册页

  • lstat() is identical to stat(), except that if path is asymbolic link, then the link itself is stat-ed, not the file that it refers to.

  • The following POSIX macros are defined to check the file type using the st_mode field:

  • S_ISLNK(m) symbolic link? (Not in POSIX.1-1996.)

osicat有函数file-kind可以检测符号链接:

(ql:quickload "osicat")

(equalp :symbolic-link (osicat:file-kind "/some/path"))

更新:此功能有问题,如果您使用 "/some/path/" 则无法使用。 (注意结尾的斜杠。)