From 695154970d839add2fbbe9754e9e638511120729 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Fri, 3 Jul 2020 14:04:23 -0700 Subject: deprecate existsDir; use dirExists instead (#14884) --- lib/pure/os.nim | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'lib/pure/os.nim') diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 5d73544ce..8bbceddeb 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -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", -- cgit 1.4.1-2-gfad0