deprecate existsDir; use dirExists instead (#14884)

This commit is contained in:
Timothee Cour
2020-07-03 14:04:23 -07:00
committed by GitHub
parent 4f6acf24ff
commit 695154970d
14 changed files with 32 additions and 39 deletions

View File

@@ -121,6 +121,7 @@
- add `macros.extractDocCommentsAndRunnables` helper
- `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)

View File

@@ -82,7 +82,7 @@ proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): Re
# we're (currently) requiring `isAbsolute` to avoid confusion when passing
# a relative path (would it be relative wrt $PWD or to projectfile)
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`
result = file.relativeTo conf.docRoot.expandFilename.AbsoluteDir
else:

View File

@@ -1117,13 +1117,7 @@ proc fileExists*(filename: string): bool {.rtl, extern: "nos$1",
var res: Stat
return stat(filename, res) >= 0'i32 and S_ISREG(res.st_mode)
when not defined(nimscript):
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],
proc dirExists*(dir: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect],
noNimJs.} =
## Returns true if the directory `dir` exists. If `dir` is a file, false
## is returned. Follows symlinks.
@@ -1150,7 +1144,7 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
##
## See also:
## * `fileExists proc <#fileExists,string>`_
## * `existsDir proc <#existsDir,string>`_
## * `dirExists proc <#dirExists,string>`_
when defined(windows):
when useWinUnicode:
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)
proc dirExists*(dir: string): bool {.inline, noNimJs.} =
## Alias for `existsDir proc <#existsDir,string>`_.
##
## See also:
## * `fileExists proc <#fileExists,string>`_
## * `symlinkExists proc <#symlinkExists,string>`_
existsDir(dir)
when not defined(nimscript):
when not defined(js): # `noNimJs` doesn't work with templates, this should improve.
template existsFile*(args: varargs[untyped]): untyped {.deprecated: "use fileExists".} =
fileExists(args)
template existsDir*(args: varargs[untyped]): untyped {.deprecated: "use dirExists".} =
dirExists(args)
# {.deprecated: [existsFile: fileExists].} # pending bug #14819; this would avoid above mentioned issue
when not defined(windows) and not weirdTarget:
proc checkSymlink(path: string): bool =
@@ -2026,7 +2020,7 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
# way of retrieving the true filename
for x in walkFiles(result):
result = x
if not fileExists(result) and not existsDir(result):
if not fileExists(result) and not dirExists(result):
# consider using: `raiseOSError(osLastError(), result)`
raise newException(OSError, "file '" & result & "' does not exist")
else:
@@ -2323,7 +2317,7 @@ proc existsOrCreateDir*(dir: string): bool {.rtl, extern: "nos$1",
result = not rawCreateDir(dir)
if result:
# 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 & "'")
proc createDir*(dir: string) {.rtl, extern: "nos$1",

View File

@@ -81,7 +81,7 @@ iterator scanSSLCertificates*(useEnvVars = false): string =
if p.endsWith(".pem") or p.endsWith(".crt"):
if fileExists(p):
yield p
elif existsDir(p):
elif dirExists(p):
for fn in joinPath(p, "*").walkFiles():
yield fn
else:

View File

@@ -131,18 +131,17 @@ proc fileExists*(filename: string): bool {.tags: [ReadIOEffect].} =
## Checks if the file exists.
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 {.
tags: [ReadIOEffect].} =
## Checks if the directory `dir` exists.
builtin
proc existsDir*(dir: string): bool =
## An alias for ``dirExists``.
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)
template existsDir*(args: varargs[untyped]): untyped {.deprecated: "use dirExists".} =
dirExists(dir)
proc selfExe*(): string =

View File

@@ -507,7 +507,7 @@ proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string, p
inc r.total
var test = makeSupTest(url, "", cat)
let buildPath = packagesDir / name
if not existsDir(buildPath):
if not dirExists(buildPath):
if useHead:
let (installCmdLine, installOutput, installStatus) = execCmdEx2("git", ["clone", url, buildPath])
if installStatus != QuitSuccess:

View File

@@ -446,7 +446,7 @@ ingameClient.registerHandler(KeyF12, down, proc() = toggleSpec())
ingameClient.registerHandler(KeyF11, down, toggleShipSelect)
ingameClient.registerHandler(MouseLeft, down, handleLClick)
when defined(recordMode):
if not existsDir("data/snapshots"):
if not dirExists("data/snapshots"):
createDir("data/snapshots")
ingameClient.registerHandler(keynum9, down, proc() =
if not isRecording: startRecording()

View File

@@ -103,7 +103,7 @@ proc saveCurrentFile() =
let
path = expandPath(currentFileTransfer.assetType, currentFileTransfer.fileName)
parent = parentDir(path)
if not existsDir(parent):
if not dirExists(parent):
createDir(parent)
echo("Created dir")
writeFile path, currentFIleTransfer.data

View File

@@ -77,7 +77,7 @@ task "testskel", "create skeleton test dir for testing":
task "clean", "cleanup generated files":
var dirs = @["nimcache", "server"/"nimcache"]
dirs.apply(proc(x: var string) =
if existsDir(x): removeDir(x))
if dirExists(x): removeDir(x))
task "download", "download game assets":
var

View File

@@ -73,7 +73,7 @@ assert fileExists("tests/newconfig/tfoo.nims") == true
assert dirExists("tests") == true
assert fileExists("tests/newconfig/tfoo.nims") == true
assert existsDir("tests") == true
assert dirExists("tests") == true
discard selfExe()

View File

@@ -75,7 +75,6 @@ block:
doAssert "./foo//./bar/".normalizedPath == "foo/bar".unixToNativePath
block: # #14142
discard existsDir("/usr")
discard dirExists("/usr")
discard fileExists("/usr/foo")
discard findExe("nim")

View File

@@ -495,7 +495,7 @@ proc styleInsensitive(s: string): string =
else: addx()
proc walker(pattern; dir: string; counter: var int, errors: var int) =
if existsDir(dir):
if dirExists(dir):
for kind, path in walkDir(dir):
case kind
of pcFile:

View File

@@ -251,12 +251,12 @@ proc walkDirRecursively(s: var seq[string], root, explicit: string,
proc addFiles(s: var seq[string], patterns: seq[string]) =
for p in items(patterns):
if existsDir(p):
if dirExists(p):
walkDirRecursively(s, p, p, false)
else:
var i = 0
for f in walkPattern(p):
if existsDir(f):
if dirExists(f):
walkDirRecursively(s, f, p, false)
elif not ignoreFile(f, p, false):
add(s, unixToNativePath(f))
@@ -518,7 +518,7 @@ template gatherFiles(fun, libpath, outDir) =
proc srcdist(c: var ConfigData) =
let cCodeDir = getOutputDir(c) / "c_code"
if not existsDir(cCodeDir): createDir(cCodeDir)
if not dirExists(cCodeDir): createDir(cCodeDir)
gatherFiles(copyFile, c.libpath, cCodeDir)
var winIndex = -1
var intel32Index = -1
@@ -532,7 +532,7 @@ proc srcdist(c: var ConfigData) =
if cpuname.cmpIgnoreStyle("i386") == 0: intel32Index = cpuA
elif cpuname.cmpIgnoreStyle("amd64") == 0: intel64Index = cpuA
var dir = getOutputDir(c) / buildDir(osA, cpuA)
if existsDir(dir): removeDir(dir)
if dirExists(dir): removeDir(dir)
createDir(dir)
var cmd = ("nim compile -f --symbolfiles:off --compileonly " &
"--gen_mapping --cc:gcc --skipUserCfg" &

View File

@@ -201,7 +201,7 @@ proc addFiles(s: var seq[string], dir, ext: string, patterns: seq[string]) =
for p in items(patterns):
if fileExists(dir / addFileExt(p, ext)):
s.add(dir / addFileExt(p, ext))
if existsDir(dir / p):
if dirExists(dir / p):
walkDirRecursively(s, dir / p, ext)
proc parseIniFile(c: var TConfigData) =
@@ -483,7 +483,7 @@ proc buildPage(c: var TConfigData, file, title, rss: string, assetDir = "") =
quit("[Error] cannot open: " & temp)
var f: File
var outfile = c.webUploadOutput / "$#.html" % file
if not existsDir(outfile.splitFile.dir):
if not dirExists(outfile.splitFile.dir):
createDir(outfile.splitFile.dir)
if open(f, outfile, fmWrite):
writeLine(f, generateHTMLPage(c, file, title, content, rss, assetDir))