* fix #14142: no more clash with: import os + use of existsDir/dirExists/existsFile/fileExists/findExe in config.nims * remove a comment * Revert "fixes the regression #12860 caused; hotfix" This reverts commit3d2459bdc0. * Revert "Undefine `paramCount` & `paramStr` in nimscript.nim for *.nims (#12860)" This reverts commitd38853c504. * noNimScript => noWeirdTarget + noNimJs
This commit is contained in:
parent
7b12f13946
commit
45cac4afda
5 changed files with 81 additions and 79 deletions
|
|
@ -62,7 +62,6 @@
|
||||||
|
|
||||||
- Added high-level `asyncnet.sendTo` and `asyncnet.recvFrom`. UDP functionality.
|
- Added high-level `asyncnet.sendTo` and `asyncnet.recvFrom`. UDP functionality.
|
||||||
|
|
||||||
- `paramCount` & `paramStr` are now defined in os.nim instead of nimscript.nim for nimscript/nimble.
|
|
||||||
- `dollars.$` now works for unsigned ints with `nim js`
|
- `dollars.$` now works for unsigned ints with `nim js`
|
||||||
|
|
||||||
- Improvements to the `bitops` module, including bitslices, non-mutating versions
|
- Improvements to the `bitops` module, including bitslices, non-mutating versions
|
||||||
|
|
|
||||||
|
|
@ -141,12 +141,10 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string;
|
||||||
setResult(a, options.existsConfigVar(conf, a.getString 0))
|
setResult(a, options.existsConfigVar(conf, a.getString 0))
|
||||||
cbconf nimcacheDir:
|
cbconf nimcacheDir:
|
||||||
setResult(a, options.getNimcacheDir(conf).string)
|
setResult(a, options.getNimcacheDir(conf).string)
|
||||||
result.registerCallback "stdlib.os." & astToStr(paramStr),
|
cbconf paramStr:
|
||||||
proc (a: VmArgs) =
|
setResult(a, os.paramStr(int a.getInt 0))
|
||||||
setResult(a, os.paramStr(int a.getInt 0))
|
cbconf paramCount:
|
||||||
result.registerCallback "stdlib.os." & astToStr(paramCount),
|
setResult(a, os.paramCount())
|
||||||
proc (a: VmArgs) =
|
|
||||||
setResult(a, os.paramCount())
|
|
||||||
cbconf cmpIgnoreStyle:
|
cbconf cmpIgnoreStyle:
|
||||||
setResult(a, strutils.cmpIgnoreStyle(a.getString 0, a.getString 1))
|
setResult(a, strutils.cmpIgnoreStyle(a.getString 0, a.getString 1))
|
||||||
cbconf cmpIgnoreCase:
|
cbconf cmpIgnoreCase:
|
||||||
|
|
|
||||||
131
lib/pure/os.nim
131
lib/pure/os.nim
|
|
@ -76,9 +76,17 @@ else:
|
||||||
{.error: "OS module not ported to your operating system!".}
|
{.error: "OS module not ported to your operating system!".}
|
||||||
|
|
||||||
when weirdTarget and defined(nimErrorProcCanHaveBody):
|
when weirdTarget and defined(nimErrorProcCanHaveBody):
|
||||||
{.pragma: noNimScript, error: "this proc is not available on the NimScript target".}
|
{.pragma: noWeirdTarget, error: "this proc is not available on the NimScript/js target".}
|
||||||
else:
|
else:
|
||||||
{.pragma: noNimScript.}
|
{.pragma: noWeirdTarget.}
|
||||||
|
|
||||||
|
when defined(nimscript):
|
||||||
|
# for procs already defined in scriptconfig.nim
|
||||||
|
template noNimJs(body): untyped = discard
|
||||||
|
elif defined(js):
|
||||||
|
{.pragma: noNimJs, error: "this proc is not available on the js target".}
|
||||||
|
else:
|
||||||
|
{.pragma: noNimJs.}
|
||||||
|
|
||||||
proc normalizePathAux(path: var string){.inline, raises: [], noSideEffect.}
|
proc normalizePathAux(path: var string){.inline, raises: [], noSideEffect.}
|
||||||
|
|
||||||
|
|
@ -1088,7 +1096,7 @@ when defined(windows) and not weirdTarget:
|
||||||
f.cFileName[1].int == dot and f.cFileName[2].int == 0)
|
f.cFileName[1].int == dot and f.cFileName[2].int == 0)
|
||||||
|
|
||||||
proc existsFile*(filename: string): bool {.rtl, extern: "nos$1",
|
proc existsFile*(filename: string): bool {.rtl, extern: "nos$1",
|
||||||
tags: [ReadDirEffect], noNimScript.} =
|
tags: [ReadDirEffect], noNimJs.} =
|
||||||
## Returns true if `filename` exists and is a regular file or symlink.
|
## Returns true if `filename` exists and is a regular file or symlink.
|
||||||
##
|
##
|
||||||
## Directories, device files, named pipes and sockets return false.
|
## Directories, device files, named pipes and sockets return false.
|
||||||
|
|
@ -1108,7 +1116,7 @@ proc existsFile*(filename: string): bool {.rtl, extern: "nos$1",
|
||||||
return stat(filename, res) >= 0'i32 and S_ISREG(res.st_mode)
|
return stat(filename, res) >= 0'i32 and S_ISREG(res.st_mode)
|
||||||
|
|
||||||
proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect],
|
proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect],
|
||||||
noNimScript.} =
|
noNimJs.} =
|
||||||
## Returns true if the directory `dir` exists. If `dir` is a file, false
|
## Returns true if the directory `dir` exists. If `dir` is a file, false
|
||||||
## is returned. Follows symlinks.
|
## is returned. Follows symlinks.
|
||||||
##
|
##
|
||||||
|
|
@ -1128,7 +1136,7 @@ proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect]
|
||||||
|
|
||||||
proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
|
proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
|
||||||
tags: [ReadDirEffect],
|
tags: [ReadDirEffect],
|
||||||
noNimScript.} =
|
noWeirdTarget.} =
|
||||||
## Returns true if the symlink `link` exists. Will return true
|
## Returns true if the symlink `link` exists. Will return true
|
||||||
## regardless of whether the link points to a directory or file.
|
## regardless of whether the link points to a directory or file.
|
||||||
##
|
##
|
||||||
|
|
@ -1146,7 +1154,7 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
|
||||||
var res: Stat
|
var res: Stat
|
||||||
return lstat(link, res) >= 0'i32 and S_ISLNK(res.st_mode)
|
return lstat(link, res) >= 0'i32 and S_ISLNK(res.st_mode)
|
||||||
|
|
||||||
proc fileExists*(filename: string): bool {.inline, noNimScript.} =
|
proc fileExists*(filename: string): bool {.inline, noNimJs.} =
|
||||||
## Alias for `existsFile proc <#existsFile,string>`_.
|
## Alias for `existsFile proc <#existsFile,string>`_.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
@ -1154,7 +1162,7 @@ proc fileExists*(filename: string): bool {.inline, noNimScript.} =
|
||||||
## * `symlinkExists proc <#symlinkExists,string>`_
|
## * `symlinkExists proc <#symlinkExists,string>`_
|
||||||
existsFile(filename)
|
existsFile(filename)
|
||||||
|
|
||||||
proc dirExists*(dir: string): bool {.inline, noNimScript.} =
|
proc dirExists*(dir: string): bool {.inline, noNimJs.} =
|
||||||
## Alias for `existsDir proc <#existsDir,string>`_.
|
## Alias for `existsDir proc <#existsDir,string>`_.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
@ -1175,7 +1183,7 @@ const
|
||||||
|
|
||||||
proc findExe*(exe: string, followSymlinks: bool = true;
|
proc findExe*(exe: string, followSymlinks: bool = true;
|
||||||
extensions: openArray[string]=ExeExts): string {.
|
extensions: openArray[string]=ExeExts): string {.
|
||||||
tags: [ReadDirEffect, ReadEnvEffect, ReadIOEffect], noNimScript.} =
|
tags: [ReadDirEffect, ReadEnvEffect, ReadIOEffect], noNimJs.} =
|
||||||
## Searches for `exe` in the current working directory and then
|
## Searches for `exe` in the current working directory and then
|
||||||
## in directories listed in the ``PATH`` environment variable.
|
## in directories listed in the ``PATH`` environment variable.
|
||||||
##
|
##
|
||||||
|
|
@ -1231,7 +1239,7 @@ when weirdTarget:
|
||||||
const times = "fake const"
|
const times = "fake const"
|
||||||
template Time(x: untyped): untyped = string
|
template Time(x: untyped): untyped = string
|
||||||
|
|
||||||
proc getLastModificationTime*(file: string): times.Time {.rtl, extern: "nos$1", noNimScript.} =
|
proc getLastModificationTime*(file: string): times.Time {.rtl, extern: "nos$1", noWeirdTarget.} =
|
||||||
## Returns the `file`'s last modification time.
|
## Returns the `file`'s last modification time.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
@ -1249,7 +1257,7 @@ proc getLastModificationTime*(file: string): times.Time {.rtl, extern: "nos$1",
|
||||||
result = fromWinTime(rdFileTime(f.ftLastWriteTime))
|
result = fromWinTime(rdFileTime(f.ftLastWriteTime))
|
||||||
findClose(h)
|
findClose(h)
|
||||||
|
|
||||||
proc getLastAccessTime*(file: string): times.Time {.rtl, extern: "nos$1", noNimScript.} =
|
proc getLastAccessTime*(file: string): times.Time {.rtl, extern: "nos$1", noWeirdTarget.} =
|
||||||
## Returns the `file`'s last read or write access time.
|
## Returns the `file`'s last read or write access time.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
@ -1267,7 +1275,7 @@ proc getLastAccessTime*(file: string): times.Time {.rtl, extern: "nos$1", noNimS
|
||||||
result = fromWinTime(rdFileTime(f.ftLastAccessTime))
|
result = fromWinTime(rdFileTime(f.ftLastAccessTime))
|
||||||
findClose(h)
|
findClose(h)
|
||||||
|
|
||||||
proc getCreationTime*(file: string): times.Time {.rtl, extern: "nos$1", noNimScript.} =
|
proc getCreationTime*(file: string): times.Time {.rtl, extern: "nos$1", noWeirdTarget.} =
|
||||||
## Returns the `file`'s creation time.
|
## Returns the `file`'s creation time.
|
||||||
##
|
##
|
||||||
## **Note:** Under POSIX OS's, the returned time may actually be the time at
|
## **Note:** Under POSIX OS's, the returned time may actually be the time at
|
||||||
|
|
@ -1289,7 +1297,7 @@ proc getCreationTime*(file: string): times.Time {.rtl, extern: "nos$1", noNimScr
|
||||||
result = fromWinTime(rdFileTime(f.ftCreationTime))
|
result = fromWinTime(rdFileTime(f.ftCreationTime))
|
||||||
findClose(h)
|
findClose(h)
|
||||||
|
|
||||||
proc fileNewer*(a, b: string): bool {.rtl, extern: "nos$1", noNimScript.} =
|
proc fileNewer*(a, b: string): bool {.rtl, extern: "nos$1", noWeirdTarget.} =
|
||||||
## Returns true if the file `a` is newer than file `b`, i.e. if `a`'s
|
## Returns true if the file `a` is newer than file `b`, i.e. if `a`'s
|
||||||
## modification time is later than `b`'s.
|
## modification time is later than `b`'s.
|
||||||
##
|
##
|
||||||
|
|
@ -1368,7 +1376,7 @@ when not defined(nimscript):
|
||||||
else:
|
else:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
||||||
proc setCurrentDir*(newDir: string) {.inline, tags: [], noNimScript.} =
|
proc setCurrentDir*(newDir: string) {.inline, tags: [], noWeirdTarget.} =
|
||||||
## Sets the `current working directory`:idx:; `OSError`
|
## Sets the `current working directory`:idx:; `OSError`
|
||||||
## is raised if `newDir` cannot been set.
|
## is raised if `newDir` cannot been set.
|
||||||
##
|
##
|
||||||
|
|
@ -1502,7 +1510,7 @@ when defined(Windows) and not weirdTarget:
|
||||||
)
|
)
|
||||||
|
|
||||||
proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||||
tags: [ReadDirEffect], noNimScript.} =
|
tags: [ReadDirEffect], noWeirdTarget.} =
|
||||||
## Returns true if both pathname arguments refer to the same physical
|
## Returns true if both pathname arguments refer to the same physical
|
||||||
## file or directory.
|
## file or directory.
|
||||||
##
|
##
|
||||||
|
|
@ -1547,7 +1555,7 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||||
result = a.st_dev == b.st_dev and a.st_ino == b.st_ino
|
result = a.st_dev == b.st_dev and a.st_ino == b.st_ino
|
||||||
|
|
||||||
proc sameFileContent*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
proc sameFileContent*(path1, path2: string): bool {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect], noNimScript.} =
|
tags: [ReadIOEffect], noWeirdTarget.} =
|
||||||
## Returns true if both pathname arguments refer to files with identical
|
## Returns true if both pathname arguments refer to files with identical
|
||||||
## binary content.
|
## binary content.
|
||||||
##
|
##
|
||||||
|
|
@ -1598,7 +1606,7 @@ type
|
||||||
fpOthersRead ## read access for others
|
fpOthersRead ## read access for others
|
||||||
|
|
||||||
proc getFilePermissions*(filename: string): set[FilePermission] {.
|
proc getFilePermissions*(filename: string): set[FilePermission] {.
|
||||||
rtl, extern: "nos$1", tags: [ReadDirEffect], noNimScript.} =
|
rtl, extern: "nos$1", tags: [ReadDirEffect], noWeirdTarget.} =
|
||||||
## Retrieves file permissions for `filename`.
|
## Retrieves file permissions for `filename`.
|
||||||
##
|
##
|
||||||
## `OSError` is raised in case of an error.
|
## `OSError` is raised in case of an error.
|
||||||
|
|
@ -1636,7 +1644,7 @@ proc getFilePermissions*(filename: string): set[FilePermission] {.
|
||||||
result = {fpUserExec..fpOthersRead}
|
result = {fpUserExec..fpOthersRead}
|
||||||
|
|
||||||
proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
||||||
rtl, extern: "nos$1", tags: [WriteDirEffect], noNimScript.} =
|
rtl, extern: "nos$1", tags: [WriteDirEffect], noWeirdTarget.} =
|
||||||
## Sets the file permissions for `filename`.
|
## Sets the file permissions for `filename`.
|
||||||
##
|
##
|
||||||
## `OSError` is raised in case of an error.
|
## `OSError` is raised in case of an error.
|
||||||
|
|
@ -1678,7 +1686,7 @@ proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
||||||
if res2 == - 1'i32: raiseOSError(osLastError(), $(filename, permissions))
|
if res2 == - 1'i32: raiseOSError(osLastError(), $(filename, permissions))
|
||||||
|
|
||||||
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect, WriteIOEffect], noNimScript.} =
|
tags: [ReadIOEffect, WriteIOEffect], noWeirdTarget.} =
|
||||||
## Copies a file from `source` to `dest`.
|
## Copies a file from `source` to `dest`.
|
||||||
##
|
##
|
||||||
## If this fails, `OSError` is raised.
|
## If this fails, `OSError` is raised.
|
||||||
|
|
@ -1754,7 +1762,7 @@ when defined(Windows) and not weirdTarget:
|
||||||
template setFileAttributes(file, attrs: untyped): untyped =
|
template setFileAttributes(file, attrs: untyped): untyped =
|
||||||
setFileAttributesA(file, attrs)
|
setFileAttributesA(file, attrs)
|
||||||
|
|
||||||
proc tryRemoveFile*(file: string): bool {.rtl, extern: "nos$1", tags: [WriteDirEffect], noNimScript.} =
|
proc tryRemoveFile*(file: string): bool {.rtl, extern: "nos$1", tags: [WriteDirEffect], noWeirdTarget.} =
|
||||||
## Removes the `file`.
|
## Removes the `file`.
|
||||||
##
|
##
|
||||||
## If this fails, returns `false`. This does not fail
|
## If this fails, returns `false`. This does not fail
|
||||||
|
|
@ -1786,7 +1794,7 @@ proc tryRemoveFile*(file: string): bool {.rtl, extern: "nos$1", tags: [WriteDirE
|
||||||
if unlink(file) != 0'i32 and errno != ENOENT:
|
if unlink(file) != 0'i32 and errno != ENOENT:
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect], noNimScript.} =
|
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect], noWeirdTarget.} =
|
||||||
## Removes the `file`.
|
## Removes the `file`.
|
||||||
##
|
##
|
||||||
## If this fails, `OSError` is raised. This does not fail
|
## If this fails, `OSError` is raised. This does not fail
|
||||||
|
|
@ -1803,7 +1811,7 @@ proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect], n
|
||||||
if not tryRemoveFile(file):
|
if not tryRemoveFile(file):
|
||||||
raiseOSError(osLastError(), file)
|
raiseOSError(osLastError(), file)
|
||||||
|
|
||||||
proc tryMoveFSObject(source, dest: string): bool {.noNimScript.} =
|
proc tryMoveFSObject(source, dest: string): bool {.noWeirdTarget.} =
|
||||||
## Moves a file or directory from `source` to `dest`.
|
## Moves a file or directory from `source` to `dest`.
|
||||||
##
|
##
|
||||||
## Returns false in case of `EXDEV` error.
|
## Returns false in case of `EXDEV` error.
|
||||||
|
|
@ -1827,7 +1835,7 @@ proc tryMoveFSObject(source, dest: string): bool {.noNimScript.} =
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect, WriteIOEffect], noNimScript.} =
|
tags: [ReadIOEffect, WriteIOEffect], noWeirdTarget.} =
|
||||||
## Moves a file from `source` to `dest`.
|
## Moves a file from `source` to `dest`.
|
||||||
##
|
##
|
||||||
## If this fails, `OSError` is raised.
|
## If this fails, `OSError` is raised.
|
||||||
|
|
@ -1864,7 +1872,7 @@ proc exitStatusLikeShell*(status: cint): cint =
|
||||||
status
|
status
|
||||||
|
|
||||||
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
||||||
tags: [ExecIOEffect], noNimScript.} =
|
tags: [ExecIOEffect], noWeirdTarget.} =
|
||||||
## Executes a `shell command`:idx:.
|
## Executes a `shell command`:idx:.
|
||||||
##
|
##
|
||||||
## Command has the form 'program args' where args are the command
|
## Command has the form 'program args' where args are the command
|
||||||
|
|
@ -1938,7 +1946,7 @@ template walkCommon(pattern: string, filter) =
|
||||||
if filter(path):
|
if filter(path):
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
iterator walkPattern*(pattern: string): string {.tags: [ReadDirEffect], noNimScript.} =
|
iterator walkPattern*(pattern: string): string {.tags: [ReadDirEffect], noWeirdTarget.} =
|
||||||
## Iterate over all the files and directories that match the `pattern`.
|
## Iterate over all the files and directories that match the `pattern`.
|
||||||
##
|
##
|
||||||
## On POSIX this uses the `glob`:idx: call.
|
## On POSIX this uses the `glob`:idx: call.
|
||||||
|
|
@ -1952,7 +1960,7 @@ iterator walkPattern*(pattern: string): string {.tags: [ReadDirEffect], noNimScr
|
||||||
## * `walkDirRec iterator <#walkDirRec.i,string>`_
|
## * `walkDirRec iterator <#walkDirRec.i,string>`_
|
||||||
walkCommon(pattern, defaultWalkFilter)
|
walkCommon(pattern, defaultWalkFilter)
|
||||||
|
|
||||||
iterator walkFiles*(pattern: string): string {.tags: [ReadDirEffect], noNimScript.} =
|
iterator walkFiles*(pattern: string): string {.tags: [ReadDirEffect], noWeirdTarget.} =
|
||||||
## Iterate over all the files that match the `pattern`.
|
## Iterate over all the files that match the `pattern`.
|
||||||
##
|
##
|
||||||
## On POSIX this uses the `glob`:idx: call.
|
## On POSIX this uses the `glob`:idx: call.
|
||||||
|
|
@ -1966,7 +1974,7 @@ iterator walkFiles*(pattern: string): string {.tags: [ReadDirEffect], noNimScrip
|
||||||
## * `walkDirRec iterator <#walkDirRec.i,string>`_
|
## * `walkDirRec iterator <#walkDirRec.i,string>`_
|
||||||
walkCommon(pattern, isFile)
|
walkCommon(pattern, isFile)
|
||||||
|
|
||||||
iterator walkDirs*(pattern: string): string {.tags: [ReadDirEffect], noNimScript.} =
|
iterator walkDirs*(pattern: string): string {.tags: [ReadDirEffect], noWeirdTarget.} =
|
||||||
## Iterate over all the directories that match the `pattern`.
|
## Iterate over all the directories that match the `pattern`.
|
||||||
##
|
##
|
||||||
## On POSIX this uses the `glob`:idx: call.
|
## On POSIX this uses the `glob`:idx: call.
|
||||||
|
|
@ -1981,7 +1989,7 @@ iterator walkDirs*(pattern: string): string {.tags: [ReadDirEffect], noNimScript
|
||||||
walkCommon(pattern, isDir)
|
walkCommon(pattern, isDir)
|
||||||
|
|
||||||
proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||||
tags: [ReadDirEffect], noNimScript.} =
|
tags: [ReadDirEffect], noWeirdTarget.} =
|
||||||
## Returns the full (`absolute`:idx:) path of an existing file `filename`.
|
## Returns the full (`absolute`:idx:) path of an existing file `filename`.
|
||||||
##
|
##
|
||||||
## Raises `OSError` in case of an error. Follows symlinks.
|
## Raises `OSError` in case of an error. Follows symlinks.
|
||||||
|
|
@ -2215,7 +2223,7 @@ iterator walkDirRec*(dir: string,
|
||||||
# continue iteration.
|
# continue iteration.
|
||||||
# Future work can provide a way to customize this and do error reporting.
|
# Future work can provide a way to customize this and do error reporting.
|
||||||
|
|
||||||
proc rawRemoveDir(dir: string) {.noNimScript.} =
|
proc rawRemoveDir(dir: string) {.noWeirdTarget.} =
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
wrapUnary(res, removeDirectoryW, dir)
|
wrapUnary(res, removeDirectoryW, dir)
|
||||||
|
|
@ -2229,7 +2237,7 @@ proc rawRemoveDir(dir: string) {.noNimScript.} =
|
||||||
if rmdir(dir) != 0'i32 and errno != ENOENT: raiseOSError(osLastError(), dir)
|
if rmdir(dir) != 0'i32 and errno != ENOENT: raiseOSError(osLastError(), dir)
|
||||||
|
|
||||||
proc removeDir*(dir: string, checkDir = false) {.rtl, extern: "nos$1", tags: [
|
proc removeDir*(dir: string, checkDir = false) {.rtl, extern: "nos$1", tags: [
|
||||||
WriteDirEffect, ReadDirEffect], benign, noNimScript.} =
|
WriteDirEffect, ReadDirEffect], benign, noWeirdTarget.} =
|
||||||
## Removes the directory `dir` including all subdirectories and files
|
## Removes the directory `dir` including all subdirectories and files
|
||||||
## in `dir` (recursively).
|
## in `dir` (recursively).
|
||||||
##
|
##
|
||||||
|
|
@ -2253,7 +2261,7 @@ proc removeDir*(dir: string, checkDir = false) {.rtl, extern: "nos$1", tags: [
|
||||||
# the same files)
|
# the same files)
|
||||||
rawRemoveDir(dir)
|
rawRemoveDir(dir)
|
||||||
|
|
||||||
proc rawCreateDir(dir: string): bool {.noNimScript.} =
|
proc rawCreateDir(dir: string): bool {.noWeirdTarget.} =
|
||||||
# Try to create one directory (not the whole path).
|
# Try to create one directory (not the whole path).
|
||||||
# returns `true` for success, `false` if the path has previously existed
|
# returns `true` for success, `false` if the path has previously existed
|
||||||
#
|
#
|
||||||
|
|
@ -2298,7 +2306,7 @@ proc rawCreateDir(dir: string): bool {.noNimScript.} =
|
||||||
raiseOSError(osLastError(), dir)
|
raiseOSError(osLastError(), dir)
|
||||||
|
|
||||||
proc existsOrCreateDir*(dir: string): bool {.rtl, extern: "nos$1",
|
proc existsOrCreateDir*(dir: string): bool {.rtl, extern: "nos$1",
|
||||||
tags: [WriteDirEffect, ReadDirEffect], noNimScript.} =
|
tags: [WriteDirEffect, ReadDirEffect], noWeirdTarget.} =
|
||||||
## Check if a `directory`:idx: `dir` exists, and create it otherwise.
|
## Check if a `directory`:idx: `dir` exists, and create it otherwise.
|
||||||
##
|
##
|
||||||
## Does not create parent directories (fails if parent does not exist).
|
## Does not create parent directories (fails if parent does not exist).
|
||||||
|
|
@ -2318,7 +2326,7 @@ proc existsOrCreateDir*(dir: string): bool {.rtl, extern: "nos$1",
|
||||||
raise newException(IOError, "Failed to create '" & dir & "'")
|
raise newException(IOError, "Failed to create '" & dir & "'")
|
||||||
|
|
||||||
proc createDir*(dir: string) {.rtl, extern: "nos$1",
|
proc createDir*(dir: string) {.rtl, extern: "nos$1",
|
||||||
tags: [WriteDirEffect, ReadDirEffect], noNimScript.} =
|
tags: [WriteDirEffect, ReadDirEffect], noWeirdTarget.} =
|
||||||
## Creates the `directory`:idx: `dir`.
|
## Creates the `directory`:idx: `dir`.
|
||||||
##
|
##
|
||||||
## The directory may contain several subdirectories that do not exist yet.
|
## The directory may contain several subdirectories that do not exist yet.
|
||||||
|
|
@ -2349,7 +2357,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1",
|
||||||
discard existsOrCreateDir(dir)
|
discard existsOrCreateDir(dir)
|
||||||
|
|
||||||
proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
tags: [WriteIOEffect, ReadIOEffect], benign, noNimScript.} =
|
tags: [WriteIOEffect, ReadIOEffect], benign, noWeirdTarget.} =
|
||||||
## Copies a directory from `source` to `dest`.
|
## Copies a directory from `source` to `dest`.
|
||||||
##
|
##
|
||||||
## If this fails, `OSError` is raised.
|
## If this fails, `OSError` is raised.
|
||||||
|
|
@ -2380,7 +2388,7 @@ proc copyDir*(source, dest: string) {.rtl, extern: "nos$1",
|
||||||
copyDir(path, dest / noSource)
|
copyDir(path, dest / noSource)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc moveDir*(source, dest: string) {.tags: [ReadIOEffect, WriteIOEffect], noNimScript.} =
|
proc moveDir*(source, dest: string) {.tags: [ReadIOEffect, WriteIOEffect], noWeirdTarget.} =
|
||||||
## Moves a directory from `source` to `dest`.
|
## Moves a directory from `source` to `dest`.
|
||||||
##
|
##
|
||||||
## If this fails, `OSError` is raised.
|
## If this fails, `OSError` is raised.
|
||||||
|
|
@ -2398,7 +2406,7 @@ proc moveDir*(source, dest: string) {.tags: [ReadIOEffect, WriteIOEffect], noNim
|
||||||
copyDir(source, dest)
|
copyDir(source, dest)
|
||||||
removeDir(source)
|
removeDir(source)
|
||||||
|
|
||||||
proc createSymlink*(src, dest: string) {.noNimScript.} =
|
proc createSymlink*(src, dest: string) {.noWeirdTarget.} =
|
||||||
## Create a symbolic link at `dest` which points to the item specified
|
## Create a symbolic link at `dest` which points to the item specified
|
||||||
## by `src`. On most operating systems, will fail if a link already exists.
|
## by `src`. On most operating systems, will fail if a link already exists.
|
||||||
##
|
##
|
||||||
|
|
@ -2426,7 +2434,7 @@ proc createSymlink*(src, dest: string) {.noNimScript.} =
|
||||||
if symlink(src, dest) != 0:
|
if symlink(src, dest) != 0:
|
||||||
raiseOSError(osLastError(), $(src, dest))
|
raiseOSError(osLastError(), $(src, dest))
|
||||||
|
|
||||||
proc createHardlink*(src, dest: string) {.noNimScript.} =
|
proc createHardlink*(src, dest: string) {.noWeirdTarget.} =
|
||||||
## Create a hard link at `dest` which points to the item specified
|
## Create a hard link at `dest` which points to the item specified
|
||||||
## by `src`.
|
## by `src`.
|
||||||
##
|
##
|
||||||
|
|
@ -2449,7 +2457,7 @@ proc createHardlink*(src, dest: string) {.noNimScript.} =
|
||||||
raiseOSError(osLastError(), $(src, dest))
|
raiseOSError(osLastError(), $(src, dest))
|
||||||
|
|
||||||
proc copyFileWithPermissions*(source, dest: string,
|
proc copyFileWithPermissions*(source, dest: string,
|
||||||
ignorePermissionErrors = true) {.noNimScript.} =
|
ignorePermissionErrors = true) {.noWeirdTarget.} =
|
||||||
## Copies a file from `source` to `dest` preserving file permissions.
|
## Copies a file from `source` to `dest` preserving file permissions.
|
||||||
##
|
##
|
||||||
## This is a wrapper proc around `copyFile <#copyFile,string,string>`_,
|
## This is a wrapper proc around `copyFile <#copyFile,string,string>`_,
|
||||||
|
|
@ -2483,7 +2491,7 @@ proc copyFileWithPermissions*(source, dest: string,
|
||||||
|
|
||||||
proc copyDirWithPermissions*(source, dest: string,
|
proc copyDirWithPermissions*(source, dest: string,
|
||||||
ignorePermissionErrors = true) {.rtl, extern: "nos$1",
|
ignorePermissionErrors = true) {.rtl, extern: "nos$1",
|
||||||
tags: [WriteIOEffect, ReadIOEffect], benign, noNimScript.} =
|
tags: [WriteIOEffect, ReadIOEffect], benign, noWeirdTarget.} =
|
||||||
## Copies a directory from `source` to `dest` preserving file permissions.
|
## Copies a directory from `source` to `dest` preserving file permissions.
|
||||||
##
|
##
|
||||||
## If this fails, `OSError` is raised. This is a wrapper proc around `copyDir
|
## If this fails, `OSError` is raised. This is a wrapper proc around `copyDir
|
||||||
|
|
@ -2526,7 +2534,7 @@ proc copyDirWithPermissions*(source, dest: string,
|
||||||
|
|
||||||
proc inclFilePermissions*(filename: string,
|
proc inclFilePermissions*(filename: string,
|
||||||
permissions: set[FilePermission]) {.
|
permissions: set[FilePermission]) {.
|
||||||
rtl, extern: "nos$1", tags: [ReadDirEffect, WriteDirEffect], noNimScript.} =
|
rtl, extern: "nos$1", tags: [ReadDirEffect, WriteDirEffect], noWeirdTarget.} =
|
||||||
## A convenience proc for:
|
## A convenience proc for:
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
|
|
@ -2535,14 +2543,14 @@ proc inclFilePermissions*(filename: string,
|
||||||
|
|
||||||
proc exclFilePermissions*(filename: string,
|
proc exclFilePermissions*(filename: string,
|
||||||
permissions: set[FilePermission]) {.
|
permissions: set[FilePermission]) {.
|
||||||
rtl, extern: "nos$1", tags: [ReadDirEffect, WriteDirEffect], noNimScript.} =
|
rtl, extern: "nos$1", tags: [ReadDirEffect, WriteDirEffect], noWeirdTarget.} =
|
||||||
## A convenience proc for:
|
## A convenience proc for:
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## setFilePermissions(filename, getFilePermissions(filename)-permissions)
|
## setFilePermissions(filename, getFilePermissions(filename)-permissions)
|
||||||
setFilePermissions(filename, getFilePermissions(filename)-permissions)
|
setFilePermissions(filename, getFilePermissions(filename)-permissions)
|
||||||
|
|
||||||
proc expandSymlink*(symlinkPath: string): string {.noNimScript.} =
|
proc expandSymlink*(symlinkPath: string): string {.noWeirdTarget.} =
|
||||||
## Returns a string representing the path to which the symbolic link points.
|
## Returns a string representing the path to which the symbolic link points.
|
||||||
##
|
##
|
||||||
## On Windows this is a noop, ``symlinkPath`` is simply returned.
|
## On Windows this is a noop, ``symlinkPath`` is simply returned.
|
||||||
|
|
@ -2720,23 +2728,8 @@ when defined(nimdoc):
|
||||||
## else:
|
## else:
|
||||||
## # Do something else!
|
## # Do something else!
|
||||||
|
|
||||||
elif defined(nimscript):
|
elif defined(nimscript): discard
|
||||||
proc paramStr*(i: int): string =
|
elif defined(nintendoswitch) or weirdTarget:
|
||||||
## Retrieves the ``i``'th command line parameter.
|
|
||||||
discard
|
|
||||||
|
|
||||||
proc paramCount*(): int =
|
|
||||||
## Retrieves the number of command line parameters.
|
|
||||||
discard
|
|
||||||
|
|
||||||
elif defined(js):
|
|
||||||
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
|
||||||
raise newException(OSError, "paramStr is not implemented on JavaScript")
|
|
||||||
|
|
||||||
proc paramCount*(): int {.tags: [ReadIOEffect].} =
|
|
||||||
raise newException(OSError, "paramCount is not implemented on JavaScript")
|
|
||||||
|
|
||||||
elif defined(nintendoswitch):
|
|
||||||
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
||||||
raise newException(OSError, "paramStr is not implemented on Nintendo Switch")
|
raise newException(OSError, "paramStr is not implemented on Nintendo Switch")
|
||||||
|
|
||||||
|
|
@ -2947,7 +2940,7 @@ when defined(haiku):
|
||||||
else:
|
else:
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noNimScript.} =
|
proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget.} =
|
||||||
## Returns the filename of the application's executable.
|
## Returns the filename of the application's executable.
|
||||||
## This proc will resolve symlinks.
|
## This proc will resolve symlinks.
|
||||||
##
|
##
|
||||||
|
|
@ -3013,14 +3006,14 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noN
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
result = getApplHeuristic()
|
result = getApplHeuristic()
|
||||||
|
|
||||||
proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noNimScript.} =
|
proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget.} =
|
||||||
## Returns the directory of the application's executable.
|
## Returns the directory of the application's executable.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
## * `getAppFilename proc <#getAppFilename>`_
|
## * `getAppFilename proc <#getAppFilename>`_
|
||||||
result = splitFile(getAppFilename()).dir
|
result = splitFile(getAppFilename()).dir
|
||||||
|
|
||||||
proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [TimeEffect], noNimScript.} =
|
proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [TimeEffect], noWeirdTarget.} =
|
||||||
## Sleeps `milsecs` milliseconds.
|
## Sleeps `milsecs` milliseconds.
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
winlean.sleep(int32(milsecs))
|
winlean.sleep(int32(milsecs))
|
||||||
|
|
@ -3031,7 +3024,7 @@ proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [TimeEffect], noNimScrip
|
||||||
discard posix.nanosleep(a, b)
|
discard posix.nanosleep(a, b)
|
||||||
|
|
||||||
proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
|
proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
|
||||||
tags: [ReadIOEffect], noNimScript.} =
|
tags: [ReadIOEffect], noWeirdTarget.} =
|
||||||
## Returns the file size of `file` (in bytes). ``OSError`` is
|
## Returns the file size of `file` (in bytes). ``OSError`` is
|
||||||
## raised in case of an error.
|
## raised in case of an error.
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
@ -3132,13 +3125,13 @@ template rawToFormalFileInfo(rawInfo, path, formalInfo): untyped =
|
||||||
assert(path != "") # symlinks can't occur for file handles
|
assert(path != "") # symlinks can't occur for file handles
|
||||||
formalInfo.kind = getSymlinkFileKind(path)
|
formalInfo.kind = getSymlinkFileKind(path)
|
||||||
|
|
||||||
when defined(js) or defined(nimscript):
|
when defined(js):
|
||||||
when not declared(FileHandle):
|
when not declared(FileHandle):
|
||||||
type FileHandle = distinct int32
|
type FileHandle = distinct int32
|
||||||
when not declared(File):
|
when not declared(File):
|
||||||
type File = object
|
type File = object
|
||||||
|
|
||||||
proc getFileInfo*(handle: FileHandle): FileInfo {.noNimScript.} =
|
proc getFileInfo*(handle: FileHandle): FileInfo {.noWeirdTarget.} =
|
||||||
## Retrieves file information for the file object represented by the given
|
## Retrieves file information for the file object represented by the given
|
||||||
## handle.
|
## handle.
|
||||||
##
|
##
|
||||||
|
|
@ -3164,7 +3157,7 @@ proc getFileInfo*(handle: FileHandle): FileInfo {.noNimScript.} =
|
||||||
raiseOSError(osLastError(), $handle)
|
raiseOSError(osLastError(), $handle)
|
||||||
rawToFormalFileInfo(rawInfo, "", result)
|
rawToFormalFileInfo(rawInfo, "", result)
|
||||||
|
|
||||||
proc getFileInfo*(file: File): FileInfo {.noNimScript.} =
|
proc getFileInfo*(file: File): FileInfo {.noWeirdTarget.} =
|
||||||
## Retrieves file information for the file object.
|
## Retrieves file information for the file object.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
@ -3174,7 +3167,7 @@ proc getFileInfo*(file: File): FileInfo {.noNimScript.} =
|
||||||
raise newException(IOError, "File is nil")
|
raise newException(IOError, "File is nil")
|
||||||
result = getFileInfo(file.getFileHandle())
|
result = getFileInfo(file.getFileHandle())
|
||||||
|
|
||||||
proc getFileInfo*(path: string, followSymlink = true): FileInfo {.noNimScript.} =
|
proc getFileInfo*(path: string, followSymlink = true): FileInfo {.noWeirdTarget.} =
|
||||||
## Retrieves file information for the file object pointed to by `path`.
|
## Retrieves file information for the file object pointed to by `path`.
|
||||||
##
|
##
|
||||||
## Due to intrinsic differences between operating systems, the information
|
## Due to intrinsic differences between operating systems, the information
|
||||||
|
|
@ -3212,7 +3205,7 @@ proc getFileInfo*(path: string, followSymlink = true): FileInfo {.noNimScript.}
|
||||||
raiseOSError(osLastError(), path)
|
raiseOSError(osLastError(), path)
|
||||||
rawToFormalFileInfo(rawInfo, path, result)
|
rawToFormalFileInfo(rawInfo, path, result)
|
||||||
|
|
||||||
proc isHidden*(path: string): bool {.noNimScript.} =
|
proc isHidden*(path: string): bool {.noWeirdTarget.} =
|
||||||
## Determines whether ``path`` is hidden or not, using `this
|
## Determines whether ``path`` is hidden or not, using `this
|
||||||
## reference <https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory>`_.
|
## reference <https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory>`_.
|
||||||
##
|
##
|
||||||
|
|
@ -3242,7 +3235,7 @@ proc isHidden*(path: string): bool {.noNimScript.} =
|
||||||
let fileName = lastPathPart(path)
|
let fileName = lastPathPart(path)
|
||||||
result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".."
|
result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".."
|
||||||
|
|
||||||
proc getCurrentProcessId*(): int {.noNimScript.} =
|
proc getCurrentProcessId*(): int {.noWeirdTarget.} =
|
||||||
## Return current process ID.
|
## Return current process ID.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
|
|
@ -3254,7 +3247,7 @@ proc getCurrentProcessId*(): int {.noNimScript.} =
|
||||||
else:
|
else:
|
||||||
result = getpid()
|
result = getpid()
|
||||||
|
|
||||||
proc setLastModificationTime*(file: string, t: times.Time) {.noNimScript.} =
|
proc setLastModificationTime*(file: string, t: times.Time) {.noWeirdTarget.} =
|
||||||
## Sets the `file`'s last modification time. `OSError` is raised in case of
|
## Sets the `file`'s last modification time. `OSError` is raised in case of
|
||||||
## an error.
|
## an error.
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,14 @@ proc rawExec(cmd: string): int {.tags: [ExecIOEffect], raises: [OSError].} =
|
||||||
proc warningImpl(arg, orig: string) = discard
|
proc warningImpl(arg, orig: string) = discard
|
||||||
proc hintImpl(arg, orig: string) = discard
|
proc hintImpl(arg, orig: string) = discard
|
||||||
|
|
||||||
|
proc paramStr*(i: int): string =
|
||||||
|
## Retrieves the ``i``'th command line parameter.
|
||||||
|
builtin
|
||||||
|
|
||||||
|
proc paramCount*(): int =
|
||||||
|
## Retrieves the number of command line parameters.
|
||||||
|
builtin
|
||||||
|
|
||||||
proc switch*(key: string, val="") =
|
proc switch*(key: string, val="") =
|
||||||
## Sets a Nim compiler command line switch, for
|
## Sets a Nim compiler command line switch, for
|
||||||
## example ``switch("checks", "on")``.
|
## example ``switch("checks", "on")``.
|
||||||
|
|
@ -272,9 +280,6 @@ proc selfExec*(command: string) {.
|
||||||
raise newException(OSError, "FAILED: " & c)
|
raise newException(OSError, "FAILED: " & c)
|
||||||
checkOsError()
|
checkOsError()
|
||||||
|
|
||||||
from os import paramCount, paramStr
|
|
||||||
export paramCount, paramStr
|
|
||||||
|
|
||||||
proc put*(key, value: string) =
|
proc put*(key, value: string) =
|
||||||
## Sets a configuration 'key' like 'gcc.options.always' to its value.
|
## Sets a configuration 'key' like 'gcc.options.always' to its value.
|
||||||
builtin
|
builtin
|
||||||
|
|
|
||||||
|
|
@ -81,3 +81,10 @@ when false: # #14142
|
||||||
discard findExe("nim")
|
discard findExe("nim")
|
||||||
|
|
||||||
echo "Nimscript imports are successful."
|
echo "Nimscript imports are successful."
|
||||||
|
|
||||||
|
block: # #14142
|
||||||
|
discard existsDir("/usr")
|
||||||
|
discard dirExists("/usr")
|
||||||
|
discard existsFile("/usr/foo")
|
||||||
|
discard fileExists("/usr/foo")
|
||||||
|
discard findExe("nim")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue