|
|
| |
| local record dir |
| path: function(...: string): string |
| split_url: function(string): string, string |
| normalize: function(string): string |
| end |
|
|
| local core = require("luarocks.core.dir") |
|
|
| dir.path = core.path |
| dir.split_url = core.split_url |
| dir.normalize = core.normalize |
|
|
| local dir_sep = package.config:sub(1, 1) |
|
|
| |
| |
| |
| |
| function dir.base_name(pathname: string): string |
|
|
| local b: string |
| b = pathname:gsub("[/\\]", "/") |
| b = b:gsub("/*$", "") |
| b = b:match(".*[/\\]([^/\\]*)") |
| b = b or pathname |
|
|
| return b |
| end |
|
|
| |
| |
| |
| |
| |
| function dir.dir_name(pathname: string): string |
|
|
| local d: string |
| d = pathname:gsub("[/\\]", "/") |
| d = d:gsub("/*$", "") |
| d = d:match("(.*)[/]+[^/]*") |
| d = d or "" |
| d = d:gsub("/", dir_sep) |
|
|
| return d |
| end |
|
|
| |
| |
| function dir.is_basic_protocol(protocol: string): boolean |
| return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" |
| end |
|
|
| function dir.deduce_base_dir(url: string): string |
| |
| local known_exts = {} |
| for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do |
| known_exts[ext] = "" |
| end |
| local base = dir.base_name(url) |
| return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", "")) |
| end |
|
|
| return dir |
|
|