diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-14 13:01:20 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-14 13:01:20 +0300 |
commit | 719d2e29e2834c8226c6b2afaeb2ab402a0ba7d8 (patch) | |
tree | 0dbe1bc2676494b70c28ca5fe5c85bb4b6c41453 | |
parent | a1f44b94b20dd1048607eca5a212558602eb7076 (diff) | |
download | luarocks-719d2e29e2834c8226c6b2afaeb2ab402a0ba7d8.tar.gz luarocks-719d2e29e2834c8226c6b2afaeb2ab402a0ba7d8.tar.bz2 luarocks-719d2e29e2834c8226c6b2afaeb2ab402a0ba7d8.zip |
repo_writer
-rw-r--r-- | src/luarocks/fs.d.tl | 2 | ||||
-rw-r--r-- | src/luarocks/manif/writer.tl | 95 | ||||
-rw-r--r-- | src/luarocks/path.tl | 2 | ||||
-rw-r--r-- | src/luarocks/repo_writer-original.lua | 52 | ||||
-rw-r--r-- | src/luarocks/repo_writer.lua | 2 | ||||
-rw-r--r-- | src/luarocks/repo_writer.tl | 8 |
6 files changed, 76 insertions, 85 deletions
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index 73848524..680369de 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl | |||
@@ -58,7 +58,7 @@ local record fs | |||
58 | move: function(string, string, string): boolean, string | 58 | move: function(string, string, string): boolean, string |
59 | -- writer | 59 | -- writer |
60 | replace_file: function(string, string): boolean, string | 60 | replace_file: function(string, string): boolean, string |
61 | get_md5: function(string): string | 61 | get_md5: function(string): string, string |
62 | end | 62 | end |
63 | 63 | ||
64 | return fs | 64 | return fs |
diff --git a/src/luarocks/manif/writer.tl b/src/luarocks/manif/writer.tl index 2b303fd5..b803bff6 100644 --- a/src/luarocks/manif/writer.tl +++ b/src/luarocks/manif/writer.tl | |||
@@ -28,6 +28,10 @@ local type Result = res.Result | |||
28 | local type p = require("luarocks.core.types.persist") | 28 | local type p = require("luarocks.core.types.persist") |
29 | local type PersistableTable = p.PersistableTable | 29 | local type PersistableTable = p.PersistableTable |
30 | 30 | ||
31 | local type rm = require("luarocks.core.types.rockmanifest") | ||
32 | local type RockManifest = rm.RockManifest | ||
33 | local type Entry = rm.RockManifest.Entry | ||
34 | |||
31 | --- Update storage table to account for items provided by a package. | 35 | --- Update storage table to account for items provided by a package. |
32 | -- @param storage table: a table storing items in the following format: | 36 | -- @param storage table: a table storing items in the following format: |
33 | -- keys are item names and values are arrays of packages providing each item, | 37 | -- keys are item names and values are arrays of packages providing each item, |
@@ -56,7 +60,7 @@ end | |||
56 | -- @param items table: a table mapping item names to paths. | 60 | -- @param items table: a table mapping item names to paths. |
57 | -- @param name string: package name. | 61 | -- @param name string: package name. |
58 | -- @param version string: package version. | 62 | -- @param version string: package version. |
59 | local function remove_package_items(storage: {string: {string}}, name: string, version: string, items: {string: string}) | 63 | local function remove_package_items(storage: {string: {string}}, name: string, version: string, items: {string: {string}}) |
60 | assert(not name:match("/")) | 64 | assert(not name:match("/")) |
61 | 65 | ||
62 | local package_identifier = name.."/"..version | 66 | local package_identifier = name.."/"..version |
@@ -95,8 +99,6 @@ end | |||
95 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 99 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
96 | -- "none" for no trees. | 100 | -- "none" for no trees. |
97 | local function update_dependencies(manifest: Manifest, deps_mode: string) | 101 | local function update_dependencies(manifest: Manifest, deps_mode: string) |
98 | assert(type(manifest) == "table") | ||
99 | assert(type(deps_mode) == "string") | ||
100 | 102 | ||
101 | if not manifest.dependencies then manifest.dependencies = {} end | 103 | if not manifest.dependencies then manifest.dependencies = {} end |
102 | local mdeps = manifest.dependencies | 104 | local mdeps = manifest.dependencies |
@@ -239,38 +241,6 @@ local function store_results(results: {string: {string: {Result}}}, manifest: Ma | |||
239 | return true | 241 | return true |
240 | end | 242 | end |
241 | 243 | ||
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 | |||
274 | --- Commit a table to disk in given local path. | 244 | --- Commit a table to disk in given local path. |
275 | -- @param where string: The directory where the table should be saved. | 245 | -- @param where string: The directory where the table should be saved. |
276 | -- @param name string: The filename. | 246 | -- @param name string: The filename. |
@@ -290,13 +260,13 @@ end | |||
290 | 260 | ||
291 | function writer.make_rock_manifest(name: string, version: string): boolean, string | 261 | function writer.make_rock_manifest(name: string, version: string): boolean, string |
292 | local install_dir = path.install_dir(name, version) | 262 | local install_dir = path.install_dir(name, version) |
293 | local tree: {string: {string}} = {} | 263 | local tree: {string: Entry} = {} |
294 | for _, file in ipairs(fs.find(install_dir)) do | 264 | for _, file in ipairs(fs.find(install_dir)) do |
295 | local full_path = dir.path(install_dir, file) | 265 | local full_path = dir.path(install_dir, file) |
296 | local walk = tree | 266 | local walk = tree |
297 | local last: {string : {string}} | 267 | local last: {string : Entry} |
298 | local last_name: string | 268 | local last_name: string |
299 | local next: {string} | 269 | local next: Entry |
300 | for filename in file:gmatch("[^\\/]+") do | 270 | for filename in file:gmatch("[^\\/]+") do |
301 | next = walk[filename] | 271 | next = walk[filename] |
302 | if not next then | 272 | if not next then |
@@ -305,9 +275,14 @@ function writer.make_rock_manifest(name: string, version: string): boolean, stri | |||
305 | end | 275 | end |
306 | last = walk | 276 | last = walk |
307 | last_name = filename | 277 | last_name = filename |
308 | walk = next | 278 | if not next is string then |
279 | walk = next | ||
280 | else | ||
281 | return nil, "Next was string, expected a table" | ||
282 | end | ||
309 | end | 283 | end |
310 | if fs.is_file(full_path) then | 284 | if fs.is_file(full_path) then |
285 | |||
311 | local sum, err = fs.get_md5(full_path) | 286 | local sum, err = fs.get_md5(full_path) |
312 | if not sum then | 287 | if not sum then |
313 | return nil, "Failed producing checksum: "..tostring(err) | 288 | return nil, "Failed producing checksum: "..tostring(err) |
@@ -315,48 +290,12 @@ function writer.make_rock_manifest(name: string, version: string): boolean, stri | |||
315 | last[last_name] = sum | 290 | last[last_name] = sum |
316 | end | 291 | end |
317 | end | 292 | end |
318 | local rock_manifest = { rock_manifest=tree } | 293 | local rock_manifest: RockManifest = { rock_manifest=tree } |
319 | manif.rock_manifest_cache[name.."/"..version] = rock_manifest | 294 | manif.rock_manifest_cache[name.."/"..version] = rock_manifest |
320 | save_table(install_dir, "rock_manifest", rock_manifest ) | 295 | save_table(install_dir, "rock_manifest", rock_manifest as PersistableTable) |
321 | return true | 296 | return true |
322 | end | 297 | end |
323 | 298 | ||
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 | |||
360 | -- Writes a 'rock_namespace' file in a locally installed rock directory. | 299 | -- Writes a 'rock_namespace' file in a locally installed rock directory. |
361 | -- @param name string: the rock name, without a namespace | 300 | -- @param name string: the rock name, without a namespace |
362 | -- @param version string: the rock version | 301 | -- @param version string: the rock version |
@@ -454,7 +393,7 @@ function writer.add_to_manifest(name: string, version: string, repo: string, dep | |||
454 | return writer.make_manifest(rocks_dir, deps_mode) | 393 | return writer.make_manifest(rocks_dir, deps_mode) |
455 | end | 394 | end |
456 | 395 | ||
457 | local results = {[name] = {[version] = {{arch = "installed", repo = rocks_dir}}}} | 396 | local results: {string : {string : {Result}}} = {[name] = {[version] = {{arch = "installed", repo = rocks_dir}}}} |
458 | 397 | ||
459 | local ok: boolean | 398 | local ok: boolean |
460 | ok, err = store_results(results, manifest) --! | 399 | ok, err = store_results(results, manifest) --! |
diff --git a/src/luarocks/path.tl b/src/luarocks/path.tl index ae5e5204..65c425d3 100644 --- a/src/luarocks/path.tl +++ b/src/luarocks/path.tl | |||
@@ -95,7 +95,7 @@ end | |||
95 | -- @param tree string or nil: If given, specifies the local tree to use. | 95 | -- @param tree string or nil: If given, specifies the local tree to use. |
96 | -- @return string: The resulting path -- does not guarantee that | 96 | -- @return string: The resulting path -- does not guarantee that |
97 | -- the package (and by extension, the file) exists. | 97 | -- the package (and by extension, the file) exists. |
98 | function path.rock_manifest_file(name: string, version: string, tree: string | Tree): string | 98 | function path.rock_manifest_file(name: string, version: string, tree?: string | Tree): string |
99 | assert(not name:match("/")) | 99 | assert(not name:match("/")) |
100 | return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") | 100 | return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") |
101 | end | 101 | end |
diff --git a/src/luarocks/repo_writer-original.lua b/src/luarocks/repo_writer-original.lua new file mode 100644 index 00000000..698af976 --- /dev/null +++ b/src/luarocks/repo_writer-original.lua | |||
@@ -0,0 +1,52 @@ | |||
1 | local repo_writer = {} | ||
2 | |||
3 | local fs = require("luarocks.fs") | ||
4 | local path = require("luarocks.path") | ||
5 | local repos = require("luarocks.repos") | ||
6 | local writer = require("luarocks.manif.writer") | ||
7 | |||
8 | function repo_writer.deploy_files(name, version, wrap_bin_scripts, deps_mode, namespace) | ||
9 | local ok, err | ||
10 | |||
11 | if not fs.exists(path.rock_manifest_file(name, version)) then | ||
12 | ok, err = writer.make_rock_manifest(name, version) | ||
13 | if err then | ||
14 | return nil, err | ||
15 | end | ||
16 | end | ||
17 | |||
18 | if namespace then | ||
19 | ok, err = writer.make_namespace_file(name, version, namespace) | ||
20 | if not ok then | ||
21 | return nil, err | ||
22 | end | ||
23 | end | ||
24 | |||
25 | ok, err = repos.deploy_local_files(name, version, wrap_bin_scripts, deps_mode) | ||
26 | if not ok then | ||
27 | return nil, err | ||
28 | end | ||
29 | |||
30 | ok, err = writer.add_to_manifest(name, version, nil, deps_mode) | ||
31 | return ok, err | ||
32 | end | ||
33 | |||
34 | function repo_writer.delete_version(name, version, deps_mode, quick) | ||
35 | local ok, err, op = repos.delete_local_version(name, version, deps_mode, quick) | ||
36 | |||
37 | if op == "remove" then | ||
38 | local rok, rerr = writer.remove_from_manifest(name, version, nil, deps_mode) | ||
39 | if ok and not rok then | ||
40 | ok, err = rok, rerr | ||
41 | end | ||
42 | end | ||
43 | |||
44 | return ok, err | ||
45 | end | ||
46 | |||
47 | function repo_writer.refresh_manifest(rocks_dir) | ||
48 | return writer.make_manifest(rocks_dir, "one") | ||
49 | end | ||
50 | |||
51 | return repo_writer | ||
52 | |||
diff --git a/src/luarocks/repo_writer.lua b/src/luarocks/repo_writer.lua index 698af976..0ccb3e91 100644 --- a/src/luarocks/repo_writer.lua +++ b/src/luarocks/repo_writer.lua | |||
@@ -1,5 +1,6 @@ | |||
1 | local repo_writer = {} | 1 | local repo_writer = {} |
2 | 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") |
5 | local repos = require("luarocks.repos") | 6 | local repos = require("luarocks.repos") |
@@ -49,4 +50,3 @@ function repo_writer.refresh_manifest(rocks_dir) | |||
49 | end | 50 | end |
50 | 51 | ||
51 | return repo_writer | 52 | return repo_writer |
52 | |||
diff --git a/src/luarocks/repo_writer.tl b/src/luarocks/repo_writer.tl index 70a49f95..ec99ba48 100644 --- a/src/luarocks/repo_writer.tl +++ b/src/luarocks/repo_writer.tl | |||
@@ -6,8 +6,8 @@ local path = require("luarocks.path") | |||
6 | local repos = require("luarocks.repos") | 6 | local repos = require("luarocks.repos") |
7 | local writer = require("luarocks.manif.writer") | 7 | local writer = require("luarocks.manif.writer") |
8 | 8 | ||
9 | function repo_writer.deploy_files(name, version, wrap_bin_scripts, deps_mode, namespace) | 9 | function repo_writer.deploy_files(name: string, version: string, wrap_bin_scripts: boolean, deps_mode: string, namespace: string): boolean, string |
10 | local ok, err | 10 | local ok, err: boolean, string |
11 | 11 | ||
12 | if not fs.exists(path.rock_manifest_file(name, version)) then | 12 | if not fs.exists(path.rock_manifest_file(name, version)) then |
13 | ok, err = writer.make_rock_manifest(name, version) | 13 | ok, err = writer.make_rock_manifest(name, version) |
@@ -32,7 +32,7 @@ function repo_writer.deploy_files(name, version, wrap_bin_scripts, deps_mode, na | |||
32 | return ok, err | 32 | return ok, err |
33 | end | 33 | end |
34 | 34 | ||
35 | function repo_writer.delete_version(name, version, deps_mode, quick) | 35 | function repo_writer.delete_version(name: string, version: string, deps_mode: string, quick: boolean): boolean, string |
36 | local ok, err, op = repos.delete_local_version(name, version, deps_mode, quick) | 36 | local ok, err, op = repos.delete_local_version(name, version, deps_mode, quick) |
37 | 37 | ||
38 | if op == "remove" then | 38 | if op == "remove" then |
@@ -45,7 +45,7 @@ function repo_writer.delete_version(name, version, deps_mode, quick) | |||
45 | return ok, err | 45 | return ok, err |
46 | end | 46 | end |
47 | 47 | ||
48 | function repo_writer.refresh_manifest(rocks_dir) | 48 | function repo_writer.refresh_manifest(rocks_dir: string): boolean, string |
49 | return writer.make_manifest(rocks_dir, "one") | 49 | return writer.make_manifest(rocks_dir, "one") |
50 | end | 50 | end |
51 | 51 | ||