diff options
| author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-04 19:47:11 +0000 |
|---|---|---|
| committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-10-04 19:47:11 +0000 |
| commit | 230da1deaefff2404e0ea4aa380c2e7cda306733 (patch) | |
| tree | 5be922f2abfb94386e8a6ffcfbd279bc920e6e94 /src | |
| parent | c9c83162748bea1f9c1b6574ce3cc6560e5490b4 (diff) | |
| download | luarocks-230da1deaefff2404e0ea4aa380c2e7cda306733.tar.gz luarocks-230da1deaefff2404e0ea4aa380c2e7cda306733.tar.bz2 luarocks-230da1deaefff2404e0ea4aa380c2e7cda306733.zip | |
Implement deployment and removal of files
git-svn-id: http://luarocks.org/svn/luarocks/trunk@63 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fs/lua.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 36 | ||||
| -rw-r--r-- | src/luarocks/path.lua | 17 | ||||
| -rw-r--r-- | src/luarocks/rep.lua | 154 |
4 files changed, 152 insertions, 57 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index dd9857a0..c7d7fb2a 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -511,7 +511,7 @@ end | |||
| 511 | -- plus an error message. | 511 | -- plus an error message. |
| 512 | function move(src, dest) | 512 | function move(src, dest) |
| 513 | assert(src and dest) | 513 | assert(src and dest) |
| 514 | if fs.exists(dest) then | 514 | if fs.exists(dest) and not fs.is_dir(dest) then |
| 515 | return false, "File already exists: "..dest | 515 | return false, "File already exists: "..dest |
| 516 | end | 516 | end |
| 517 | local ok, err = fs.copy(src, dest) | 517 | local ok, err = fs.copy(src, dest) |
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index de885ca5..e3e2728b 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -293,9 +293,41 @@ function update_manifest(name, version, repo) | |||
| 293 | 293 | ||
| 294 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} | 294 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} |
| 295 | 295 | ||
| 296 | print("TODO LR2 update manifest") | ||
| 297 | |||
| 298 | store_results(results, manifest) | 296 | store_results(results, manifest) |
| 299 | 297 | ||
| 300 | return save_table(repo, "manifest", manifest) | 298 | return save_table(repo, "manifest", manifest) |
| 301 | end | 299 | end |
| 300 | |||
| 301 | --- Given a path of a deployed file, figure out which rock name and version | ||
| 302 | -- correspond to it in the tree manifest. | ||
| 303 | -- @param file string: The full path of a deployed file. | ||
| 304 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. | ||
| 305 | -- @return string, string: name and version of the provider rock. | ||
| 306 | function find_current_provider(file, root) | ||
| 307 | assert(type(file) == "string") | ||
| 308 | assert(type(root) == "string" or not root) | ||
| 309 | root = root or cfg.root_dir | ||
| 310 | |||
| 311 | local manifest = manif_core.load_local_manifest(path.rocks_dir(root)) | ||
| 312 | local deploy_bin = path.deploy_bin_dir(root) | ||
| 313 | local deploy_lua = path.deploy_lua_dir(root) | ||
| 314 | local deploy_lib = path.deploy_lib_dir(root) | ||
| 315 | local key, manifest_tbl | ||
| 316 | |||
| 317 | if file:match("^"..deploy_bin) then | ||
| 318 | manifest_tbl = manifest.commands | ||
| 319 | key = file:sub(#deploy_bin+1) | ||
| 320 | elseif file:match("^"..deploy_lua) then | ||
| 321 | manifest_tbl = manifest.modules | ||
| 322 | key = path.path_to_module(file:sub(#deploy_lua+1)) | ||
| 323 | elseif file:match("^"..deploy_lib) then | ||
| 324 | manifest_tbl = manifest.modules | ||
| 325 | key = path.path_to_module(file:sub(#deploy_lib+1)) | ||
| 326 | end | ||
| 327 | |||
| 328 | local providers = manifest_tbl[key] | ||
| 329 | if not providers then | ||
| 330 | return nil, "File "..file.." is not tracked by LuaRocks." | ||
| 331 | end | ||
| 332 | return providers[1]:match("([^/]*)/([^/]*)") | ||
| 333 | end | ||
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index f62ff230..b63eaa43 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
| @@ -216,6 +216,7 @@ function path_to_module(file) | |||
| 216 | name = name:gsub(dir.separator, ".") | 216 | name = name:gsub(dir.separator, ".") |
| 217 | end | 217 | end |
| 218 | end | 218 | end |
| 219 | name = name:gsub("^%.+", ""):gsub("%.+$", "") | ||
| 219 | return name | 220 | return name |
| 220 | end | 221 | end |
| 221 | 222 | ||
| @@ -247,3 +248,19 @@ function configure_paths(rockspec) | |||
| 247 | vars.DOCDIR = doc_dir(name, version) | 248 | vars.DOCDIR = doc_dir(name, version) |
| 248 | rockspec.variables = vars | 249 | rockspec.variables = vars |
| 249 | end | 250 | end |
| 251 | |||
| 252 | function versioned_name(file, name, version) | ||
| 253 | assert(type(file) == "string") | ||
| 254 | assert(type(name) == "string") | ||
| 255 | assert(type(version) == "string") | ||
| 256 | |||
| 257 | name = name:gsub("%-", "_") | ||
| 258 | version = version:gsub("%-", "_") | ||
| 259 | return dir.path(dir.dir_name(file), name.."_"..version.."-"..dir.base_name(file)) | ||
| 260 | end | ||
| 261 | |||
| 262 | function unversioned_name(file) | ||
| 263 | assert(type(file) == "string") | ||
| 264 | |||
| 265 | return dir.path(dir.dir_name(file), dir.base_name(file):match("^[^-]+-(.*)")) | ||
| 266 | end | ||
diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua index 0a2e9cbb..8d3ecfb2 100644 --- a/src/luarocks/rep.lua +++ b/src/luarocks/rep.lua | |||
| @@ -8,6 +8,7 @@ local cfg = require("luarocks.cfg") | |||
| 8 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| 9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
| 10 | local manif = require("luarocks.manif") | 10 | local manif = require("luarocks.manif") |
| 11 | local deps = require("luarocks.deps") | ||
| 11 | 12 | ||
| 12 | --- Get all installed versions of a package. | 13 | --- Get all installed versions of a package. |
| 13 | -- @param name string: a package name. | 14 | -- @param name string: a package name. |
| @@ -32,21 +33,6 @@ function is_installed(name, version) | |||
| 32 | 33 | ||
| 33 | return fs.is_dir(path.install_dir(name, version)) | 34 | return fs.is_dir(path.install_dir(name, version)) |
| 34 | end | 35 | end |
| 35 | |||
| 36 | --- Delete a package from the local repository. | ||
| 37 | -- Version numbers are compared as exact string comparison. | ||
| 38 | -- @param name string: name of package | ||
| 39 | -- @param version string: package version in string format | ||
| 40 | function delete_version(name, version) | ||
| 41 | assert(type(name) == "string") | ||
| 42 | assert(type(version) == "string") | ||
| 43 | |||
| 44 | fs.delete(path.install_dir(name, version)) | ||
| 45 | print("TODO LR2 remove deployed files based on rock_manifest") | ||
| 46 | if not get_versions(name) then | ||
| 47 | fs.delete(dir.path(cfg.rocks_dir, name)) | ||
| 48 | end | ||
| 49 | end | ||
| 50 | 36 | ||
| 51 | --[[ | 37 | --[[ |
| 52 | --- Install bin entries in the repository bin dir. | 38 | --- Install bin entries in the repository bin dir. |
| @@ -121,8 +107,6 @@ function package_modules(package, version) | |||
| 121 | local result = {} | 107 | local result = {} |
| 122 | local rock_manifest = manif.load_rock_manifest(package, version) | 108 | local rock_manifest = manif.load_rock_manifest(package, version) |
| 123 | 109 | ||
| 124 | print(pkg, version, util.show_table(rock_manifest)) | ||
| 125 | |||
| 126 | if rock_manifest.lib then | 110 | if rock_manifest.lib then |
| 127 | for name,sub in pairs(rock_manifest.lib) do | 111 | for name,sub in pairs(rock_manifest.lib) do |
| 128 | store_package_data(result, name, sub, "", "") | 112 | store_package_data(result, name, sub, "", "") |
| @@ -202,35 +186,6 @@ function run_hook(rockspec, hook_name) | |||
| 202 | return true | 186 | return true |
| 203 | end | 187 | end |
| 204 | 188 | ||
| 205 | local function deploy_file_tree(file_tree, source_dir, deploy_dir, move_fn) | ||
| 206 | assert(type(file_tree) == "table") | ||
| 207 | assert(type(source_dir) == "string") | ||
| 208 | assert(type(deploy_dir) == "string") | ||
| 209 | assert(type(move_fn) == "function" or not move_fn) | ||
| 210 | |||
| 211 | print("TODO LR2 actually fs.move") | ||
| 212 | if not move_fn then move_fn = fs.copy end | ||
| 213 | |||
| 214 | local ok, err = fs.make_dir(deploy_dir) | ||
| 215 | if not ok then | ||
| 216 | return nil, "Could not create "..deploy_dir | ||
| 217 | end | ||
| 218 | for file, sub in pairs(file_tree) do | ||
| 219 | if type(sub) == "table" then | ||
| 220 | ok, err = deploy_file_tree(sub, dir.path(source_dir, file), dir.path(deploy_dir, file)) | ||
| 221 | if not ok then return nil, err end | ||
| 222 | else | ||
| 223 | local target = dir.path(deploy_dir, file) | ||
| 224 | if fs.exists(target) then | ||
| 225 | print("TODO LR2 make_way_for_new_version(target)") | ||
| 226 | end | ||
| 227 | local source = dir.path(source_dir, file) | ||
| 228 | ok, err = move_fn(source, deploy_dir) | ||
| 229 | if not ok then return nil, err end | ||
| 230 | end | ||
| 231 | end | ||
| 232 | end | ||
| 233 | |||
| 234 | local function install_binary(source, target) | 189 | local function install_binary(source, target) |
| 235 | assert(type(source) == "string") | 190 | assert(type(source) == "string") |
| 236 | assert(type(target) == "string") | 191 | assert(type(target) == "string") |
| @@ -249,22 +204,113 @@ local function install_binary(source, target) | |||
| 249 | return ok, err | 204 | return ok, err |
| 250 | end | 205 | end |
| 251 | 206 | ||
| 207 | local function resolve_conflict(name, version, target) | ||
| 208 | local cname, cversion = manif.find_current_provider(target) | ||
| 209 | if not cname then | ||
| 210 | return nil, cversion | ||
| 211 | end | ||
| 212 | if name ~= cname or deps.compare_versions(version, cversion) then | ||
| 213 | print("MOVE EXISTING, MAKE WAY FOR NEW") | ||
| 214 | fs.move(target, path.versioned_name(target, cname, cversion)) | ||
| 215 | return target | ||
| 216 | else | ||
| 217 | print("INSTALL NEW WITH DIFFERENT NAME") | ||
| 218 | return path.versioned_name(target, name, version) | ||
| 219 | end | ||
| 220 | end | ||
| 221 | |||
| 252 | function deploy_files(name, version) | 222 | function deploy_files(name, version) |
| 253 | assert(type(name) == "string") | 223 | assert(type(name) == "string") |
| 254 | assert(type(version) == "string") | 224 | assert(type(version) == "string") |
| 225 | |||
| 226 | local function deploy_file_tree(file_tree, source_dir, deploy_dir, move_fn) | ||
| 227 | assert(type(file_tree) == "table") | ||
| 228 | assert(type(source_dir) == "string") | ||
| 229 | assert(type(deploy_dir) == "string") | ||
| 230 | assert(type(move_fn) == "function" or not move_fn) | ||
| 231 | |||
| 232 | if not move_fn then move_fn = fs.move end | ||
| 233 | |||
| 234 | local ok, err = fs.make_dir(deploy_dir) | ||
| 235 | if not ok then | ||
| 236 | return nil, "Could not create "..deploy_dir | ||
| 237 | end | ||
| 238 | for file, sub in pairs(file_tree) do | ||
| 239 | local target = dir.path(deploy_dir, file) | ||
| 240 | if type(sub) == "table" then | ||
| 241 | ok, err = deploy_file_tree(sub, dir.path(source_dir, file), dir.path(deploy_dir, file)) | ||
| 242 | if not ok then return nil, err end | ||
| 243 | fs.remove_dir_if_empty(target) | ||
| 244 | else | ||
| 245 | if fs.exists(target) then | ||
| 246 | target, err = resolve_conflict(name, version, target) | ||
| 247 | if err then return nil, err.." Cannot install new version." end | ||
| 248 | end | ||
| 249 | local source = dir.path(source_dir, file) | ||
| 250 | ok, err = move_fn(source, target) | ||
| 251 | if not ok then return nil, err end | ||
| 252 | end | ||
| 253 | end | ||
| 254 | return true | ||
| 255 | end | ||
| 255 | 256 | ||
| 256 | local rock_manifest = manif.load_rock_manifest(name, version) | 257 | local rock_manifest = manif.load_rock_manifest(name, version) |
| 257 | 258 | ||
| 259 | local ok, err = true | ||
| 258 | if rock_manifest.bin then | 260 | if rock_manifest.bin then |
| 259 | local ok, err = deploy_file_tree(rock_manifest.bin, path_bin_dir(name, version), cfg.deploy_bin_dir, install_binary) | 261 | ok, err = deploy_file_tree(rock_manifest.bin, path_bin_dir(name, version), cfg.deploy_bin_dir, install_binary) |
| 260 | if err then return nil, err end | ||
| 261 | end | 262 | end |
| 262 | if rock_manifest.lua then | 263 | if ok and rock_manifest.lua then |
| 263 | local ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir(name, version), cfg.deploy_lua_dir) | 264 | ok, err = deploy_file_tree(rock_manifest.lua, path.lua_dir(name, version), cfg.deploy_lua_dir) |
| 264 | if err then return nil, err end | ||
| 265 | end | 265 | end |
| 266 | if rock_manifest.lib then | 266 | if ok and rock_manifest.lib then |
| 267 | local ok, err = deploy_file_tree(rock_manifest.lib, path.lib_dir(name, version), cfg.deploy_lib_dir) | 267 | ok, err = deploy_file_tree(rock_manifest.lib, path.lib_dir(name, version), cfg.deploy_lib_dir) |
| 268 | if err then return nil, err end | ||
| 269 | end | 268 | end |
| 269 | return ok, err | ||
| 270 | end | ||
| 271 | |||
| 272 | --- Delete a package from the local repository. | ||
| 273 | -- Version numbers are compared as exact string comparison. | ||
| 274 | -- @param name string: name of package | ||
| 275 | -- @param version string: package version in string format | ||
| 276 | function delete_version(name, version) | ||
| 277 | assert(type(name) == "string") | ||
| 278 | assert(type(version) == "string") | ||
| 279 | |||
| 280 | local function delete_deployed_file_tree(file_tree, deploy_dir) | ||
| 281 | for file, sub in pairs(file_tree) do | ||
| 282 | local target = dir.path(deploy_dir, file) | ||
| 283 | if type(sub) == "table" then | ||
| 284 | local ok, err = delete_deployed_file_tree(sub, dir.path(deploy_dir, file)) | ||
| 285 | fs.remove_dir_if_empty(target) | ||
| 286 | else | ||
| 287 | local versioned = path.versioned_name(target, name, version) | ||
| 288 | if fs.exists(versioned) then | ||
| 289 | fs.delete(versioned) | ||
| 290 | else | ||
| 291 | fs.delete(target) | ||
| 292 | end | ||
| 293 | end | ||
| 294 | end | ||
| 295 | return true | ||
| 296 | end | ||
| 297 | |||
| 298 | local rock_manifest = manif.load_rock_manifest(name, version) | ||
| 299 | local ok, err = true | ||
| 300 | if rock_manifest.bin then | ||
| 301 | ok, err = delete_deployed_file_tree(rock_manifest.bin, cfg.deploy_bin_dir) | ||
| 302 | end | ||
| 303 | if ok and rock_manifest.lua then | ||
| 304 | ok, err = delete_deployed_file_tree(rock_manifest.lua, cfg.deploy_lua_dir) | ||
| 305 | end | ||
| 306 | if ok and rock_manifest.lib then | ||
| 307 | ok, err = delete_deployed_file_tree(rock_manifest.lib, cfg.deploy_lib_dir) | ||
| 308 | end | ||
| 309 | if err then return nil, err end | ||
| 310 | |||
| 311 | fs.delete(path.install_dir(name, version)) | ||
| 312 | if not get_versions(name) then | ||
| 313 | fs.delete(dir.path(cfg.rocks_dir, name)) | ||
| 314 | end | ||
| 315 | return true | ||
| 270 | end | 316 | end |
