diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2025-03-04 01:41:58 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2025-03-10 10:51:04 -0300 |
| commit | 86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4 (patch) | |
| tree | 5c9b86835c20e8982492b1d0ad27b83bf407972d | |
| parent | d8775ec1e6b5d0b8750dc6bf379a76c01ac10e5f (diff) | |
| download | luarocks-86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4.tar.gz luarocks-86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4.tar.bz2 luarocks-86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4.zip | |
fs: begin making dependencies mandatory
| -rw-r--r-- | src/luarocks/fs/lua.lua | 113 |
1 files changed, 20 insertions, 93 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 0f1ee55e..9c0729c3 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | ||
| 2 | --- Native Lua implementation of filesystem and platform abstractions, | 2 | --- Native Lua implementation of filesystem and platform abstractions, |
| 3 | -- using LuaFileSystem, LuaSocket, LuaSec, lua-zlib, LuaPosix, MD5. | 3 | -- using LuaFileSystem, LuaSocket, LuaSec, lua-zlib, miniposix, MD5. |
| 4 | -- module("luarocks.fs.lua") | 4 | -- module("luarocks.fs.lua") |
| 5 | local fs_lua = {} | 5 | local fs_lua = {} |
| 6 | 6 | ||
| @@ -9,22 +9,18 @@ local fs = require("luarocks.fs") | |||
| 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.core.util") | 11 | local util = require("luarocks.core.util") |
| 12 | local vers = require("luarocks.core.vers") | ||
| 13 | 12 | ||
| 14 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | 13 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end |
| 15 | 14 | ||
| 16 | local socket_ok, zip_ok, lfs_ok, md5_ok, posix_ok, bz2_ok, _ | 15 | local http = require("socket.http") |
| 17 | local http, ftp, zip, lfs, md5, posix, bz2 | 16 | local ftp = require("socket.ftp") |
| 18 | 17 | local zip = require("luarocks.tools.zip") | |
| 19 | if cfg.fs_use_modules then | 18 | local bz2 = require("bz2") |
| 20 | socket_ok, http = pcall(require, "socket.http") | 19 | local lfs = require("lfs") |
| 21 | _, ftp = pcall(require, "socket.ftp") | 20 | local md5 = require("md5") |
| 22 | zip_ok, zip = pcall(require, "luarocks.tools.zip") | 21 | local miniposix = require("miniposix") |
| 23 | bz2_ok, bz2 = pcall(require, "bz2") | 22 | local ltn12 = require("ltn12") |
| 24 | lfs_ok, lfs = pcall(require, "lfs") | 23 | local https = require("ssl.https") |
| 25 | md5_ok, md5 = pcall(require, "md5") | ||
| 26 | posix_ok, posix = pcall(require, "posix") | ||
| 27 | end | ||
| 28 | 24 | ||
| 29 | local patch = require("luarocks.tools.patch") | 25 | local patch = require("luarocks.tools.patch") |
| 30 | local tar = require("luarocks.tools.tar") | 26 | local tar = require("luarocks.tools.tar") |
| @@ -289,8 +285,6 @@ end | |||
| 289 | -- LuaFileSystem functions | 285 | -- LuaFileSystem functions |
| 290 | --------------------------------------------------------------------- | 286 | --------------------------------------------------------------------- |
| 291 | 287 | ||
| 292 | if lfs_ok then | ||
| 293 | |||
| 294 | function fs_lua.file_age(filename) | 288 | function fs_lua.file_age(filename) |
| 295 | local attr = lfs.attributes(filename) | 289 | local attr = lfs.attributes(filename) |
| 296 | if attr and attr.change then | 290 | if attr and attr.change then |
| @@ -482,8 +476,8 @@ function fs_lua.copy(src, dest, perms) | |||
| 482 | if not perms then | 476 | if not perms then |
| 483 | fullattrs = lfs.attributes(src, "permissions") | 477 | fullattrs = lfs.attributes(src, "permissions") |
| 484 | end | 478 | end |
| 485 | if fullattrs and posix_ok then | 479 | if fullattrs then |
| 486 | return posix.chmod(dest, fullattrs) | 480 | return miniposix.chmod(dest, fullattrs) |
| 487 | else | 481 | else |
| 488 | if cfg.is_platform("unix") then | 482 | if cfg.is_platform("unix") then |
| 489 | if not perms then | 483 | if not perms then |
| @@ -683,26 +677,10 @@ function fs_lua.set_time(file, time) | |||
| 683 | return lfs.touch(file, time) | 677 | return lfs.touch(file, time) |
| 684 | end | 678 | end |
| 685 | 679 | ||
| 686 | else -- if not lfs_ok | ||
| 687 | |||
| 688 | function fs_lua.exists(file) | ||
| 689 | assert(file) | ||
| 690 | -- check if file exists by attempting to open it | ||
| 691 | return util.exists(fs.absolute_name(file)) | ||
| 692 | end | ||
| 693 | |||
| 694 | function fs_lua.file_age(_) | ||
| 695 | return math.huge | ||
| 696 | end | ||
| 697 | |||
| 698 | end | ||
| 699 | |||
| 700 | --------------------------------------------------------------------- | 680 | --------------------------------------------------------------------- |
| 701 | -- lua-bz2 functions | 681 | -- lua-bz2 functions |
| 702 | --------------------------------------------------------------------- | 682 | --------------------------------------------------------------------- |
| 703 | 683 | ||
| 704 | if bz2_ok then | ||
| 705 | |||
| 706 | local function bunzip2_string(data) | 684 | local function bunzip2_string(data) |
| 707 | local decompressor = bz2.initDecompress() | 685 | local decompressor = bz2.initDecompress() |
| 708 | local output, err = decompressor:update(data) | 686 | local output, err = decompressor:update(data) |
| @@ -728,14 +706,10 @@ function fs_lua.bunzip2(infile, outfile) | |||
| 728 | return fs.filter_file(bunzip2_string, infile, outfile) | 706 | return fs.filter_file(bunzip2_string, infile, outfile) |
| 729 | end | 707 | end |
| 730 | 708 | ||
| 731 | end | ||
| 732 | |||
| 733 | --------------------------------------------------------------------- | 709 | --------------------------------------------------------------------- |
| 734 | -- luarocks.tools.zip functions | 710 | -- luarocks.tools.zip functions |
| 735 | --------------------------------------------------------------------- | 711 | --------------------------------------------------------------------- |
| 736 | 712 | ||
| 737 | if zip_ok then | ||
| 738 | |||
| 739 | function fs_lua.zip(zipfile, ...) | 713 | function fs_lua.zip(zipfile, ...) |
| 740 | return zip.zip(zipfile, ...) | 714 | return zip.zip(zipfile, ...) |
| 741 | end | 715 | end |
| @@ -748,25 +722,13 @@ function fs_lua.gunzip(infile, outfile) | |||
| 748 | return zip.gunzip(infile, outfile) | 722 | return zip.gunzip(infile, outfile) |
| 749 | end | 723 | end |
| 750 | 724 | ||
| 751 | end | ||
| 752 | |||
| 753 | --------------------------------------------------------------------- | 725 | --------------------------------------------------------------------- |
| 754 | -- LuaSocket functions | 726 | -- LuaSocket/LuaSec functions |
| 755 | --------------------------------------------------------------------- | 727 | --------------------------------------------------------------------- |
| 756 | 728 | ||
| 757 | if socket_ok then | ||
| 758 | |||
| 759 | local ltn12 = require("ltn12") | ||
| 760 | local luasec_ok, https = pcall(require, "ssl.https") | ||
| 761 | |||
| 762 | if luasec_ok and not vers.compare_versions(https._VERSION, "1.0.3") then | ||
| 763 | luasec_ok = false | ||
| 764 | https = nil | ||
| 765 | end | ||
| 766 | |||
| 767 | local redirect_protocols = { | 729 | local redirect_protocols = { |
| 768 | http = http, | 730 | http = http, |
| 769 | https = luasec_ok and https, | 731 | https = https, |
| 770 | } | 732 | } |
| 771 | 733 | ||
| 772 | local function request(url, method, http, loop_control) -- luacheck: ignore 431 | 734 | local function request(url, method, http, loop_control) -- luacheck: ignore 431 |
| @@ -964,8 +926,7 @@ function fs_lua.download(url, filename, cache) | |||
| 964 | elseif util.starts_with(url, "ftp:") then | 926 | elseif util.starts_with(url, "ftp:") then |
| 965 | ok, err = ftp_request(url, filename) | 927 | ok, err = ftp_request(url, filename) |
| 966 | elseif util.starts_with(url, "https:") then | 928 | elseif util.starts_with(url, "https:") then |
| 967 | -- skip LuaSec when proxy is enabled since it is not supported | 929 | if not os.getenv("https_proxy") then |
| 968 | if luasec_ok and not os.getenv("https_proxy") then | ||
| 969 | local _ | 930 | local _ |
| 970 | ok, err, _, from_cache = http_request(url, filename, https, cache) | 931 | ok, err, _, from_cache = http_request(url, filename, https, cache) |
| 971 | else | 932 | else |
| @@ -990,29 +951,10 @@ function fs_lua.download(url, filename, cache) | |||
| 990 | return filename, nil, nil, from_cache | 951 | return filename, nil, nil, from_cache |
| 991 | end | 952 | end |
| 992 | 953 | ||
| 993 | else --...if socket_ok == false then | ||
| 994 | |||
| 995 | function fs_lua.download(url, filename, cache) | ||
| 996 | return fs.use_downloader(url, filename, cache) | ||
| 997 | end | ||
| 998 | |||
| 999 | end | ||
| 1000 | --------------------------------------------------------------------- | 954 | --------------------------------------------------------------------- |
| 1001 | -- MD5 functions | 955 | -- MD5 functions |
| 1002 | --------------------------------------------------------------------- | 956 | --------------------------------------------------------------------- |
| 1003 | 957 | ||
| 1004 | if md5_ok then | ||
| 1005 | |||
| 1006 | -- Support the interface of lmd5 by lhf in addition to md5 by Roberto | ||
| 1007 | -- and the keplerproject. | ||
| 1008 | if not md5.sumhexa and md5.digest then | ||
| 1009 | md5.sumhexa = function(msg) | ||
| 1010 | return md5.digest(msg) | ||
| 1011 | end | ||
| 1012 | end | ||
| 1013 | |||
| 1014 | if md5.sumhexa then | ||
| 1015 | |||
| 1016 | --- Get the MD5 checksum for a file. | 958 | --- Get the MD5 checksum for a file. |
| 1017 | -- @param file string: The file to be computed. | 959 | -- @param file string: The file to be computed. |
| 1018 | -- @return string: The MD5 checksum or nil + error | 960 | -- @return string: The MD5 checksum or nil + error |
| @@ -1026,9 +968,6 @@ function fs_lua.get_md5(file) | |||
| 1026 | return nil, "Failed to compute MD5 hash for file "..file | 968 | return nil, "Failed to compute MD5 hash for file "..file |
| 1027 | end | 969 | end |
| 1028 | 970 | ||
| 1029 | end | ||
| 1030 | end | ||
| 1031 | |||
| 1032 | --------------------------------------------------------------------- | 971 | --------------------------------------------------------------------- |
| 1033 | -- POSIX functions | 972 | -- POSIX functions |
| 1034 | --------------------------------------------------------------------- | 973 | --------------------------------------------------------------------- |
| @@ -1045,8 +984,6 @@ function fs_lua._unix_rwx_to_number(rwx, neg) | |||
| 1045 | return math.floor(num) | 984 | return math.floor(num) |
| 1046 | end | 985 | end |
| 1047 | 986 | ||
| 1048 | if posix_ok then | ||
| 1049 | |||
| 1050 | local octal_to_rwx = { | 987 | local octal_to_rwx = { |
| 1051 | ["0"] = "---", | 988 | ["0"] = "---", |
| 1052 | ["1"] = "--x", | 989 | ["1"] = "--x", |
| @@ -1064,9 +1001,7 @@ do | |||
| 1064 | if umask_cache then | 1001 | if umask_cache then |
| 1065 | return umask_cache | 1002 | return umask_cache |
| 1066 | end | 1003 | end |
| 1067 | -- LuaPosix (as of 34.0.4) only returns the umask as rwx | 1004 | local num = miniposix.umask() |
| 1068 | local rwx = posix.umask() | ||
| 1069 | local num = fs_lua._unix_rwx_to_number(rwx, true) | ||
| 1070 | umask_cache = ("%03o"):format(num) | 1005 | umask_cache = ("%03o"):format(num) |
| 1071 | return umask_cache | 1006 | return umask_cache |
| 1072 | end | 1007 | end |
| @@ -1078,27 +1013,23 @@ function fs_lua.set_permissions(filename, mode, scope) | |||
| 1078 | return false, err | 1013 | return false, err |
| 1079 | end | 1014 | end |
| 1080 | 1015 | ||
| 1081 | -- LuaPosix (as of 5.1.15) does not support octal notation... | ||
| 1082 | local new_perms = {} | 1016 | local new_perms = {} |
| 1083 | for c in perms:sub(-3):gmatch(".") do | 1017 | for c in perms:sub(-3):gmatch(".") do |
| 1084 | table.insert(new_perms, octal_to_rwx[c]) | 1018 | table.insert(new_perms, octal_to_rwx[c]) |
| 1085 | end | 1019 | end |
| 1086 | perms = table.concat(new_perms) | 1020 | perms = table.concat(new_perms) |
| 1087 | local err = posix.chmod(filename, perms) | 1021 | local err = miniposix.chmod(filename, perms) |
| 1088 | return err == 0 | 1022 | return err == 0 |
| 1089 | end | 1023 | end |
| 1090 | 1024 | ||
| 1091 | function fs_lua.current_user() | 1025 | function fs_lua.current_user() |
| 1092 | return posix.getpwuid(posix.geteuid()).pw_name | 1026 | return miniposix.getpwuid(miniposix.geteuid()).pw_name |
| 1093 | end | 1027 | end |
| 1094 | 1028 | ||
| 1095 | function fs_lua.is_superuser() | 1029 | function fs_lua.is_superuser() |
| 1096 | return posix.geteuid() == 0 | 1030 | return miniposix.geteuid() == 0 |
| 1097 | end | 1031 | end |
| 1098 | 1032 | ||
| 1099 | -- This call is not available on all systems, see #677 | ||
| 1100 | if posix.mkdtemp then | ||
| 1101 | |||
| 1102 | --- Create a temporary directory. | 1033 | --- Create a temporary directory. |
| 1103 | -- @param name_pattern string: name pattern to use for avoiding conflicts | 1034 | -- @param name_pattern string: name pattern to use for avoiding conflicts |
| 1104 | -- when creating temporary directory. | 1035 | -- when creating temporary directory. |
| @@ -1106,11 +1037,7 @@ if posix.mkdtemp then | |||
| 1106 | function fs_lua.make_temp_dir(name_pattern) | 1037 | function fs_lua.make_temp_dir(name_pattern) |
| 1107 | assert(type(name_pattern) == "string") | 1038 | assert(type(name_pattern) == "string") |
| 1108 | 1039 | ||
| 1109 | return posix.mkdtemp(temp_dir_pattern(name_pattern) .. "-XXXXXX") | 1040 | return miniposix.mkdtemp(temp_dir_pattern(name_pattern) .. "-XXXXXX") |
| 1110 | end | ||
| 1111 | |||
| 1112 | end -- if posix.mkdtemp | ||
| 1113 | |||
| 1114 | end | 1041 | end |
| 1115 | 1042 | ||
| 1116 | --------------------------------------------------------------------- | 1043 | --------------------------------------------------------------------- |
