aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2025-03-04 01:41:58 -0300
committerHisham Muhammad <hisham@gobolinux.org>2025-03-10 10:51:04 -0300
commit86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4 (patch)
tree5c9b86835c20e8982492b1d0ad27b83bf407972d
parentd8775ec1e6b5d0b8750dc6bf379a76c01ac10e5f (diff)
downloadluarocks-86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4.tar.gz
luarocks-86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4.tar.bz2
luarocks-86d29c4e46bddf06b29f7d07c5c4e75b09ca69d4.zip
fs: begin making dependencies mandatory
-rw-r--r--src/luarocks/fs/lua.lua113
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")
5local fs_lua = {} 5local fs_lua = {}
6 6
@@ -9,22 +9,18 @@ local fs = require("luarocks.fs")
9local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
10local dir = require("luarocks.dir") 10local dir = require("luarocks.dir")
11local util = require("luarocks.core.util") 11local util = require("luarocks.core.util")
12local vers = require("luarocks.core.vers")
13 12
14local pack = table.pack or function(...) return { n = select("#", ...), ... } end 13local pack = table.pack or function(...) return { n = select("#", ...), ... } end
15 14
16local socket_ok, zip_ok, lfs_ok, md5_ok, posix_ok, bz2_ok, _ 15local http = require("socket.http")
17local http, ftp, zip, lfs, md5, posix, bz2 16local ftp = require("socket.ftp")
18 17local zip = require("luarocks.tools.zip")
19if cfg.fs_use_modules then 18local bz2 = require("bz2")
20 socket_ok, http = pcall(require, "socket.http") 19local lfs = require("lfs")
21 _, ftp = pcall(require, "socket.ftp") 20local md5 = require("md5")
22 zip_ok, zip = pcall(require, "luarocks.tools.zip") 21local miniposix = require("miniposix")
23 bz2_ok, bz2 = pcall(require, "bz2") 22local ltn12 = require("ltn12")
24 lfs_ok, lfs = pcall(require, "lfs") 23local https = require("ssl.https")
25 md5_ok, md5 = pcall(require, "md5")
26 posix_ok, posix = pcall(require, "posix")
27end
28 24
29local patch = require("luarocks.tools.patch") 25local patch = require("luarocks.tools.patch")
30local tar = require("luarocks.tools.tar") 26local tar = require("luarocks.tools.tar")
@@ -289,8 +285,6 @@ end
289-- LuaFileSystem functions 285-- LuaFileSystem functions
290--------------------------------------------------------------------- 286---------------------------------------------------------------------
291 287
292if lfs_ok then
293
294function fs_lua.file_age(filename) 288function 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)
684end 678end
685 679
686else -- if not lfs_ok
687
688function 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))
692end
693
694function fs_lua.file_age(_)
695 return math.huge
696end
697
698end
699
700--------------------------------------------------------------------- 680---------------------------------------------------------------------
701-- lua-bz2 functions 681-- lua-bz2 functions
702--------------------------------------------------------------------- 682---------------------------------------------------------------------
703 683
704if bz2_ok then
705
706local function bunzip2_string(data) 684local 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)
729end 707end
730 708
731end
732
733--------------------------------------------------------------------- 709---------------------------------------------------------------------
734-- luarocks.tools.zip functions 710-- luarocks.tools.zip functions
735--------------------------------------------------------------------- 711---------------------------------------------------------------------
736 712
737if zip_ok then
738
739function fs_lua.zip(zipfile, ...) 713function fs_lua.zip(zipfile, ...)
740 return zip.zip(zipfile, ...) 714 return zip.zip(zipfile, ...)
741end 715end
@@ -748,25 +722,13 @@ function fs_lua.gunzip(infile, outfile)
748 return zip.gunzip(infile, outfile) 722 return zip.gunzip(infile, outfile)
749end 723end
750 724
751end
752
753--------------------------------------------------------------------- 725---------------------------------------------------------------------
754-- LuaSocket functions 726-- LuaSocket/LuaSec functions
755--------------------------------------------------------------------- 727---------------------------------------------------------------------
756 728
757if socket_ok then
758
759local ltn12 = require("ltn12")
760local luasec_ok, https = pcall(require, "ssl.https")
761
762if luasec_ok and not vers.compare_versions(https._VERSION, "1.0.3") then
763 luasec_ok = false
764 https = nil
765end
766
767local redirect_protocols = { 729local redirect_protocols = {
768 http = http, 730 http = http,
769 https = luasec_ok and https, 731 https = https,
770} 732}
771 733
772local function request(url, method, http, loop_control) -- luacheck: ignore 431 734local 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
991end 952end
992 953
993else --...if socket_ok == false then
994
995function fs_lua.download(url, filename, cache)
996 return fs.use_downloader(url, filename, cache)
997end
998
999end
1000--------------------------------------------------------------------- 954---------------------------------------------------------------------
1001-- MD5 functions 955-- MD5 functions
1002--------------------------------------------------------------------- 956---------------------------------------------------------------------
1003 957
1004if md5_ok then
1005
1006-- Support the interface of lmd5 by lhf in addition to md5 by Roberto
1007-- and the keplerproject.
1008if not md5.sumhexa and md5.digest then
1009 md5.sumhexa = function(msg)
1010 return md5.digest(msg)
1011 end
1012end
1013
1014if 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
1027end 969end
1028 970
1029end
1030end
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)
1046end 985end
1047 986
1048if posix_ok then
1049
1050local octal_to_rwx = { 987local 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
1089end 1023end
1090 1024
1091function fs_lua.current_user() 1025function fs_lua.current_user()
1092 return posix.getpwuid(posix.geteuid()).pw_name 1026 return miniposix.getpwuid(miniposix.geteuid()).pw_name
1093end 1027end
1094 1028
1095function fs_lua.is_superuser() 1029function fs_lua.is_superuser()
1096 return posix.geteuid() == 0 1030 return miniposix.geteuid() == 0
1097end 1031end
1098 1032
1099-- This call is not available on all systems, see #677
1100if 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
1106function fs_lua.make_temp_dir(name_pattern) 1037function 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")
1110end
1111
1112end -- if posix.mkdtemp
1113
1114end 1041end
1115 1042
1116--------------------------------------------------------------------- 1043---------------------------------------------------------------------