diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-14 01:52:06 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-14 01:52:06 +0300 |
commit | a1f44b94b20dd1048607eca5a212558602eb7076 (patch) | |
tree | cfc92ea0378e9226de04bf79cf18ee12ad2c7b77 | |
parent | c7b03dea26827e1d526d06e7f5c3b8b86ce1fe05 (diff) | |
download | luarocks-a1f44b94b20dd1048607eca5a212558602eb7076.tar.gz luarocks-a1f44b94b20dd1048607eca5a212558602eb7076.tar.bz2 luarocks-a1f44b94b20dd1048607eca5a212558602eb7076.zip |
writer
-rw-r--r-- | src/luarocks/core/cfg.d.tl | 2 | ||||
-rw-r--r-- | src/luarocks/fs.d.tl | 3 | ||||
-rw-r--r-- | src/luarocks/manif/writer.tl | 134 | ||||
-rw-r--r-- | src/luarocks/path.tl | 2 | ||||
-rw-r--r-- | src/luarocks/repo_writer.tl | 3 | ||||
-rw-r--r-- | src/luarocks/search.tl | 2 |
6 files changed, 108 insertions, 38 deletions
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index 9c4d0e3f..2c32569a 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl | |||
@@ -77,6 +77,8 @@ local record cfg | |||
77 | hooks_enabled: boolean | 77 | hooks_enabled: boolean |
78 | wrap_bin_scripts: boolean | 78 | wrap_bin_scripts: boolean |
79 | wrapper_suffix: string | 79 | wrapper_suffix: string |
80 | -- writer | ||
81 | no_manifest: boolean | ||
80 | end | 82 | end |
81 | 83 | ||
82 | return cfg \ No newline at end of file | 84 | return cfg \ No newline at end of file |
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index 4868889c..73848524 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl | |||
@@ -56,6 +56,9 @@ local record fs | |||
56 | is_lua: function(string): boolean | 56 | is_lua: function(string): boolean |
57 | copy_binary: function(string, string): boolean, string | 57 | copy_binary: function(string, string): boolean, string |
58 | move: function(string, string, string): boolean, string | 58 | move: function(string, string, string): boolean, string |
59 | -- writer | ||
60 | replace_file: function(string, string): boolean, string | ||
61 | get_md5: function(string): string | ||
59 | end | 62 | end |
60 | 63 | ||
61 | return fs | 64 | return fs |
diff --git a/src/luarocks/manif/writer.tl b/src/luarocks/manif/writer.tl index 0461b230..2b303fd5 100644 --- a/src/luarocks/manif/writer.tl +++ b/src/luarocks/manif/writer.tl | |||
@@ -22,6 +22,12 @@ local type Manifest = m.Manifest | |||
22 | local type r = require("luarocks.core.types.rockspec") | 22 | local type r = require("luarocks.core.types.rockspec") |
23 | local type Rockspec = r.Rockspec | 23 | local type Rockspec = r.Rockspec |
24 | 24 | ||
25 | local type res = require("luarocks.core.types.result") | ||
26 | local type Result = res.Result | ||
27 | |||
28 | local type p = require("luarocks.core.types.persist") | ||
29 | local type PersistableTable = p.PersistableTable | ||
30 | |||
25 | --- Update storage table to account for items provided by a package. | 31 | --- Update storage table to account for items provided by a package. |
26 | -- @param storage table: a table storing items in the following format: | 32 | -- @param storage table: a table storing items in the following format: |
27 | -- keys are item names and values are arrays of packages providing each item, | 33 | -- keys are item names and values are arrays of packages providing each item, |
@@ -204,16 +210,14 @@ end | |||
204 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). | 210 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). |
205 | -- It will be altered to include the search results. | 211 | -- It will be altered to include the search results. |
206 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. | 212 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. |
207 | local function store_results(results, manifest) | 213 | local function store_results(results: {string: {string: {Result}}}, manifest: Manifest): boolean, string |
208 | assert(type(results) == "table") | ||
209 | assert(type(manifest) == "table") | ||
210 | 214 | ||
211 | for name, versions in pairs(results) do | 215 | for name, versions in pairs(results) do |
212 | local pkgtable = manifest.repository[name] or {} | 216 | local pkgtable = manifest.repository[name] or {} |
213 | for version, entries in pairs(versions) do | 217 | for version, entries in pairs(versions) do |
214 | local versiontable = {} | 218 | local versiontable = {} |
215 | for _, entry in ipairs(entries) do | 219 | for _, entry in ipairs(entries) do |
216 | local entrytable = {} | 220 | local entrytable: Manifest = {} |
217 | entrytable.arch = entry.arch | 221 | entrytable.arch = entry.arch |
218 | if entry.arch == "installed" then | 222 | if entry.arch == "installed" then |
219 | local rock_manifest, err = manif.load_rock_manifest(name, version) | 223 | local rock_manifest, err = manif.load_rock_manifest(name, version) |
@@ -235,16 +239,46 @@ local function store_results(results, manifest) | |||
235 | return true | 239 | return true |
236 | end | 240 | end |
237 | 241 | ||
242 | -- and here what would `entrytable` be, since it can either be a `Manifest` or ... | ||
243 | -- ``` | ||
244 | -- local function store_results(results: {string: {string: {Result}}}, manifest: Manifest): boolean | ||
245 | |||
246 | -- for name, versions in pairs(results) do | ||
247 | -- local pkgtable = manifest.repository[name] or {} | ||
248 | -- for version, entries in pairs(versions) do | ||
249 | -- local versiontable = {} | ||
250 | -- for _, entry in ipairs(entries) do | ||
251 | -- local entrytable: Manifest = {} | ||
252 | -- entrytable.arch = entry.arch | ||
253 | -- if entry.arch == "installed" then | ||
254 | -- local rock_manifest, err = manif.load_rock_manifest(name, version) | ||
255 | -- if not rock_manifest then return nil, err end | ||
256 | |||
257 | -- entrytable.modules = repos.package_modules(name, version) | ||
258 | -- store_package_items(manifest.modules, name, version, entrytable.modules) | ||
259 | -- entrytable.commands = repos.package_commands(name, version) | ||
260 | -- store_package_items(manifest.commands, name, version, entrytable.commands) | ||
261 | -- end | ||
262 | -- table.insert(versiontable, entrytable) | ||
263 | -- end | ||
264 | -- pkgtable[version] = versiontable | ||
265 | -- end | ||
266 | -- manifest.repository[name] = pkgtable | ||
267 | -- end | ||
268 | -- sort_package_matching_table(manifest.modules) | ||
269 | -- sort_package_matching_table(manifest.commands) | ||
270 | -- return true | ||
271 | -- end | ||
272 | -- ``` | ||
273 | |||
238 | --- Commit a table to disk in given local path. | 274 | --- Commit a table to disk in given local path. |
239 | -- @param where string: The directory where the table should be saved. | 275 | -- @param where string: The directory where the table should be saved. |
240 | -- @param name string: The filename. | 276 | -- @param name string: The filename. |
241 | -- @param tbl table: The table to be saved. | 277 | -- @param tbl table: The table to be saved. |
242 | -- @return boolean or (nil, string): true if successful, or nil and a | 278 | -- @return boolean or (nil, string): true if successful, or nil and a |
243 | -- message in case of errors. | 279 | -- message in case of errors. |
244 | local function save_table(where, name, tbl) | 280 | local function save_table(where: string, name: string, tbl: PersistableTable): boolean, string |
245 | assert(type(where) == "string") | 281 | assert(not name:match("/")) |
246 | assert(type(name) == "string" and not name:match("/")) | ||
247 | assert(type(tbl) == "table") | ||
248 | 282 | ||
249 | local filename = dir.path(where, name) | 283 | local filename = dir.path(where, name) |
250 | local ok, err = persist.save_from_table(filename..".tmp", tbl) | 284 | local ok, err = persist.save_from_table(filename..".tmp", tbl) |
@@ -254,16 +288,17 @@ local function save_table(where, name, tbl) | |||
254 | return ok, err | 288 | return ok, err |
255 | end | 289 | end |
256 | 290 | ||
257 | function writer.make_rock_manifest(name, version) | 291 | function writer.make_rock_manifest(name: string, version: string): boolean, string |
258 | local install_dir = path.install_dir(name, version) | 292 | local install_dir = path.install_dir(name, version) |
259 | local tree = {} | 293 | local tree: {string: {string}} = {} |
260 | for _, file in ipairs(fs.find(install_dir)) do | 294 | for _, file in ipairs(fs.find(install_dir)) do |
261 | local full_path = dir.path(install_dir, file) | 295 | local full_path = dir.path(install_dir, file) |
262 | local walk = tree | 296 | local walk = tree |
263 | local last | 297 | local last: {string : {string}} |
264 | local last_name | 298 | local last_name: string |
299 | local next: {string} | ||
265 | for filename in file:gmatch("[^\\/]+") do | 300 | for filename in file:gmatch("[^\\/]+") do |
266 | local next = walk[filename] | 301 | next = walk[filename] |
267 | if not next then | 302 | if not next then |
268 | next = {} | 303 | next = {} |
269 | walk[filename] = next | 304 | walk[filename] = next |
@@ -286,16 +321,50 @@ function writer.make_rock_manifest(name, version) | |||
286 | return true | 321 | return true |
287 | end | 322 | end |
288 | 323 | ||
324 | -- in this code, what would next and walk be, since we have `walk[filename] = next`, but also `walk = next` | ||
325 | -- ``` | ||
326 | -- function writer.make_rock_manifest(name: string, version: string): boolean, string | ||
327 | -- local install_dir = path.install_dir(name, version) | ||
328 | -- local tree: {string: {string}} = {} | ||
329 | -- for _, file in ipairs(fs.find(install_dir)) do | ||
330 | -- local full_path = dir.path(install_dir, file) | ||
331 | -- local walk = tree | ||
332 | -- local last: {string : {string}} | ||
333 | -- local last_name: string | ||
334 | -- local next: {string} | ||
335 | -- for filename in file:gmatch("[^\\/]+") do | ||
336 | -- next = walk[filename] | ||
337 | -- if not next then | ||
338 | -- next = {} | ||
339 | -- walk[filename] = next | ||
340 | -- end | ||
341 | -- last = walk | ||
342 | -- last_name = filename | ||
343 | -- walk = next | ||
344 | -- end | ||
345 | -- if fs.is_file(full_path) then | ||
346 | -- local sum, err = fs.get_md5(full_path) | ||
347 | -- if not sum then | ||
348 | -- return nil, "Failed producing checksum: "..tostring(err) | ||
349 | -- end | ||
350 | -- last[last_name] = sum | ||
351 | -- end | ||
352 | -- end | ||
353 | -- local rock_manifest = { rock_manifest=tree } | ||
354 | -- manif.rock_manifest_cache[name.."/"..version] = rock_manifest | ||
355 | -- save_table(install_dir, "rock_manifest", rock_manifest ) | ||
356 | -- return true | ||
357 | -- end | ||
358 | -- ``` | ||
359 | |||
289 | -- Writes a 'rock_namespace' file in a locally installed rock directory. | 360 | -- Writes a 'rock_namespace' file in a locally installed rock directory. |
290 | -- @param name string: the rock name, without a namespace | 361 | -- @param name string: the rock name, without a namespace |
291 | -- @param version string: the rock version | 362 | -- @param version string: the rock version |
292 | -- @param namespace string?: the namespace | 363 | -- @param namespace string?: the namespace |
293 | -- @return true if successful (or unnecessary, if there is no namespace), | 364 | -- @return true if successful (or unnecessary, if there is no namespace), |
294 | -- or nil and an error message. | 365 | -- or nil and an error message. |
295 | function writer.make_namespace_file(name, version, namespace) | 366 | function writer.make_namespace_file(name: string, version: string, namespace?: string): boolean, string |
296 | assert(type(name) == "string" and not name:match("/")) | 367 | assert(not name:match("/")) |
297 | assert(type(version) == "string") | ||
298 | assert(type(namespace) == "string" or not namespace) | ||
299 | if not namespace then | 368 | if not namespace then |
300 | return true | 369 | return true |
301 | end | 370 | end |
@@ -321,9 +390,7 @@ end | |||
321 | -- @param remote boolean: 'true' if making a manifest for a rocks server. | 390 | -- @param remote boolean: 'true' if making a manifest for a rocks server. |
322 | -- @return boolean or (nil, string): True if manifest was generated, | 391 | -- @return boolean or (nil, string): True if manifest was generated, |
323 | -- or nil and an error message. | 392 | -- or nil and an error message. |
324 | function writer.make_manifest(repo, deps_mode, remote) | 393 | function writer.make_manifest(repo: string, deps_mode: string, remote?: boolean): boolean, string |
325 | assert(type(repo) == "string") | ||
326 | assert(type(deps_mode) == "string") | ||
327 | 394 | ||
328 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 395 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
329 | 396 | ||
@@ -344,10 +411,10 @@ function writer.make_manifest(repo, deps_mode, remote) | |||
344 | local cache = {} | 411 | local cache = {} |
345 | for luaver in util.lua_versions() do | 412 | for luaver in util.lua_versions() do |
346 | local vmanifest = { repository = {}, modules = {}, commands = {} } | 413 | local vmanifest = { repository = {}, modules = {}, commands = {} } |
347 | local ok, err = store_results(results, vmanifest) | 414 | ok, err = store_results(results, vmanifest) |
348 | filter_by_lua_version(vmanifest, luaver, repo, cache) | 415 | filter_by_lua_version(vmanifest, luaver, repo, cache) |
349 | if not cfg.no_manifest then | 416 | if not cfg.no_manifest then |
350 | save_table(repo, "manifest-"..luaver, vmanifest) | 417 | save_table(repo, "manifest-"..luaver, vmanifest as PersistableTable) |
351 | end | 418 | end |
352 | end | 419 | end |
353 | else | 420 | else |
@@ -358,7 +425,7 @@ function writer.make_manifest(repo, deps_mode, remote) | |||
358 | -- We want to have cache updated; but exit before save_table is called | 425 | -- We want to have cache updated; but exit before save_table is called |
359 | return true | 426 | return true |
360 | end | 427 | end |
361 | return save_table(repo, "manifest", manifest) | 428 | return save_table(repo, "manifest", manifest as PersistableTable) |
362 | end | 429 | end |
363 | 430 | ||
364 | --- Update manifest file for a local repository | 431 | --- Update manifest file for a local repository |
@@ -372,11 +439,9 @@ end | |||
372 | -- "none" for using the default dependency mode from the configuration. | 439 | -- "none" for using the default dependency mode from the configuration. |
373 | -- @return boolean or (nil, string): True if manifest was updated successfully, | 440 | -- @return boolean or (nil, string): True if manifest was updated successfully, |
374 | -- or nil and an error message. | 441 | -- or nil and an error message. |
375 | function writer.add_to_manifest(name, version, repo, deps_mode) | 442 | function writer.add_to_manifest(name: string, version: string, repo: string, deps_mode: string): boolean, string |
376 | assert(type(name) == "string" and not name:match("/")) | 443 | assert(not name:match("/")) |
377 | assert(type(version) == "string") | ||
378 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 444 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
379 | assert(type(deps_mode) == "string") | ||
380 | 445 | ||
381 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 446 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
382 | 447 | ||
@@ -391,7 +456,8 @@ function writer.add_to_manifest(name, version, repo, deps_mode) | |||
391 | 456 | ||
392 | local results = {[name] = {[version] = {{arch = "installed", repo = rocks_dir}}}} | 457 | local results = {[name] = {[version] = {{arch = "installed", repo = rocks_dir}}}} |
393 | 458 | ||
394 | local ok, err = store_results(results, manifest) | 459 | local ok: boolean |
460 | ok, err = store_results(results, manifest) --! | ||
395 | if not ok then return nil, err end | 461 | if not ok then return nil, err end |
396 | 462 | ||
397 | update_dependencies(manifest, deps_mode) | 463 | update_dependencies(manifest, deps_mode) |
@@ -399,7 +465,7 @@ function writer.add_to_manifest(name, version, repo, deps_mode) | |||
399 | if cfg.no_manifest then | 465 | if cfg.no_manifest then |
400 | return true | 466 | return true |
401 | end | 467 | end |
402 | return save_table(rocks_dir, "manifest", manifest) | 468 | return save_table(rocks_dir, "manifest", manifest as PersistableTable) |
403 | end | 469 | end |
404 | 470 | ||
405 | --- Update manifest file for a local repository | 471 | --- Update manifest file for a local repository |
@@ -413,11 +479,9 @@ end | |||
413 | -- "none" for using the default dependency mode from the configuration. | 479 | -- "none" for using the default dependency mode from the configuration. |
414 | -- @return boolean or (nil, string): True if manifest was updated successfully, | 480 | -- @return boolean or (nil, string): True if manifest was updated successfully, |
415 | -- or nil and an error message. | 481 | -- or nil and an error message. |
416 | function writer.remove_from_manifest(name, version, repo, deps_mode) | 482 | function writer.remove_from_manifest(name: string, version: string, repo: string, deps_mode: string): boolean, string |
417 | assert(type(name) == "string" and not name:match("/")) | 483 | assert(not name:match("/")) |
418 | assert(type(version) == "string") | ||
419 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 484 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
420 | assert(type(deps_mode) == "string") | ||
421 | 485 | ||
422 | if deps_mode == "none" then deps_mode = cfg.deps_mode end | 486 | if deps_mode == "none" then deps_mode = cfg.deps_mode end |
423 | 487 | ||
@@ -441,7 +505,7 @@ function writer.remove_from_manifest(name, version, repo, deps_mode) | |||
441 | return writer.make_manifest(rocks_dir, deps_mode) | 505 | return writer.make_manifest(rocks_dir, deps_mode) |
442 | end | 506 | end |
443 | 507 | ||
444 | remove_package_items(manifest.modules, name, version, version_entry.modules) | 508 | remove_package_items(manifest.modules, name, version, version_entry.modules) --! |
445 | remove_package_items(manifest.commands, name, version, version_entry.commands) | 509 | remove_package_items(manifest.commands, name, version, version_entry.commands) |
446 | 510 | ||
447 | package_entry[version] = nil | 511 | package_entry[version] = nil |
@@ -458,7 +522,7 @@ function writer.remove_from_manifest(name, version, repo, deps_mode) | |||
458 | if cfg.no_manifest then | 522 | if cfg.no_manifest then |
459 | return true | 523 | return true |
460 | end | 524 | end |
461 | return save_table(rocks_dir, "manifest", manifest) | 525 | return save_table(rocks_dir, "manifest", manifest as PersistableTable) |
462 | end | 526 | end |
463 | 527 | ||
464 | return writer | 528 | return writer |
diff --git a/src/luarocks/path.tl b/src/luarocks/path.tl index a75d7b83..ae5e5204 100644 --- a/src/luarocks/path.tl +++ b/src/luarocks/path.tl | |||
@@ -106,7 +106,7 @@ end | |||
106 | -- @param tree string or nil: If given, specifies the local tree to use. | 106 | -- @param tree string or nil: If given, specifies the local tree to use. |
107 | -- @return string: The resulting path -- does not guarantee that | 107 | -- @return string: The resulting path -- does not guarantee that |
108 | -- the package (and by extension, the file) exists. | 108 | -- the package (and by extension, the file) exists. |
109 | function path.rock_namespace_file(name: string, version: string, tree: string | Tree): string | 109 | function path.rock_namespace_file(name: string, version: string, tree?: string | Tree): string |
110 | assert(not name:match("/")) | 110 | assert(not name:match("/")) |
111 | return dir.path(path.rocks_dir(tree), name, version, "rock_namespace") | 111 | return dir.path(path.rocks_dir(tree), name, version, "rock_namespace") |
112 | end | 112 | end |
diff --git a/src/luarocks/repo_writer.tl b/src/luarocks/repo_writer.tl index 698af976..70a49f95 100644 --- a/src/luarocks/repo_writer.tl +++ b/src/luarocks/repo_writer.tl | |||
@@ -1,4 +1,5 @@ | |||
1 | local repo_writer = {} | 1 | local record repo_writer |
2 | end | ||
2 | 3 | ||
3 | local fs = require("luarocks.fs") | 4 | local fs = require("luarocks.fs") |
4 | local path = require("luarocks.path") | 5 | local path = require("luarocks.path") |
diff --git a/src/luarocks/search.tl b/src/luarocks/search.tl index caf01221..fdeebcd8 100644 --- a/src/luarocks/search.tl +++ b/src/luarocks/search.tl | |||
@@ -66,7 +66,7 @@ end | |||
66 | -- values are tables matching version strings to arrays of | 66 | -- values are tables matching version strings to arrays of |
67 | -- tables with fields "arch" and "repo". | 67 | -- tables with fields "arch" and "repo". |
68 | -- If a table was given in the "result_tree" parameter, that is the result value. | 68 | -- If a table was given in the "result_tree" parameter, that is the result value. |
69 | function search.disk_search(repo: string, query: Query, result_tree: {string: {string: {Result}}}): {string: {string: {Result}}} | 69 | function search.disk_search(repo: string, query: Query, result_tree?: {string: {string: {Result}}}): {string: {string: {Result}}} |
70 | 70 | ||
71 | local fs = require("luarocks.fs") | 71 | local fs = require("luarocks.fs") |
72 | 72 | ||