Software /
code /
prosody
Comparison
util/paths.lua @ 6164:ef4024f6bc40
core.configmanager: Move path utility functions into util.paths
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 09 May 2014 19:34:35 +0200 |
child | 6505:2dc8dbd0940e |
comparison
equal
deleted
inserted
replaced
6162:fbc3b195dab8 | 6164:ef4024f6bc40 |
---|---|
1 local path_sep = package.config:sub(1,1); | |
2 | |
3 local path_util = {} | |
4 | |
5 -- Helper function to resolve relative paths (needed by config) | |
6 function path_util.resolve_relative_path(parent_path, path) | |
7 if path then | |
8 -- Some normalization | |
9 parent_path = parent_path:gsub("%"..path_sep.."+$", ""); | |
10 path = path:gsub("^%.%"..path_sep.."+", ""); | |
11 | |
12 local is_relative; | |
13 if path_sep == "/" and path:sub(1,1) ~= "/" then | |
14 is_relative = true; | |
15 elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and (path:sub(2,3) ~= ":\\" and path:sub(2,3) ~= ":/")) then | |
16 is_relative = true; | |
17 end | |
18 if is_relative then | |
19 return parent_path..path_sep..path; | |
20 end | |
21 end | |
22 return path; | |
23 end | |
24 | |
25 -- Helper function to convert a glob to a Lua pattern | |
26 function path_util.glob_to_pattern(glob) | |
27 return "^"..glob:gsub("[%p*?]", function (c) | |
28 if c == "*" then | |
29 return ".*"; | |
30 elseif c == "?" then | |
31 return "."; | |
32 else | |
33 return "%"..c; | |
34 end | |
35 end).."$"; | |
36 end | |
37 | |
38 return path_util; |