staticos.nim 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ## This module implements path handling like os module but works at only compile-time.
  2. ## This module works even when cross compiling to OS that is not supported by os module.
  3. when defined(nimPreviewSlimSystem):
  4. import std/assertions
  5. proc staticFileExists*(filename: string): bool {.compileTime.} =
  6. ## Returns true if `filename` exists and is a regular file or symlink.
  7. ##
  8. ## Directories, device files, named pipes and sockets return false.
  9. raiseAssert "implemented in the vmops"
  10. proc staticDirExists*(dir: string): bool {.compileTime.} =
  11. ## Returns true if the directory `dir` exists. If `dir` is a file, false
  12. ## is returned. Follows symlinks.
  13. raiseAssert "implemented in the vmops"
  14. type
  15. PathComponent* = enum ## Enumeration specifying a path component.
  16. ##
  17. ## See also:
  18. ## * `walkDirRec iterator`_
  19. ## * `FileInfo object`_
  20. pcFile, ## path refers to a file
  21. pcLinkToFile, ## path refers to a symbolic link to a file
  22. pcDir, ## path refers to a directory
  23. pcLinkToDir ## path refers to a symbolic link to a directory
  24. proc staticWalkDir*(dir: string; relative = false): seq[
  25. tuple[kind: PathComponent, path: string]] {.compileTime.} =
  26. ## Walks over the directory `dir` and returns a seq with each directory or
  27. ## file in `dir`. The component type and full path for each item are returned.
  28. ##
  29. ## Walking is not recursive.
  30. ## * If `relative` is true (default: false)
  31. ## the resulting path is shortened to be relative to ``dir``,
  32. ## otherwise the full path is returned.
  33. raiseAssert "implemented in the vmops"