From: Tobias Ulmer Date: Wed, 9 Jan 2013 12:10:53 +0000 (+0100) Subject: Repair dirname and basename X-Git-Tag: e2factory-2.3.13rc1~61 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=50218a617b79f40482f12ef41e74bbefea002a17;p=e2factory.git Repair dirname and basename basename and dirname must be able to handle paths ending in zero or more slashes. Concatenation of dir- and basename will otherwise go wrong in edge cases. previously: dirname(foo/bar/) -> foo/bar basename(foo/bar/) -> bar => foo/bar/bar now: dirname(foo/bar///) -> foo basename(foo/bar///) -> bar => foo/bar Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index ca5200c..98b2c19 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -565,7 +565,7 @@ end function e2lib.dirname(path) assert(type(path) == "string") - local s, e, dir = string.find(path, "^(.*)/[^/]*$") + local s, e, dir = string.find(path, "^(.*)/[^/]+[/]*$") if dir == "" then return "/" end @@ -580,7 +580,7 @@ end function e2lib.basename(path) assert(type(path) == "string") - local s, e, base = string.find(path, "^.*/([^/]+)[/]?$") + local s, e, base = string.find(path, "^.*/([^/]+)[/]*$") if not base then base = path end