{.deprecated: [existsFile: fileExists].} (#14735)

* {.deprecated: [existsFile: fileExists].}

* s/existsFile/fileExists/ except under deps

* workaround pending #14819

* fix test
This commit is contained in:
Timothee Cour 2020-07-02 07:19:13 -07:00 • committed by GitHub
commit dc5a40f3f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 66 additions and 67 deletions

View file

@ -313,7 +313,7 @@ proc defaultMsgHandler*(filename: string, line, col: int, msgkind: MsgKind,
else: writeLine(stdout, message)
proc defaultFindFile*(filename: string): string =
if existsFile(filename): result = filename
if fileExists(filename): result = filename
else: result = ""
proc newSharedState(options: RstParseOptions,
@ -328,7 +328,7 @@ proc newSharedState(options: RstParseOptions,
proc findRelativeFile(p: RstParser; filename: string): string =
result = p.filename.splitFile.dir / filename
if not existsFile(result):
if not fileExists(result):
result = p.s.findFile(filename)
proc rstMessage(p: RstParser, msgKind: MsgKind, arg: string) =

View file

@ -231,7 +231,7 @@ proc listDirs*(ftp: AsyncFtpClient, dir = ""): Future[seq[string]] {.async.} =
result = splitLines(await ftp.getLines())
proc existsFile*(ftp: AsyncFtpClient, file: string): Future[bool] {.async.} =
proc fileExists*(ftp: AsyncFtpClient, file: string): Future[bool] {.async.} =
## Determines whether ``file`` exists.
var files = await ftp.listDirs()
for f in items(files):

View file

@ -513,10 +513,10 @@ when defineSsl:
# http://simplestcodings.blogspot.co.uk/2010/08/secure-server-client-using-openssl-in-c.html
proc loadCertificates(ctx: SslCtx, certFile, keyFile: string) =
if certFile != "" and not existsFile(certFile):
if certFile != "" and not fileExists(certFile):
raise newException(system.IOError,
"Certificate file could not be found: " & certFile)
if keyFile != "" and not existsFile(keyFile):
if keyFile != "" and not fileExists(keyFile):
raise newException(system.IOError, "Key file could not be found: " & keyFile)
if certFile != "":

View file

@ -1097,14 +1097,14 @@ when defined(windows) and not weirdTarget:
result = f.cFileName[0].int == dot and (f.cFileName[1].int == 0 or
f.cFileName[1].int == dot and f.cFileName[2].int == 0)
proc existsFile*(filename: string): bool {.rtl, extern: "nos$1",
proc fileExists*(filename: string): bool {.rtl, extern: "nos$1",
tags: [ReadDirEffect], noNimJs.} =
## Returns true if `filename` exists and is a regular file or symlink.
##
## Directories, device files, named pipes and sockets return false.
##
## See also:
## * `existsDir proc <#existsDir,string>`_
## * `dirExists proc <#dirExists,string>`_
## * `symlinkExists proc <#symlinkExists,string>`_
when defined(windows):
when useWinUnicode:
@ -1117,13 +1117,19 @@ proc existsFile*(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],
noNimJs.} =
## Returns true if the directory `dir` exists. If `dir` is a file, false
## is returned. Follows symlinks.
##
## See also:
## * `existsFile proc <#existsFile,string>`_
## * `fileExists proc <#fileExists,string>`_
## * `symlinkExists proc <#symlinkExists,string>`_
when defined(windows):
when useWinUnicode:
@ -1143,7 +1149,7 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
## regardless of whether the link points to a directory or file.
##
## See also:
## * `existsFile proc <#existsFile,string>`_
## * `fileExists proc <#fileExists,string>`_
## * `existsDir proc <#existsDir,string>`_
when defined(windows):
when useWinUnicode:
@ -1156,19 +1162,12 @@ proc symlinkExists*(link: string): bool {.rtl, extern: "nos$1",
var res: Stat
return lstat(link, res) >= 0'i32 and S_ISLNK(res.st_mode)
proc fileExists*(filename: string): bool {.inline, noNimJs.} =
## Alias for `existsFile proc <#existsFile,string>`_.
##
## See also:
## * `existsDir proc <#existsDir,string>`_
## * `symlinkExists proc <#symlinkExists,string>`_
existsFile(filename)
proc dirExists*(dir: string): bool {.inline, noNimJs.} =
## Alias for `existsDir proc <#existsDir,string>`_.
##
## See also:
## * `existsFile proc <#existsFile,string>`_
## * `fileExists proc <#fileExists,string>`_
## * `symlinkExists proc <#symlinkExists,string>`_
existsDir(dir)
@ -1200,7 +1199,7 @@ proc findExe*(exe: string, followSymlinks: bool = true;
template checkCurrentDir() =
for ext in extensions:
result = addFileExt(exe, ext)
if existsFile(result): return
if fileExists(result): return
when defined(posix):
if '/' in exe: checkCurrentDir()
else:
@ -1216,7 +1215,7 @@ proc findExe*(exe: string, followSymlinks: bool = true;
var x = expandTilde(candidate) / exe
for ext in extensions:
var x = addFileExt(x, ext)
if existsFile(x):
if fileExists(x):
when not defined(windows):
while followSymlinks: # doubles as if here
if x.checkSymlink:
@ -2027,7 +2026,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 existsFile(result) and not existsDir(result):
if not fileExists(result) and not existsDir(result):
# consider using: `raiseOSError(osLastError(), result)`
raise newException(OSError, "file '" & result & "' does not exist")
else:
@ -2893,7 +2892,7 @@ when not weirdTarget and defined(openbsd):
# search in path
for p in split(string(getEnv("PATH")), {PathSep}):
var x = joinPath(p, exePath)
if existsFile(x):
if fileExists(x):
return expandFilename(x)
else:
result = ""
@ -2908,7 +2907,7 @@ when not (defined(windows) or defined(macosx) or weirdTarget):
# iterate over any path in the $PATH environment variable
for p in split(string(getEnv("PATH")), {PathSep}):
var x = joinPath(p, result)
if existsFile(x): return x
if fileExists(x): return x
else:
result = ""

View file

@ -79,7 +79,7 @@ iterator scanSSLCertificates*(useEnvVars = false): string =
when not defined(haiku):
for p in certificate_paths:
if p.endsWith(".pem") or p.endsWith(".crt"):
if existsFile(p):
if fileExists(p):
yield p
elif existsDir(p):
for fn in joinPath(p, "*").walkFiles():

View file

@ -131,15 +131,16 @@ 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 existsFile*(filename: string): bool =
## An alias for ``fileExists``.
fileExists(filename)
proc existsDir*(dir: string): bool =
## An alias for ``dirExists``.
dirExists(dir)