Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stevedonovan/Penlight.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorNathaniel Wesley Filardo <VP331RHQ115POU58JFRLKB7OPA0L18E3@cmx.ietfng.org>2022-07-21 16:26:25 +0300
committerGitHub <noreply@github.com>2022-07-21 16:26:25 +0300
commitaf6026474ace10f235edd367abd38755f7c04b1d (patch)
tree374b6703035ede00306aa1690a0f3e29eaf137c2 /lua
parent3ebfb6123128497ee5e8fac445ae98bc95ad0cd8 (diff)
fix(app) require_here follow symlink'd main module (#423)
Diffstat (limited to 'lua')
-rw-r--r--lua/pl/app.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/lua/pl/app.lua b/lua/pl/app.lua
index a06305d..28f839e 100644
--- a/lua/pl/app.lua
+++ b/lua/pl/app.lua
@@ -29,12 +29,24 @@ end
--
-- Note: the path is prefixed, so it is searched first when requiring modules.
-- @string base optional base directory (absolute, or relative path).
+-- @bool nofollow always use the invocation's directory, even if the invoked file is a symlink
-- @treturn string the current script's path with a trailing slash
-function app.require_here (base)
- local p = path.dirname(app.script_name())
+function app.require_here (base, nofollow)
+ local p = app.script_name()
if not path.isabs(p) then
p = path.join(path.currentdir(),p)
end
+ if not nofollow then
+ local t = path.link_attrib(p)
+ if t and t.mode == 'link' then
+ t = t.target
+ if not path.isabs(t) then
+ t = path.join(path.dirname(p), t)
+ end
+ p = t
+ end
+ end
+ p = path.normpath(path.dirname(p))
if p:sub(-1,-1) ~= path.sep then
p = p..path.sep
end