diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-09-02 17:50:32 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
commit | 3be22b3f07dc1558c7734cf7639e3468ec8de796 (patch) | |
tree | b159d3985bf0e18d1dd9ee3b22d537799a2ab714 | |
parent | aa3199def734b492059fcaccdebd3cde85cb8547 (diff) | |
download | luarocks-3be22b3f07dc1558c7734cf7639e3468ec8de796.tar.gz luarocks-3be22b3f07dc1558c7734cf7639e3468ec8de796.tar.bz2 luarocks-3be22b3f07dc1558c7734cf7639e3468ec8de796.zip |
Teal: make luarocks.fs not dependent on luarocks.util
Break circular dependency detected by Cyan
-rw-r--r-- | src/luarocks/core/util.lua | 26 | ||||
-rw-r--r-- | src/luarocks/core/util.tl | 36 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 2 | ||||
-rw-r--r-- | src/luarocks/util.lua | 25 | ||||
-rw-r--r-- | src/luarocks/util.tl | 25 |
5 files changed, 66 insertions, 48 deletions
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 6a457c54..76ec1a62 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
@@ -331,4 +331,30 @@ function util.sortedpairs(tbl, sort_by) | |||
331 | end | 331 | end |
332 | end | 332 | end |
333 | 333 | ||
334 | |||
335 | |||
336 | |||
337 | |||
338 | |||
339 | |||
340 | |||
341 | |||
342 | function util.exists(file) | ||
343 | local fd, _, code = io.open(file, "r") | ||
344 | if code == 13 then | ||
345 | |||
346 | |||
347 | return true | ||
348 | end | ||
349 | if fd then | ||
350 | fd:close() | ||
351 | return true | ||
352 | end | ||
353 | return false | ||
354 | end | ||
355 | |||
356 | function util.starts_with(s, prefix) | ||
357 | return s:sub(1, #prefix) == prefix | ||
358 | end | ||
359 | |||
334 | return util | 360 | return util |
diff --git a/src/luarocks/core/util.tl b/src/luarocks/core/util.tl index a9be2d43..b1bbea05 100644 --- a/src/luarocks/core/util.tl +++ b/src/luarocks/core/util.tl | |||
@@ -298,13 +298,13 @@ function util.sortedpairs<K, V>(tbl: {K: V}, sort_by?: SortBy<K>): function(): K | |||
298 | table.sort(keys, sort_by) | 298 | table.sort(keys, sort_by) |
299 | else | 299 | else |
300 | -- sort_by is Ordering<K> | 300 | -- sort_by is Ordering<K> |
301 | 301 | ||
302 | sub_orders = sort_by.sub_orders | 302 | sub_orders = sort_by.sub_orders |
303 | 303 | ||
304 | local seen_ordered_key: {K: boolean} = {} | 304 | local seen_ordered_key: {K: boolean} = {} |
305 | 305 | ||
306 | local my_ordered_keys: {K} = {} | 306 | local my_ordered_keys: {K} = {} |
307 | 307 | ||
308 | for _, key in ipairs(sort_by) do | 308 | for _, key in ipairs(sort_by) do |
309 | if tbl[key] then | 309 | if tbl[key] then |
310 | seen_ordered_key[key] = true | 310 | seen_ordered_key[key] = true |
@@ -319,10 +319,10 @@ function util.sortedpairs<K, V>(tbl: {K: V}, sort_by?: SortBy<K>): function(): K | |||
319 | table.insert(my_ordered_keys, key) | 319 | table.insert(my_ordered_keys, key) |
320 | end | 320 | end |
321 | end | 321 | end |
322 | 322 | ||
323 | keys = my_ordered_keys | 323 | keys = my_ordered_keys |
324 | end | 324 | end |
325 | 325 | ||
326 | local i = 1 | 326 | local i = 1 |
327 | return function(): K, V, Ordering<K> | 327 | return function(): K, V, Ordering<K> |
328 | local key = keys[i] | 328 | local key = keys[i] |
@@ -331,5 +331,31 @@ function util.sortedpairs<K, V>(tbl: {K: V}, sort_by?: SortBy<K>): function(): K | |||
331 | end | 331 | end |
332 | end | 332 | end |
333 | 333 | ||
334 | -------------------------------------------------------------------------------- | ||
335 | -- Functions needed by luarocks.fs, | ||
336 | -- added here to avoid a circular dependency: | ||
337 | -------------------------------------------------------------------------------- | ||
338 | |||
339 | -- A portable version of fs.exists that can be used at early startup, | ||
340 | -- before the platform has been determined and luarocks.fs has been | ||
341 | -- initialized. | ||
342 | function util.exists(file: string): boolean | ||
343 | local fd, _, code = io.open(file, "r") | ||
344 | if code == 13 then | ||
345 | -- code 13 means "Permission denied" on both Unix and Windows | ||
346 | -- io.open on folders always fails with code 13 on Windows | ||
347 | return true | ||
348 | end | ||
349 | if fd then | ||
350 | fd:close() | ||
351 | return true | ||
352 | end | ||
353 | return false | ||
354 | end | ||
355 | |||
356 | function util.starts_with(s: string, prefix: string): boolean | ||
357 | return s:sub(1,#prefix) == prefix | ||
358 | end | ||
359 | |||
334 | return util | 360 | return util |
335 | 361 | ||
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index fdf3af78..02d9353a 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -8,7 +8,7 @@ local fs = require("luarocks.fs") | |||
8 | 8 | ||
9 | local cfg = require("luarocks.core.cfg") | 9 | local cfg = require("luarocks.core.cfg") |
10 | local dir = require("luarocks.dir") | 10 | local dir = require("luarocks.dir") |
11 | local util = require("luarocks.util") | 11 | local util = require("luarocks.core.util") |
12 | local vers = require("luarocks.core.vers") | 12 | local vers = require("luarocks.core.vers") |
13 | 13 | ||
14 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | 14 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 0ea480be..15ed2cf0 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
@@ -29,6 +29,8 @@ local util = {Fn = {}, } | |||
29 | 29 | ||
30 | 30 | ||
31 | 31 | ||
32 | |||
33 | |||
32 | util.cleanup_path = core.cleanup_path | 34 | util.cleanup_path = core.cleanup_path |
33 | util.split_string = core.split_string | 35 | util.split_string = core.split_string |
34 | util.sortedpairs = core.sortedpairs | 36 | util.sortedpairs = core.sortedpairs |
@@ -40,6 +42,8 @@ util.printerr = core.printerr | |||
40 | util.warning = core.warning | 42 | util.warning = core.warning |
41 | util.keys = core.keys | 43 | util.keys = core.keys |
42 | util.matchquote = core.matchquote | 44 | util.matchquote = core.matchquote |
45 | util.exists = core.exists | ||
46 | util.starts_with = core.starts_with | ||
43 | 47 | ||
44 | 48 | ||
45 | 49 | ||
@@ -188,10 +192,6 @@ function util.lua_path_variables() | |||
188 | return lpath_var, lcpath_var | 192 | return lpath_var, lcpath_var |
189 | end | 193 | end |
190 | 194 | ||
191 | function util.starts_with(s, prefix) | ||
192 | return s:sub(1, #prefix) == prefix | ||
193 | end | ||
194 | |||
195 | 195 | ||
196 | function util.printout(...) | 196 | function util.printout(...) |
197 | io.stdout:write(table.concat({ ... }, "\t")) | 197 | io.stdout:write(table.concat({ ... }, "\t")) |
@@ -396,23 +396,6 @@ function util.deep_copy(tbl) | |||
396 | return copy | 396 | return copy |
397 | end | 397 | end |
398 | 398 | ||
399 | |||
400 | |||
401 | |||
402 | function util.exists(file) | ||
403 | local fd, _, code = io.open(file, "r") | ||
404 | if code == 13 then | ||
405 | |||
406 | |||
407 | return true | ||
408 | end | ||
409 | if fd then | ||
410 | fd:close() | ||
411 | return true | ||
412 | end | ||
413 | return false | ||
414 | end | ||
415 | |||
416 | function util.lua_is_wrapper(interp) | 399 | function util.lua_is_wrapper(interp) |
417 | local fd, err = io.open(interp, "r") | 400 | local fd, err = io.open(interp, "r") |
418 | if not fd then | 401 | if not fd then |
diff --git a/src/luarocks/util.tl b/src/luarocks/util.tl index 80d39b16..436914ab 100644 --- a/src/luarocks/util.tl +++ b/src/luarocks/util.tl | |||
@@ -22,6 +22,8 @@ local record util | |||
22 | warning: function(string) | 22 | warning: function(string) |
23 | keys: function<K, V>({K : V}): {K} | 23 | keys: function<K, V>({K : V}): {K} |
24 | matchquote: function(string): string | 24 | matchquote: function(string): string |
25 | exists: function(string): boolean | ||
26 | starts_with: function(s: string, prefix: string): boolean | ||
25 | 27 | ||
26 | record Fn | 28 | record Fn |
27 | fn: function(any) | 29 | fn: function(any) |
@@ -40,6 +42,8 @@ util.printerr = core.printerr | |||
40 | util.warning = core.warning | 42 | util.warning = core.warning |
41 | util.keys = core.keys | 43 | util.keys = core.keys |
42 | util.matchquote = core.matchquote | 44 | util.matchquote = core.matchquote |
45 | util.exists = core.exists | ||
46 | util.starts_with = core.starts_with | ||
43 | 47 | ||
44 | local type Fn = util.Fn | 48 | local type Fn = util.Fn |
45 | local type Rockspec = require("luarocks.core.types.rockspec").Rockspec | 49 | local type Rockspec = require("luarocks.core.types.rockspec").Rockspec |
@@ -188,10 +192,6 @@ function util.lua_path_variables(): string, string | |||
188 | return lpath_var, lcpath_var | 192 | return lpath_var, lcpath_var |
189 | end | 193 | end |
190 | 194 | ||
191 | function util.starts_with(s: string, prefix: string): boolean | ||
192 | return s:sub(1,#prefix) == prefix | ||
193 | end | ||
194 | |||
195 | --- Print a line to standard output | 195 | --- Print a line to standard output |
196 | function util.printout(...: string) | 196 | function util.printout(...: string) |
197 | io.stdout:write(table.concat({...},"\t")) | 197 | io.stdout:write(table.concat({...},"\t")) |
@@ -396,23 +396,6 @@ function util.deep_copy(tbl: {any: any}): {any: any} | |||
396 | return copy | 396 | return copy |
397 | end | 397 | end |
398 | 398 | ||
399 | -- A portable version of fs.exists that can be used at early startup, | ||
400 | -- before the platform has been determined and luarocks.fs has been | ||
401 | -- initialized. | ||
402 | function util.exists(file: string): boolean | ||
403 | local fd, _, code = io.open(file, "r") | ||
404 | if code == 13 then | ||
405 | -- code 13 means "Permission denied" on both Unix and Windows | ||
406 | -- io.open on folders always fails with code 13 on Windows | ||
407 | return true | ||
408 | end | ||
409 | if fd then | ||
410 | fd:close() | ||
411 | return true | ||
412 | end | ||
413 | return false | ||
414 | end | ||
415 | |||
416 | function util.lua_is_wrapper(interp: string): boolean, string | 399 | function util.lua_is_wrapper(interp: string): boolean, string |
417 | local fd, err = io.open(interp, "r") | 400 | local fd, err = io.open(interp, "r") |
418 | if not fd then | 401 | if not fd then |