From afcba75d2772e664b69698390c8000210b203175 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 8 Oct 2017 00:52:24 -0300 Subject: Dir separator is always "/". The code was already effectively using "/" as the only directory separator, even on Windows. This commit removes the unnecessary indirection. --- src/luarocks/cmd/build.lua | 2 +- src/luarocks/core/dir.lua | 2 -- src/luarocks/core/path.lua | 6 +++--- src/luarocks/fs/lua.lua | 10 ++++------ src/luarocks/fs/unix/tools.lua | 2 +- src/luarocks/fs/win32.lua | 2 +- 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) return build_rock(name, true, deps_mode, build_only_deps) elseif name:match("%.rock$") then return build_rock(name, true, deps_mode, build_only_deps) - elseif not name:match(dir.separator) then + elseif not name:match("/") then local search = require("luarocks.search") return search.act_on_src_or_rockspec(do_build, name:lower(), version, nil, deps_mode, build_only_deps) 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 = {} local require = nil -------------------------------------------------------------------------------- -dir.separator = "/" - --- Describe a path in a cross-platform way. -- Use this function to avoid platform-specific directory -- 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) local name = file:match("(.*)%."..cfg.lua_extension.."$") if name then - name = name:gsub(dir.separator, ".") + name = name:gsub("/", ".") local init = name:match("(.*)%.init$") if init then name = init @@ -52,12 +52,12 @@ function path.path_to_module(file) else name = file:match("(.*)%."..cfg.lib_extension.."$") if name then - name = name:gsub(dir.separator, ".") + name = name:gsub("/", ".") --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. else name = file:match("(.*)%."..cfg.static_lib_extension.."$") if name then - name = name:gsub(dir.separator, ".") + name = name:gsub("/", ".") end ]] 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") local dir_stack = {} -local dir_separator = "/" - --- Test is file/dir is writable. -- Warning: testing if a file/dir is writable does not guarantee -- that it will remain writable and therefore it is no replacement @@ -236,8 +234,8 @@ function fs_lua.make_dir(directory) path = "" end end - for d in directory:gmatch("([^"..dir.separator.."]+)"..dir.separator.."*") do - path = path and path .. dir.separator .. d or d + for d in directory:gmatch("([^/]+)/*") do + path = path and path .. "/" .. d or d local mode = lfs.attributes(path, "mode") if not mode then local ok, err = lfs.mkdir(path) @@ -416,7 +414,7 @@ local function recursive_find(cwd, prefix, result) table.insert(result, item) local pathname = dir.path(cwd, file) if lfs.attributes(pathname, "mode") == "directory" then - recursive_find(pathname, item..dir_separator, result) + recursive_find(pathname, item.."/", result) end end end @@ -798,7 +796,7 @@ function fs_lua.make_temp_dir(name) assert(type(name) == "string") name = dir.normalize(name) - return posix.mkdtemp((os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX") + return posix.mkdtemp((os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub("/", "_") .. "-XXXXXX") end 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) assert(type(name) == "string") name = dir.normalize(name) - local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX" + local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub("/", "_") .. "-XXXXXX" local pipe = io.popen(vars.MKTEMP.." -d "..fs.Q(template)) local dirname = pipe:read("*l") 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) assert(type(name) == "string") name = dir.normalize(name) - local temp_dir = os.getenv("TMP") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) + local temp_dir = os.getenv("TMP") .. "/luarocks_" .. name:gsub("/", "_") .. "-" .. tostring(math.floor(math.random() * 10000)) local ok, err = fs.make_dir(temp_dir) if ok then 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 -- @return string: A directory name using the platform's separator. function path.module_to_path(mod) assert(type(mod) == "string") - return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) + return (mod:gsub("[^.]*$", ""):gsub("%.", "/")) end --- Set up path-related variables for a given rock. -- cgit v1.2.3-55-g6feb