diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2017-10-08 00:52:24 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2017-10-08 00:52:24 -0300 |
| commit | afcba75d2772e664b69698390c8000210b203175 (patch) | |
| tree | 8c8c4cc7b5afd10a9797e578a2636f89b10fd7c5 /src | |
| parent | 5bc085477a1509915b6c91b93b855976a4a540ce (diff) | |
| download | luarocks-afcba75d2772e664b69698390c8000210b203175.tar.gz luarocks-afcba75d2772e664b69698390c8000210b203175.tar.bz2 luarocks-afcba75d2772e664b69698390c8000210b203175.zip | |
Dir separator is always "/".
The code was already effectively using "/" as the only
directory separator, even on Windows. This commit removes
the unnecessary indirection.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/build.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/core/dir.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/core/path.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 10 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/path.lua | 2 |
7 files changed, 11 insertions, 15 deletions
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index a6b67b92..904a7298 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua | |||
| @@ -76,7 +76,7 @@ local function do_build(name, version, deps_mode, build_only_deps) | |||
| 76 | return build_rock(name, true, deps_mode, build_only_deps) | 76 | return build_rock(name, true, deps_mode, build_only_deps) |
| 77 | elseif name:match("%.rock$") then | 77 | elseif name:match("%.rock$") then |
| 78 | return build_rock(name, true, deps_mode, build_only_deps) | 78 | return build_rock(name, true, deps_mode, build_only_deps) |
| 79 | elseif not name:match(dir.separator) then | 79 | elseif not name:match("/") then |
| 80 | local search = require("luarocks.search") | 80 | local search = require("luarocks.search") |
| 81 | return search.act_on_src_or_rockspec(do_build, name:lower(), version, nil, deps_mode, build_only_deps) | 81 | return search.act_on_src_or_rockspec(do_build, name:lower(), version, nil, deps_mode, build_only_deps) |
| 82 | end | 82 | end |
diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua index 05b2c72d..70a82bd4 100644 --- a/src/luarocks/core/dir.lua +++ b/src/luarocks/core/dir.lua | |||
| @@ -4,8 +4,6 @@ local dir = {} | |||
| 4 | local require = nil | 4 | local require = nil |
| 5 | -------------------------------------------------------------------------------- | 5 | -------------------------------------------------------------------------------- |
| 6 | 6 | ||
| 7 | dir.separator = "/" | ||
| 8 | |||
| 9 | --- Describe a path in a cross-platform way. | 7 | --- Describe a path in a cross-platform way. |
| 10 | -- Use this function to avoid platform-specific directory | 8 | -- Use this function to avoid platform-specific directory |
| 11 | -- separators in other modules. Removes trailing slashes from | 9 | -- separators in other modules. Removes trailing slashes from |
diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua index ed85aeac..fd84c7df 100644 --- a/src/luarocks/core/path.lua +++ b/src/luarocks/core/path.lua | |||
| @@ -44,7 +44,7 @@ function path.path_to_module(file) | |||
| 44 | 44 | ||
| 45 | local name = file:match("(.*)%."..cfg.lua_extension.."$") | 45 | local name = file:match("(.*)%."..cfg.lua_extension.."$") |
| 46 | if name then | 46 | if name then |
| 47 | name = name:gsub(dir.separator, ".") | 47 | name = name:gsub("/", ".") |
| 48 | local init = name:match("(.*)%.init$") | 48 | local init = name:match("(.*)%.init$") |
| 49 | if init then | 49 | if init then |
| 50 | name = init | 50 | name = init |
| @@ -52,12 +52,12 @@ function path.path_to_module(file) | |||
| 52 | else | 52 | else |
| 53 | name = file:match("(.*)%."..cfg.lib_extension.."$") | 53 | name = file:match("(.*)%."..cfg.lib_extension.."$") |
| 54 | if name then | 54 | if name then |
| 55 | name = name:gsub(dir.separator, ".") | 55 | name = name:gsub("/", ".") |
| 56 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. | 56 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. |
| 57 | else | 57 | else |
| 58 | name = file:match("(.*)%."..cfg.static_lib_extension.."$") | 58 | name = file:match("(.*)%."..cfg.static_lib_extension.."$") |
| 59 | if name then | 59 | if name then |
| 60 | name = name:gsub(dir.separator, ".") | 60 | name = name:gsub("/", ".") |
| 61 | end | 61 | end |
| 62 | ]] | 62 | ]] |
| 63 | end | 63 | end |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index dbd4174d..7b6505c2 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -28,8 +28,6 @@ local patch = require("luarocks.tools.patch") | |||
| 28 | 28 | ||
| 29 | local dir_stack = {} | 29 | local dir_stack = {} |
| 30 | 30 | ||
| 31 | local dir_separator = "/" | ||
| 32 | |||
| 33 | --- Test is file/dir is writable. | 31 | --- Test is file/dir is writable. |
| 34 | -- Warning: testing if a file/dir is writable does not guarantee | 32 | -- Warning: testing if a file/dir is writable does not guarantee |
| 35 | -- that it will remain writable and therefore it is no replacement | 33 | -- that it will remain writable and therefore it is no replacement |
| @@ -236,8 +234,8 @@ function fs_lua.make_dir(directory) | |||
| 236 | path = "" | 234 | path = "" |
| 237 | end | 235 | end |
| 238 | end | 236 | end |
| 239 | for d in directory:gmatch("([^"..dir.separator.."]+)"..dir.separator.."*") do | 237 | for d in directory:gmatch("([^/]+)/*") do |
| 240 | path = path and path .. dir.separator .. d or d | 238 | path = path and path .. "/" .. d or d |
| 241 | local mode = lfs.attributes(path, "mode") | 239 | local mode = lfs.attributes(path, "mode") |
| 242 | if not mode then | 240 | if not mode then |
| 243 | local ok, err = lfs.mkdir(path) | 241 | local ok, err = lfs.mkdir(path) |
| @@ -416,7 +414,7 @@ local function recursive_find(cwd, prefix, result) | |||
| 416 | table.insert(result, item) | 414 | table.insert(result, item) |
| 417 | local pathname = dir.path(cwd, file) | 415 | local pathname = dir.path(cwd, file) |
| 418 | if lfs.attributes(pathname, "mode") == "directory" then | 416 | if lfs.attributes(pathname, "mode") == "directory" then |
| 419 | recursive_find(pathname, item..dir_separator, result) | 417 | recursive_find(pathname, item.."/", result) |
| 420 | end | 418 | end |
| 421 | end | 419 | end |
| 422 | end | 420 | end |
| @@ -798,7 +796,7 @@ function fs_lua.make_temp_dir(name) | |||
| 798 | assert(type(name) == "string") | 796 | assert(type(name) == "string") |
| 799 | name = dir.normalize(name) | 797 | name = dir.normalize(name) |
| 800 | 798 | ||
| 801 | return posix.mkdtemp((os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX") | 799 | return posix.mkdtemp((os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub("/", "_") .. "-XXXXXX") |
| 802 | end | 800 | end |
| 803 | 801 | ||
| 804 | end | 802 | end |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index b2ace3b1..33ba911d 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
| @@ -230,7 +230,7 @@ function tools.make_temp_dir(name) | |||
| 230 | assert(type(name) == "string") | 230 | assert(type(name) == "string") |
| 231 | name = dir.normalize(name) | 231 | name = dir.normalize(name) |
| 232 | 232 | ||
| 233 | local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX" | 233 | local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub("/", "_") .. "-XXXXXX" |
| 234 | local pipe = io.popen(vars.MKTEMP.." -d "..fs.Q(template)) | 234 | local pipe = io.popen(vars.MKTEMP.." -d "..fs.Q(template)) |
| 235 | local dirname = pipe:read("*l") | 235 | local dirname = pipe:read("*l") |
| 236 | pipe:close() | 236 | pipe:close() |
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index bd504fa7..92068e39 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
| @@ -255,7 +255,7 @@ function win32.make_temp_dir(name) | |||
| 255 | assert(type(name) == "string") | 255 | assert(type(name) == "string") |
| 256 | name = dir.normalize(name) | 256 | name = dir.normalize(name) |
| 257 | 257 | ||
| 258 | local temp_dir = os.getenv("TMP") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) | 258 | local temp_dir = os.getenv("TMP") .. "/luarocks_" .. name:gsub("/", "_") .. "-" .. tostring(math.floor(math.random() * 10000)) |
| 259 | local ok, err = fs.make_dir(temp_dir) | 259 | local ok, err = fs.make_dir(temp_dir) |
| 260 | if ok then | 260 | if ok then |
| 261 | return temp_dir | 261 | return temp_dir |
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 37898435..d740331b 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
| @@ -200,7 +200,7 @@ end | |||
| 200 | -- @return string: A directory name using the platform's separator. | 200 | -- @return string: A directory name using the platform's separator. |
| 201 | function path.module_to_path(mod) | 201 | function path.module_to_path(mod) |
| 202 | assert(type(mod) == "string") | 202 | assert(type(mod) == "string") |
| 203 | return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) | 203 | return (mod:gsub("[^.]*$", ""):gsub("%.", "/")) |
| 204 | end | 204 | end |
| 205 | 205 | ||
| 206 | --- Set up path-related variables for a given rock. | 206 | --- Set up path-related variables for a given rock. |
