• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
      • Io
      • Defttag
      • Sys-call
      • Save-exec
      • Quicklisp
      • Oslib
        • File-types
          • File-kind
          • Regular-files
          • Existing-paths
          • Missing-paths
          • Directories
          • Path-exists-p
          • Regular-file-p
          • Directory-p
          • Regular-files-p
          • Paths-all-missing-p
          • Paths-all-exist-p
          • Directories-p
          • Regular-files-exec
          • File-kind-p
          • Existing-paths-exec
          • Missing-paths-exec
          • Directories-exec
        • Argv
        • Copy
        • Catpath
        • Universal-time
        • Ls
        • Basename
        • Tempfile
        • Dirname
        • Copy!
        • Mkdir
        • Ls-files
        • Lisp-version
        • Rmtree
        • Ls-subdirs
        • Lisp-type
        • Date
        • Getpid
        • Basenames
        • Dirnames
        • Ls-subdirs!
        • Ls-files!
        • Dirname!
        • Basename!
        • Catpaths
        • Mkdir!
        • Ls!
        • Rmtree!
        • Remove-nonstrings
      • Std/io
      • Bridge
      • Clex
      • Tshell
      • Unsound-eval
      • Hacker
      • Startup-banner
      • Command-line
    • Hardware-verification
    • Software-verification
    • Testing-utilities
    • Math
  • Oslib

File-types

Functions for working with file types, e.g., regular files versus directories, devices, etc.

Many of these functions are just ACL2 wrappers for the Common Lisp Osicat library. Unlike the more basic file reading/writing operations (see ACL2::std/io), there is no complex logical story for reasoning about these operations. Instead, in the logic, practically everything here is just reading the oracle.

As a general rule, these functions are not entirely portable, especially regarding special characters like ~, .., \, * in path names. Paths containing these things will certainly not behave in the same way across different operating systems, and for that matter they may not even behave the same way on the same operating system, but in different Lisps. There's not much to be done for this, as the root causes are the lack of standards among file systems and Common Lisp implementations.

Some possibly helpful reading about file systems in general and in Lisp:

  • David A. Wheeler. Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems.
  • Peter Seibel's Practical Common Lisp, especially the chapters on Files and File I/O and Practical: A Portable Pathname Library.
  • The Common Lisp Hyperspec, especially the chapters on file names and files.
  • The CL-FAD (Common Lisp Files and Directories) library is perhaps similar to osicat, but doesn't seem to have any support for querying what type of file you're looking at, etc., so we don't currently use it.

Future work

BOZO I would really like to have tests like -r, -w, and -x in Perl/Bash. It looks like osicat gives me a way to access the permissions of a file, but these seem like just the rwx bits from the "stat" structure, and I don't think that's actually tells us anything useful, unless the file happens to be owned by us---at least, not without some way to figure out what groups our user is in, etc.

The source code for Gnu's "test" utility (from coreutils) invokes the EUIDACCESS system call to figure out whether the argument is readable, writable, or executable. So that'd probably be the nicest thing to use. So maybe we could rig something up with CFFI to invoke that, but I am in way over my head here, and even if we did that, it'd probably just be a solution for Linux. Who knows how Windows or FreeBSD or Darwin or anything else do it.

Subtopics

File-kind
See what kind of file a path refers to.
Regular-files
Collect paths that are regular files.
Existing-paths
Collect paths that exist.
Missing-paths
Collect paths that do not exist.
Directories
Collect paths that are directories.
Path-exists-p
Does a path exist? After following symlinks, does it refer to any "file" at all (a regular file, a directory, a device, ...)?
Regular-file-p
Does a path, after following symlinks, refer to an existing, regular file—not to a directory, device, etc.
Directory-p
Does a path, after following symlinks, refer to a directory?
Regular-files-p
Are all of these paths regular files?
Paths-all-missing-p
Do none of these paths exist?
Paths-all-exist-p
Do all of these paths exist?
Directories-p
Are all of these paths directories?
Regular-files-exec
File-kind-p
Possible return values from file-kind.
Existing-paths-exec
Missing-paths-exec
Directories-exec