diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/build.lua | 12 | ||||
| -rw-r--r-- | src/luarocks/build/builtin.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/cache.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/fetch.lua | 9 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 28 | ||||
| -rw-r--r-- | src/luarocks/fs/unix/tools.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/pack.lua | 14 | ||||
| -rw-r--r-- | src/luarocks/repos.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/tools/tar.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/unpack.lua | 3 |
11 files changed, 63 insertions, 37 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index dbe450ab..40f02e38 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -56,14 +56,17 @@ local function install_files(files, location, is_module_path) | |||
| 56 | if type(k) == "string" then | 56 | if type(k) == "string" then |
| 57 | if is_module_path then | 57 | if is_module_path then |
| 58 | dest = dir.path(location, path.module_to_path(k)) | 58 | dest = dir.path(location, path.module_to_path(k)) |
| 59 | fs.make_dir(dest) | 59 | local ok, err = fs.make_dir(dest) |
| 60 | if not ok then return nil, err end | ||
| 60 | else | 61 | else |
| 61 | dest = dir.path(location, dir.dir_name(k)) | 62 | dest = dir.path(location, dir.dir_name(k)) |
| 62 | fs.make_dir(dest) | 63 | local ok, err = fs.make_dir(dest) |
| 64 | if not ok then return nil, err end | ||
| 63 | dest = dir.path(dest, dir.base_name(k)) | 65 | dest = dir.path(dest, dir.base_name(k)) |
| 64 | end | 66 | end |
| 65 | else | 67 | else |
| 66 | fs.make_dir(dest) | 68 | local ok, err = fs.make_dir(dest) |
| 69 | if not ok then return nil, err end | ||
| 67 | end | 70 | end |
| 68 | local ok = fs.copy(dir.path(file), dest) | 71 | local ok = fs.copy(dir.path(file), dest) |
| 69 | if not ok then | 72 | if not ok then |
| @@ -180,7 +183,8 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) | |||
| 180 | } | 183 | } |
| 181 | 184 | ||
| 182 | for _, d in pairs(dirs) do | 185 | for _, d in pairs(dirs) do |
| 183 | fs.make_dir(d.name) | 186 | local ok, err = fs.make_dir(d.name) |
| 187 | if not ok then return nil, err end | ||
| 184 | end | 188 | end |
| 185 | local rollback = util.schedule_function(function() | 189 | local rollback = util.schedule_function(function() |
| 186 | fs.delete(path.install_dir(name, version)) | 190 | fs.delete(path.install_dir(name, version)) |
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 9d97d58b..c96a2496 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
| @@ -224,7 +224,8 @@ function run(rockspec) | |||
| 224 | if not ok then break end | 224 | if not ok then break end |
| 225 | local module_name = dir.path(moddir, name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension)):gsub("//", "/") | 225 | local module_name = dir.path(moddir, name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension)):gsub("//", "/") |
| 226 | if moddir ~= "" then | 226 | if moddir ~= "" then |
| 227 | fs.make_dir(moddir) | 227 | local ok, err = fs.make_dir(moddir) |
| 228 | if not ok then return nil, err end | ||
| 228 | end | 229 | end |
| 229 | local dest = dir.path(libdir, moddir) | 230 | local dest = dir.path(libdir, moddir) |
| 230 | built_modules[module_name] = dest | 231 | built_modules[module_name] = dest |
| @@ -242,7 +243,7 @@ function run(rockspec) | |||
| 242 | end | 243 | end |
| 243 | end | 244 | end |
| 244 | if fs.is_dir("lua") then | 245 | if fs.is_dir("lua") then |
| 245 | ok, err = fs.copy_contents("lua", luadir) | 246 | local ok, err = fs.copy_contents("lua", luadir) |
| 246 | if not ok then | 247 | if not ok then |
| 247 | return nil, "Failed copying contents of 'lua' directory: "..err | 248 | return nil, "Failed copying contents of 'lua' directory: "..err |
| 248 | end | 249 | end |
diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua index 21185c10..fe74ba18 100644 --- a/src/luarocks/cache.lua +++ b/src/luarocks/cache.lua | |||
| @@ -53,11 +53,13 @@ end | |||
| 53 | function refresh_local_cache(server, url, user, password) | 53 | function refresh_local_cache(server, url, user, password) |
| 54 | local local_cache, protocol, server_path, user, password = split_server_url(server, url, user, password) | 54 | local local_cache, protocol, server_path, user, password = split_server_url(server, url, user, password) |
| 55 | 55 | ||
| 56 | fs.make_dir(cfg.local_cache) | 56 | local ok, err = fs.make_dir(cfg.local_cache) |
| 57 | if not ok then return nil, err end | ||
| 57 | 58 | ||
| 58 | local tmp_cache = false | 59 | local tmp_cache = false |
| 59 | if not local_cache then | 60 | if not local_cache then |
| 60 | local_cache = fs.make_temp_dir("local_cache") | 61 | local err |
| 62 | local_cache, err = fs.make_temp_dir("local_cache") | ||
| 61 | tmp_cache = true | 63 | tmp_cache = true |
| 62 | end | 64 | end |
| 63 | local ok = fs.make_dir(local_cache) | 65 | local ok = fs.make_dir(local_cache) |
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index bfdbacec..be2f32c6 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
| @@ -66,9 +66,9 @@ function fetch_url_at_temp_dir(url, tmpname, filename) | |||
| 66 | return nil, "File not found: "..pathname | 66 | return nil, "File not found: "..pathname |
| 67 | end | 67 | end |
| 68 | else | 68 | else |
| 69 | local temp_dir = fs.make_temp_dir(tmpname) | 69 | local temp_dir, err = fs.make_temp_dir(tmpname) |
| 70 | if not temp_dir then | 70 | if not temp_dir then |
| 71 | return nil, "Failed creating temporary directory." | 71 | return nil, "Failed creating temporary directory "..tmpname..": "..err |
| 72 | end | 72 | end |
| 73 | util.schedule_function(fs.delete, temp_dir) | 73 | util.schedule_function(fs.delete, temp_dir) |
| 74 | fs.change_dir(temp_dir) | 74 | fs.change_dir(temp_dir) |
| @@ -104,7 +104,10 @@ function fetch_and_unpack_rock(rock_file, dest) | |||
| 104 | local unpack_dir | 104 | local unpack_dir |
| 105 | if dest then | 105 | if dest then |
| 106 | unpack_dir = dest | 106 | unpack_dir = dest |
| 107 | fs.make_dir(unpack_dir) | 107 | local ok, err = fs.make_dir(unpack_dir) |
| 108 | if not ok then | ||
| 109 | return nil, "Failed unpacking rock file: " .. err | ||
| 110 | end | ||
| 108 | else | 111 | else |
| 109 | unpack_dir = fs.make_temp_dir(name) | 112 | unpack_dir = fs.make_temp_dir(name) |
| 110 | end | 113 | end |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 36b33690..7e208357 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -69,16 +69,17 @@ end | |||
| 69 | --- Create a temporary directory. | 69 | --- Create a temporary directory. |
| 70 | -- @param name string: name pattern to use for avoiding conflicts | 70 | -- @param name string: name pattern to use for avoiding conflicts |
| 71 | -- when creating temporary directory. | 71 | -- when creating temporary directory. |
| 72 | -- @return string or nil: name of temporary directory or nil on failure. | 72 | -- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. |
| 73 | function make_temp_dir(name) | 73 | function make_temp_dir(name) |
| 74 | assert(type(name) == "string") | 74 | assert(type(name) == "string") |
| 75 | name = dir.normalize(name) | 75 | name = dir.normalize(name) |
| 76 | 76 | ||
| 77 | local temp_dir = (os.getenv("TMP") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) | 77 | local temp_dir = (os.getenv("TMP") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) |
| 78 | if fs.make_dir(temp_dir) then | 78 | local ok, err = fs.make_dir(temp_dir) |
| 79 | if ok then | ||
| 79 | return temp_dir | 80 | return temp_dir |
| 80 | else | 81 | else |
| 81 | return nil | 82 | return nil, err |
| 82 | end | 83 | end |
| 83 | end | 84 | end |
| 84 | 85 | ||
| @@ -131,11 +132,7 @@ if lfs_ok then | |||
| 131 | function execute_string(cmd) | 132 | function execute_string(cmd) |
| 132 | if cfg.verbose then print("Executing: "..cmd) end | 133 | if cfg.verbose then print("Executing: "..cmd) end |
| 133 | local code = os.execute(cmd) | 134 | local code = os.execute(cmd) |
| 134 | if code == 0 or code == true then | 135 | return (code == 0 or code == true) |
| 135 | return true | ||
| 136 | else | ||
| 137 | return false | ||
| 138 | end | ||
| 139 | end | 136 | end |
| 140 | 137 | ||
| 141 | --- Obtain current directory. | 138 | --- Obtain current directory. |
| @@ -180,7 +177,7 @@ end | |||
| 180 | -- If any of the higher levels in the path name does not exist | 177 | -- If any of the higher levels in the path name does not exist |
| 181 | -- too, they are created as well. | 178 | -- too, they are created as well. |
| 182 | -- @param directory string: pathname of directory to create. | 179 | -- @param directory string: pathname of directory to create. |
| 183 | -- @return boolean: true on success, false on failure. | 180 | -- @return boolean or (boolean, string): true on success or (false, error message) on failure. |
| 184 | function make_dir(directory) | 181 | function make_dir(directory) |
| 185 | assert(type(directory) == "string") | 182 | assert(type(directory) == "string") |
| 186 | directory = dir.normalize(directory) | 183 | directory = dir.normalize(directory) |
| @@ -197,11 +194,12 @@ function make_dir(directory) | |||
| 197 | path = path and path .. dir.separator .. d or d | 194 | path = path and path .. dir.separator .. d or d |
| 198 | local mode = lfs.attributes(path, "mode") | 195 | local mode = lfs.attributes(path, "mode") |
| 199 | if not mode then | 196 | if not mode then |
| 200 | if not lfs.mkdir(path) then | 197 | local ok, err = lfs.mkdir(path) |
| 201 | return false | 198 | if not ok then |
| 199 | return false, err | ||
| 202 | end | 200 | end |
| 203 | elseif mode ~= "directory" then | 201 | elseif mode ~= "directory" then |
| 204 | return false | 202 | return false, path.." is not a directory" |
| 205 | end | 203 | end |
| 206 | end | 204 | end |
| 207 | return true | 205 | return true |
| @@ -274,7 +272,8 @@ local function recursive_copy(src, dest) | |||
| 274 | if not ok then return false end | 272 | if not ok then return false end |
| 275 | elseif srcmode == "directory" then | 273 | elseif srcmode == "directory" then |
| 276 | local subdir = dir.path(dest, dir.base_name(src)) | 274 | local subdir = dir.path(dest, dir.base_name(src)) |
| 277 | fs.make_dir(subdir) | 275 | local ok, err = fs.make_dir(subdir) |
| 276 | if not ok then return nil, err end | ||
| 278 | for file in lfs.dir(src) do | 277 | for file in lfs.dir(src) do |
| 279 | if file ~= "." and file ~= ".." then | 278 | if file ~= "." and file ~= ".." then |
| 280 | local ok = recursive_copy(dir.path(src, file), subdir) | 279 | local ok = recursive_copy(dir.path(src, file), subdir) |
| @@ -455,7 +454,8 @@ function unzip(zipfile) | |||
| 455 | local file = files() | 454 | local file = files() |
| 456 | repeat | 455 | repeat |
| 457 | if file.filename:sub(#file.filename) == "/" then | 456 | if file.filename:sub(#file.filename) == "/" then |
| 458 | fs.make_dir(dir.path(fs.current_dir(), file.filename)) | 457 | local ok, err = fs.make_dir(dir.path(fs.current_dir(), file.filename)) |
| 458 | if not ok then return nil, err end | ||
| 459 | else | 459 | else |
| 460 | local rf, err = zipfile:open(file.filename) | 460 | local rf, err = zipfile:open(file.filename) |
| 461 | if not rf then zipfile:close(); return nil, err end | 461 | if not rf then zipfile:close(); return nil, err end |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 3b853be7..23bd8161 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
| @@ -71,7 +71,11 @@ end | |||
| 71 | -- @return boolean: true on success, false on failure. | 71 | -- @return boolean: true on success, false on failure. |
| 72 | function make_dir(directory) | 72 | function make_dir(directory) |
| 73 | assert(directory) | 73 | assert(directory) |
| 74 | return fs.execute(vars.MKDIR.." -p", directory) | 74 | local ok, err = fs.execute(vars.MKDIR.." -p", directory) |
| 75 | if not ok then | ||
| 76 | err = "failed making directory "..directory | ||
| 77 | end | ||
| 78 | return ok, err | ||
| 75 | end | 79 | end |
| 76 | 80 | ||
| 77 | --- Remove a directory if it is empty. | 81 | --- Remove a directory if it is empty. |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 1af1dd91..97ba4fe5 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
| @@ -103,7 +103,10 @@ end | |||
| 103 | function make_dir(directory) | 103 | function make_dir(directory) |
| 104 | assert(directory) | 104 | assert(directory) |
| 105 | fs.execute(fs.quiet(vars.MKDIR.." "..fs.Q(directory))) | 105 | fs.execute(fs.quiet(vars.MKDIR.." "..fs.Q(directory))) |
| 106 | return 1 | 106 | if not fs.is_dir(directory) then |
| 107 | return false, "failed making directory "..directory | ||
| 108 | end | ||
| 109 | return true | ||
| 107 | end | 110 | end |
| 108 | 111 | ||
| 109 | --- Remove a directory if it is empty. | 112 | --- Remove a directory if it is empty. |
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 583932e0..ede992ce 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua | |||
| @@ -58,12 +58,14 @@ local function pack_source_rock(rockspec_file) | |||
| 58 | end | 58 | end |
| 59 | 59 | ||
| 60 | local function copy_back_files(name, version, file_tree, deploy_dir, pack_dir) | 60 | local function copy_back_files(name, version, file_tree, deploy_dir, pack_dir) |
| 61 | fs.make_dir(pack_dir) | 61 | local ok, err = fs.make_dir(pack_dir) |
| 62 | if not ok then return nil, err end | ||
| 62 | for file, sub in pairs(file_tree) do | 63 | for file, sub in pairs(file_tree) do |
| 63 | local source = dir.path(deploy_dir, file) | 64 | local source = dir.path(deploy_dir, file) |
| 64 | local target = dir.path(pack_dir, file) | 65 | local target = dir.path(pack_dir, file) |
| 65 | if type(sub) == "table" then | 66 | if type(sub) == "table" then |
| 66 | local ok, err = copy_back_files(name, version, sub, source, target) | 67 | local ok, err = copy_back_files(name, version, sub, source, target) |
| 68 | if not ok then return nil, err end | ||
| 67 | else | 69 | else |
| 68 | local versioned = path.versioned_name(source, deploy_dir, name, version) | 70 | local versioned = path.versioned_name(source, deploy_dir, name, version) |
| 69 | if fs.exists(versioned) then | 71 | if fs.exists(versioned) then |
| @@ -128,11 +130,13 @@ local function do_pack_binary_rock(name, version) | |||
| 128 | 130 | ||
| 129 | local is_binary = false | 131 | local is_binary = false |
| 130 | if rock_manifest.lib then | 132 | if rock_manifest.lib then |
| 131 | copy_back_files(name, version, rock_manifest.lib, path.deploy_lib_dir(root), dir.path(temp_dir, "lib")) | 133 | local ok, err = copy_back_files(name, version, rock_manifest.lib, path.deploy_lib_dir(root), dir.path(temp_dir, "lib")) |
| 134 | if not ok then return nil, "Failed copying back files: " .. err end | ||
| 132 | is_binary = true | 135 | is_binary = true |
| 133 | end | 136 | end |
| 134 | if rock_manifest.lua then | 137 | if rock_manifest.lua then |
| 135 | copy_back_files(name, version, rock_manifest.lua, path.deploy_lua_dir(root), dir.path(temp_dir, "lua")) | 138 | local ok, err = copy_back_files(name, version, rock_manifest.lua, path.deploy_lua_dir(root), dir.path(temp_dir, "lua")) |
| 139 | if not ok then return nil, "Failed copying back files: " .. err end | ||
| 136 | end | 140 | end |
| 137 | 141 | ||
| 138 | fs.change_dir(temp_dir) | 142 | fs.change_dir(temp_dir) |
| @@ -157,9 +161,9 @@ function pack_binary_rock(name, version, cmd, ...) | |||
| 157 | -- to shave off the final deploy steps from the build phase and the initial | 161 | -- to shave off the final deploy steps from the build phase and the initial |
| 158 | -- collect steps from the pack phase. | 162 | -- collect steps from the pack phase. |
| 159 | 163 | ||
| 160 | local temp_dir = fs.make_temp_dir("luarocks-build-pack-"..dir.base_name(name)) | 164 | local temp_dir, err = fs.make_temp_dir("luarocks-build-pack-"..dir.base_name(name)) |
| 161 | if not temp_dir then | 165 | if not temp_dir then |
| 162 | return nil, "Failed creating temporary directory." | 166 | return nil, "Failed creating temporary directory: "..err |
| 163 | end | 167 | end |
| 164 | util.schedule_function(fs.delete, temp_dir) | 168 | util.schedule_function(fs.delete, temp_dir) |
| 165 | 169 | ||
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index b7e64d42..c7b381df 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua | |||
| @@ -175,7 +175,8 @@ local function resolve_conflict(target, deploy_dir, name, version) | |||
| 175 | end | 175 | end |
| 176 | if name ~= cname or deps.compare_versions(version, cversion) then | 176 | if name ~= cname or deps.compare_versions(version, cversion) then |
| 177 | local versioned = path.versioned_name(target, deploy_dir, cname, cversion) | 177 | local versioned = path.versioned_name(target, deploy_dir, cname, cversion) |
| 178 | fs.make_dir(dir.dir_name(versioned)) | 178 | local ok, err = fs.make_dir(dir.dir_name(versioned)) |
| 179 | if not ok then return nil, err end | ||
| 179 | fs.move(target, versioned) | 180 | fs.move(target, versioned) |
| 180 | return target | 181 | return target |
| 181 | else | 182 | else |
| @@ -220,7 +221,8 @@ function deploy_files(name, version, wrap_bin_scripts) | |||
| 220 | target = new_target | 221 | target = new_target |
| 221 | end | 222 | end |
| 222 | end | 223 | end |
| 223 | fs.make_dir(dir.dir_name(target)) | 224 | ok, err = fs.make_dir(dir.dir_name(target)) |
| 225 | if not ok then return nil, err end | ||
| 224 | ok, err = move_fn(source, target, name, version) | 226 | ok, err = move_fn(source, target, name, version) |
| 225 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) | 227 | fs.remove_dir_tree_if_empty(dir.dir_name(source)) |
| 226 | if not ok then return nil, err end | 228 | if not ok then return nil, err end |
diff --git a/src/luarocks/tools/tar.lua b/src/luarocks/tools/tar.lua index ba01a413..0c68ab2f 100644 --- a/src/luarocks/tools/tar.lua +++ b/src/luarocks/tools/tar.lua | |||
| @@ -119,11 +119,13 @@ function untar(filename, destdir) | |||
| 119 | end | 119 | end |
| 120 | local pathname = dir.path(destdir, header.name) | 120 | local pathname = dir.path(destdir, header.name) |
| 121 | if header.typeflag == "directory" then | 121 | if header.typeflag == "directory" then |
| 122 | fs.make_dir(pathname) | 122 | local ok, err = fs.make_dir(pathname) |
| 123 | if not ok then return nil, err end | ||
| 123 | elseif header.typeflag == "file" then | 124 | elseif header.typeflag == "file" then |
| 124 | local dirname = dir.dir_name(pathname) | 125 | local dirname = dir.dir_name(pathname) |
| 125 | if dirname ~= "" then | 126 | if dirname ~= "" then |
| 126 | fs.make_dir(dirname) | 127 | local ok, err = fs.make_dir(dirname) |
| 128 | if not ok then return nil, err end | ||
| 127 | end | 129 | end |
| 128 | local file_handle = io.open(pathname, "wb") | 130 | local file_handle = io.open(pathname, "wb") |
| 129 | file_handle:write(file_data) | 131 | file_handle:write(file_data) |
diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua index 67153812..67db5ca5 100644 --- a/src/luarocks/unpack.lua +++ b/src/luarocks/unpack.lua | |||
| @@ -99,7 +99,8 @@ local function run_unpacker(file) | |||
| 99 | if (fs.exists(dir_name)) then | 99 | if (fs.exists(dir_name)) then |
| 100 | return nil, "Directory "..dir_name.." already exists." | 100 | return nil, "Directory "..dir_name.." already exists." |
| 101 | end | 101 | end |
| 102 | fs.make_dir(dir_name) | 102 | local ok, err = fs.make_dir(dir_name) |
| 103 | if not ok then return nil, err end | ||
| 103 | local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name)) | 104 | local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name)) |
| 104 | 105 | ||
| 105 | local rockspec, err | 106 | local rockspec, err |
