mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 23:41:29 +00:00
Fix getAppFilename exception handling (#22544)
* Fix `getAppFilename` exception handling avoid platform-dependendent error handling strategies * more fixes * space
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#
|
||||
|
||||
## This module contains basic operating system facilities like
|
||||
## retrieving environment variables, working with directories,
|
||||
## retrieving environment variables, working with directories,
|
||||
## running shell commands, etc.
|
||||
|
||||
## .. importdoc:: symlinks.nim, appdirs.nim, dirs.nim, ospaths2.nim
|
||||
@@ -624,10 +624,12 @@ when defined(haiku):
|
||||
else:
|
||||
result = ""
|
||||
|
||||
proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget.} =
|
||||
proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget, raises: [].} =
|
||||
## Returns the filename of the application's executable.
|
||||
## This proc will resolve symlinks.
|
||||
##
|
||||
## Returns empty string when name is unavailable
|
||||
##
|
||||
## See also:
|
||||
## * `getAppDir proc`_
|
||||
## * `getCurrentCompilerExe proc`_
|
||||
@@ -657,14 +659,17 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noW
|
||||
if getExecPath2(result.cstring, size):
|
||||
result = "" # error!
|
||||
if result.len > 0:
|
||||
result = result.expandFilename
|
||||
try:
|
||||
result = result.expandFilename
|
||||
except OSError:
|
||||
result = ""
|
||||
else:
|
||||
when defined(linux) or defined(aix):
|
||||
result = getApplAux("/proc/self/exe")
|
||||
elif defined(solaris):
|
||||
result = getApplAux("/proc/" & $getpid() & "/path/a.out")
|
||||
elif defined(genode):
|
||||
raiseOSError(OSErrorCode(-1), "POSIX command line not supported")
|
||||
result = "" # Not supported
|
||||
elif defined(freebsd) or defined(dragonfly) or defined(netbsd):
|
||||
result = getApplFreebsd()
|
||||
elif defined(haiku):
|
||||
@@ -676,7 +681,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noW
|
||||
|
||||
# little heuristic that may work on other POSIX-like systems:
|
||||
if result.len == 0:
|
||||
result = getApplHeuristic()
|
||||
result = try: getApplHeuristic() except OSError: ""
|
||||
|
||||
proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noWeirdTarget.} =
|
||||
## Returns the directory of the application's executable.
|
||||
|
||||
Reference in New Issue
Block a user