deprecate existsDir; use dirExists instead (#14884)
This commit is contained in:
parent
4f6acf24ff
commit
695154970d
14 changed files with 32 additions and 39 deletions
|
|
@ -121,6 +121,7 @@
|
||||||
- add `macros.extractDocCommentsAndRunnables` helper
|
- add `macros.extractDocCommentsAndRunnables` helper
|
||||||
|
|
||||||
- `strformat.fmt` and `strformat.&` support `= specifier`. `fmt"{expr=}"` now expands to `fmt"expr={expr}"`.
|
- `strformat.fmt` and `strformat.&` support `= specifier`. `fmt"{expr=}"` now expands to `fmt"expr={expr}"`.
|
||||||
|
- deprecations: `os.existsDir` => `dirExists`, `os.existsFile` => `fileExists`
|
||||||
|
|
||||||
- Add `jsre` module, [Regular Expressions for the JavaScript target.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
- Add `jsre` module, [Regular Expressions for the JavaScript target.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): Re
|
||||||
# we're (currently) requiring `isAbsolute` to avoid confusion when passing
|
# we're (currently) requiring `isAbsolute` to avoid confusion when passing
|
||||||
# a relative path (would it be relative wrt $PWD or to projectfile)
|
# a relative path (would it be relative wrt $PWD or to projectfile)
|
||||||
conf.globalAssert conf.docRoot.isAbsolute, arg=conf.docRoot
|
conf.globalAssert conf.docRoot.isAbsolute, arg=conf.docRoot
|
||||||
conf.globalAssert conf.docRoot.existsDir, arg=conf.docRoot
|
conf.globalAssert conf.docRoot.dirExists, arg=conf.docRoot
|
||||||
# needed because `canonicalizePath` called on `file`
|
# needed because `canonicalizePath` called on `file`
|
||||||
result = file.relativeTo conf.docRoot.expandFilename.AbsoluteDir
|
result = file.relativeTo conf.docRoot.expandFilename.AbsoluteDir
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1117,13 +1117,7 @@ proc fileExists*(filename: string): bool {.rtl, extern: "nos$1",
|
||||||
var res: Stat
|
var res: Stat
|
||||||
return stat(filename, res) >= 0'i32 and S_ISREG(res.st_mode)
|
return stat(filename, res) >= 0'i32 and S_ISREG(res.st_mode)
|
||||||
|
|
||||||
when not defined(nimscript):
|
proc dirExists*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect],
|
||||||
when not defined(js): # `noNimJs` doesn't work with templates, this should improve.
|
|
||||||
template existsFile*(args: varargs[untyped]): untyped {.deprecated: "use fileExists".} =
|
|
||||||
fileExists(args)
|
|
||||||
# {.deprecated: [existsFile: fileExists].} # pending bug #14819; this would avoid above mentioned issue
|
|
||||||
|
|
||||||
proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect],
|
|
||||||
noNimJs.} =
|
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.
|
||||||
|
|
@ -1150,7 +1144,7 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
## * `fileExists proc <#fileExists,string>`_
|
## * `fileExists proc <#fileExists,string>`_
|
||||||
## * `existsDir proc <#existsDir,string>`_
|
## * `dirExists proc <#dirExists,string>`_
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
wrapUnary(a, getFileAttributesW, link)
|
wrapUnary(a, getFileAttributesW, link)
|
||||||
|
|
@ -1163,13 +1157,13 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
|
||||||
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 dirExists*(dir: string): bool {.inline, noNimJs.} =
|
when not defined(nimscript):
|
||||||
## Alias for `existsDir proc <#existsDir,string>`_.
|
when not defined(js): # `noNimJs` doesn't work with templates, this should improve.
|
||||||
##
|
template existsFile*(args: varargs[untyped]): untyped {.deprecated: "use fileExists".} =
|
||||||
## See also:
|
fileExists(args)
|
||||||
## * `fileExists proc <#fileExists,string>`_
|
template existsDir*(args: varargs[untyped]): untyped {.deprecated: "use dirExists".} =
|
||||||
## * `symlinkExists proc <#symlinkExists,string>`_
|
dirExists(args)
|
||||||
existsDir(dir)
|
# {.deprecated: [existsFile: fileExists].} # pending bug #14819; this would avoid above mentioned issue
|
||||||
|
|
||||||
when not defined(windows) and not weirdTarget:
|
when not defined(windows) and not weirdTarget:
|
||||||
proc checkSymlink(path: string): bool =
|
proc checkSymlink(path: string): bool =
|
||||||
|
|
@ -2026,7 +2020,7 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
|
||||||
# way of retrieving the true filename
|
# way of retrieving the true filename
|
||||||
for x in walkFiles(result):
|
for x in walkFiles(result):
|
||||||
result = x
|
result = x
|
||||||
if not fileExists(result) and not existsDir(result):
|
if not fileExists(result) and not dirExists(result):
|
||||||
# consider using: `raiseOSError(osLastError(), result)`
|
# consider using: `raiseOSError(osLastError(), result)`
|
||||||
raise newException(OSError, "file '" & result & "' does not exist")
|
raise newException(OSError, "file '" & result & "' does not exist")
|
||||||
else:
|
else:
|
||||||
|
|
@ -2323,7 +2317,7 @@ proc existsOrCreateDir*(dir: string): bool {.rtl, extern: "nos$1",
|
||||||
result = not rawCreateDir(dir)
|
result = not rawCreateDir(dir)
|
||||||
if result:
|
if result:
|
||||||
# path already exists - need to check that it is indeed a directory
|
# path already exists - need to check that it is indeed a directory
|
||||||
if not existsDir(dir):
|
if not dirExists(dir):
|
||||||
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",
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ iterator scanSSLCertificates*(useEnvVars = false): string =
|
||||||
if p.endsWith(".pem") or p.endsWith(".crt"):
|
if p.endsWith(".pem") or p.endsWith(".crt"):
|
||||||
if fileExists(p):
|
if fileExists(p):
|
||||||
yield p
|
yield p
|
||||||
elif existsDir(p):
|
elif dirExists(p):
|
||||||
for fn in joinPath(p, "*").walkFiles():
|
for fn in joinPath(p, "*").walkFiles():
|
||||||
yield fn
|
yield fn
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -131,18 +131,17 @@ proc fileExists*(filename: string): bool {.tags: [ReadIOEffect].} =
|
||||||
## Checks if the file exists.
|
## Checks if the file exists.
|
||||||
builtin
|
builtin
|
||||||
|
|
||||||
template existsFile*(args: varargs[untyped]): untyped {.deprecated: "use fileExists".} =
|
|
||||||
# xxx: warning won't be shown for nimsscript because of current logic handling
|
|
||||||
# `foreignPackageNotes`
|
|
||||||
fileExists(args)
|
|
||||||
|
|
||||||
proc dirExists*(dir: string): bool {.
|
proc dirExists*(dir: string): bool {.
|
||||||
tags: [ReadIOEffect].} =
|
tags: [ReadIOEffect].} =
|
||||||
## Checks if the directory `dir` exists.
|
## Checks if the directory `dir` exists.
|
||||||
builtin
|
builtin
|
||||||
|
|
||||||
proc existsDir*(dir: string): bool =
|
template existsFile*(args: varargs[untyped]): untyped {.deprecated: "use fileExists".} =
|
||||||
## An alias for ``dirExists``.
|
# xxx: warning won't be shown for nimsscript because of current logic handling
|
||||||
|
# `foreignPackageNotes`
|
||||||
|
fileExists(args)
|
||||||
|
|
||||||
|
template existsDir*(args: varargs[untyped]): untyped {.deprecated: "use dirExists".} =
|
||||||
dirExists(dir)
|
dirExists(dir)
|
||||||
|
|
||||||
proc selfExe*(): string =
|
proc selfExe*(): string =
|
||||||
|
|
|
||||||
|
|
@ -507,7 +507,7 @@ proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string, p
|
||||||
inc r.total
|
inc r.total
|
||||||
var test = makeSupTest(url, "", cat)
|
var test = makeSupTest(url, "", cat)
|
||||||
let buildPath = packagesDir / name
|
let buildPath = packagesDir / name
|
||||||
if not existsDir(buildPath):
|
if not dirExists(buildPath):
|
||||||
if useHead:
|
if useHead:
|
||||||
let (installCmdLine, installOutput, installStatus) = execCmdEx2("git", ["clone", url, buildPath])
|
let (installCmdLine, installOutput, installStatus) = execCmdEx2("git", ["clone", url, buildPath])
|
||||||
if installStatus != QuitSuccess:
|
if installStatus != QuitSuccess:
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,7 @@ ingameClient.registerHandler(KeyF12, down, proc() = toggleSpec())
|
||||||
ingameClient.registerHandler(KeyF11, down, toggleShipSelect)
|
ingameClient.registerHandler(KeyF11, down, toggleShipSelect)
|
||||||
ingameClient.registerHandler(MouseLeft, down, handleLClick)
|
ingameClient.registerHandler(MouseLeft, down, handleLClick)
|
||||||
when defined(recordMode):
|
when defined(recordMode):
|
||||||
if not existsDir("data/snapshots"):
|
if not dirExists("data/snapshots"):
|
||||||
createDir("data/snapshots")
|
createDir("data/snapshots")
|
||||||
ingameClient.registerHandler(keynum9, down, proc() =
|
ingameClient.registerHandler(keynum9, down, proc() =
|
||||||
if not isRecording: startRecording()
|
if not isRecording: startRecording()
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ proc saveCurrentFile() =
|
||||||
let
|
let
|
||||||
path = expandPath(currentFileTransfer.assetType, currentFileTransfer.fileName)
|
path = expandPath(currentFileTransfer.assetType, currentFileTransfer.fileName)
|
||||||
parent = parentDir(path)
|
parent = parentDir(path)
|
||||||
if not existsDir(parent):
|
if not dirExists(parent):
|
||||||
createDir(parent)
|
createDir(parent)
|
||||||
echo("Created dir")
|
echo("Created dir")
|
||||||
writeFile path, currentFIleTransfer.data
|
writeFile path, currentFIleTransfer.data
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ task "testskel", "create skeleton test dir for testing":
|
||||||
task "clean", "cleanup generated files":
|
task "clean", "cleanup generated files":
|
||||||
var dirs = @["nimcache", "server"/"nimcache"]
|
var dirs = @["nimcache", "server"/"nimcache"]
|
||||||
dirs.apply(proc(x: var string) =
|
dirs.apply(proc(x: var string) =
|
||||||
if existsDir(x): removeDir(x))
|
if dirExists(x): removeDir(x))
|
||||||
|
|
||||||
task "download", "download game assets":
|
task "download", "download game assets":
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ assert fileExists("tests/newconfig/tfoo.nims") == true
|
||||||
assert dirExists("tests") == true
|
assert dirExists("tests") == true
|
||||||
|
|
||||||
assert fileExists("tests/newconfig/tfoo.nims") == true
|
assert fileExists("tests/newconfig/tfoo.nims") == true
|
||||||
assert existsDir("tests") == true
|
assert dirExists("tests") == true
|
||||||
|
|
||||||
discard selfExe()
|
discard selfExe()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ block:
|
||||||
doAssert "./foo//./bar/".normalizedPath == "foo/bar".unixToNativePath
|
doAssert "./foo//./bar/".normalizedPath == "foo/bar".unixToNativePath
|
||||||
|
|
||||||
block: # #14142
|
block: # #14142
|
||||||
discard existsDir("/usr")
|
|
||||||
discard dirExists("/usr")
|
discard dirExists("/usr")
|
||||||
discard fileExists("/usr/foo")
|
discard fileExists("/usr/foo")
|
||||||
discard findExe("nim")
|
discard findExe("nim")
|
||||||
|
|
|
||||||
|
|
@ -495,7 +495,7 @@ proc styleInsensitive(s: string): string =
|
||||||
else: addx()
|
else: addx()
|
||||||
|
|
||||||
proc walker(pattern; dir: string; counter: var int, errors: var int) =
|
proc walker(pattern; dir: string; counter: var int, errors: var int) =
|
||||||
if existsDir(dir):
|
if dirExists(dir):
|
||||||
for kind, path in walkDir(dir):
|
for kind, path in walkDir(dir):
|
||||||
case kind
|
case kind
|
||||||
of pcFile:
|
of pcFile:
|
||||||
|
|
|
||||||
|
|
@ -251,12 +251,12 @@ proc walkDirRecursively(s: var seq[string], root, explicit: string,
|
||||||
|
|
||||||
proc addFiles(s: var seq[string], patterns: seq[string]) =
|
proc addFiles(s: var seq[string], patterns: seq[string]) =
|
||||||
for p in items(patterns):
|
for p in items(patterns):
|
||||||
if existsDir(p):
|
if dirExists(p):
|
||||||
walkDirRecursively(s, p, p, false)
|
walkDirRecursively(s, p, p, false)
|
||||||
else:
|
else:
|
||||||
var i = 0
|
var i = 0
|
||||||
for f in walkPattern(p):
|
for f in walkPattern(p):
|
||||||
if existsDir(f):
|
if dirExists(f):
|
||||||
walkDirRecursively(s, f, p, false)
|
walkDirRecursively(s, f, p, false)
|
||||||
elif not ignoreFile(f, p, false):
|
elif not ignoreFile(f, p, false):
|
||||||
add(s, unixToNativePath(f))
|
add(s, unixToNativePath(f))
|
||||||
|
|
@ -518,7 +518,7 @@ template gatherFiles(fun, libpath, outDir) =
|
||||||
|
|
||||||
proc srcdist(c: var ConfigData) =
|
proc srcdist(c: var ConfigData) =
|
||||||
let cCodeDir = getOutputDir(c) / "c_code"
|
let cCodeDir = getOutputDir(c) / "c_code"
|
||||||
if not existsDir(cCodeDir): createDir(cCodeDir)
|
if not dirExists(cCodeDir): createDir(cCodeDir)
|
||||||
gatherFiles(copyFile, c.libpath, cCodeDir)
|
gatherFiles(copyFile, c.libpath, cCodeDir)
|
||||||
var winIndex = -1
|
var winIndex = -1
|
||||||
var intel32Index = -1
|
var intel32Index = -1
|
||||||
|
|
@ -532,7 +532,7 @@ proc srcdist(c: var ConfigData) =
|
||||||
if cpuname.cmpIgnoreStyle("i386") == 0: intel32Index = cpuA
|
if cpuname.cmpIgnoreStyle("i386") == 0: intel32Index = cpuA
|
||||||
elif cpuname.cmpIgnoreStyle("amd64") == 0: intel64Index = cpuA
|
elif cpuname.cmpIgnoreStyle("amd64") == 0: intel64Index = cpuA
|
||||||
var dir = getOutputDir(c) / buildDir(osA, cpuA)
|
var dir = getOutputDir(c) / buildDir(osA, cpuA)
|
||||||
if existsDir(dir): removeDir(dir)
|
if dirExists(dir): removeDir(dir)
|
||||||
createDir(dir)
|
createDir(dir)
|
||||||
var cmd = ("nim compile -f --symbolfiles:off --compileonly " &
|
var cmd = ("nim compile -f --symbolfiles:off --compileonly " &
|
||||||
"--gen_mapping --cc:gcc --skipUserCfg" &
|
"--gen_mapping --cc:gcc --skipUserCfg" &
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ proc addFiles(s: var seq[string], dir, ext: string, patterns: seq[string]) =
|
||||||
for p in items(patterns):
|
for p in items(patterns):
|
||||||
if fileExists(dir / addFileExt(p, ext)):
|
if fileExists(dir / addFileExt(p, ext)):
|
||||||
s.add(dir / addFileExt(p, ext))
|
s.add(dir / addFileExt(p, ext))
|
||||||
if existsDir(dir / p):
|
if dirExists(dir / p):
|
||||||
walkDirRecursively(s, dir / p, ext)
|
walkDirRecursively(s, dir / p, ext)
|
||||||
|
|
||||||
proc parseIniFile(c: var TConfigData) =
|
proc parseIniFile(c: var TConfigData) =
|
||||||
|
|
@ -483,7 +483,7 @@ proc buildPage(c: var TConfigData, file, title, rss: string, assetDir = "") =
|
||||||
quit("[Error] cannot open: " & temp)
|
quit("[Error] cannot open: " & temp)
|
||||||
var f: File
|
var f: File
|
||||||
var outfile = c.webUploadOutput / "$#.html" % file
|
var outfile = c.webUploadOutput / "$#.html" % file
|
||||||
if not existsDir(outfile.splitFile.dir):
|
if not dirExists(outfile.splitFile.dir):
|
||||||
createDir(outfile.splitFile.dir)
|
createDir(outfile.splitFile.dir)
|
||||||
if open(f, outfile, fmWrite):
|
if open(f, outfile, fmWrite):
|
||||||
writeLine(f, generateHTMLPage(c, file, title, content, rss, assetDir))
|
writeLine(f, generateHTMLPage(c, file, title, content, rss, assetDir))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue