From dc5a40f3f39c6ea672e6dc6aca7f8118a69dda99 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 2 Jul 2020 07:19:13 -0700 Subject: {.deprecated: [existsFile: fileExists].} (#14735) * {.deprecated: [existsFile: fileExists].} * s/existsFile/fileExists/ except under deps * workaround pending #14819 * fix test --- lib/pure/os.nim | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'lib/pure/os.nim') diff --git a/lib/pure/os.nim b/lib/pure/os.nim index dcb63458b..5d73544ce 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -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 = "" -- cgit 1.4.1-2-gfad0