commit bae9b9bb963b1709a861ef743a7600d53b71e379
parent 555f93ac27a2ae06a3391567027ea76bb34663be
Author: aabacchus <ben@bvnf.space>
Date: Thu, 15 Jun 2023 19:16:47 +0100
add checksum action
Diffstat:
3 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/README b/README
@@ -6,7 +6,7 @@ An implementation of the kiss package manager in Lua.
[ ] alternatives
[ ] build
[ ] hooks
-[ ] checksum
+[x] checksum
[x] download
[ ] install
[x] list
diff --git a/bliss/checksum.lua b/bliss/checksum.lua
@@ -0,0 +1,57 @@
+local utils = require 'bliss.utils'
+local b3sum = require 'bliss.b3sum'
+local pkg = require 'bliss.pkg'
+local download = require 'bliss.download'
+
+-- returns a string of the BLAKE3 checksum of the contents of filename
+local function checksum_file(filename)
+ local f = assert(io.open(filename))
+ local ctx = b3sum.init()
+ local buf = f:read(4096)
+ while buf do
+ b3sum.update(ctx, buf)
+ buf = f:read(4096)
+ end
+ f:close()
+ return b3sum.finalize(ctx, 33)
+end
+
+local function checksum(env, arg)
+ if #arg == 0 then utils.die("need a package") end
+ for _,p in ipairs(arg) do
+ local repo_dir = pkg.find(p, env.PATH)
+ local sources = pkg.find_sources(p, repo_dir)
+ local cache = pkg.resolve(p, sources, env, repo_dir)
+
+ download.download_sources(env, p, sources, cache)
+
+ local f = assert(io.open(repo_dir .. '/checksums', 'w'))
+
+ local sums = ''
+ for i, v in ipairs(cache) do
+ local map = {['git+'] = 1, ['http'] = 2}
+ local t = map[string.sub(sources[i][1], 1, 4)] or 3
+ if t ~= 1 then
+ local sum = checksum_file(v)
+ sums = sums .. sum .. '\n'
+ end
+ end
+ if #sums ~= 0 then
+ f:write(sums)
+ utils.log(p, "Generated checksums")
+ else
+ utils.log(p, "No sources needing checksums")
+ end
+ f:close()
+ end
+end
+
+local function verify_checksums(pkg, path)
+ -- TODO
+end
+
+local M = {
+ checksum = checksum,
+ checksum_file = checksum_file,
+}
+return M
diff --git a/bliss/init.lua b/bliss/init.lua
@@ -3,7 +3,7 @@ local cwd = (...):gsub('%.init$', '')
local M = {}
-- merge these into the toplevel bliss module
-local names = {'utils', 'search', 'list', 'pkg', 'download'}
+local names = {'utils', 'search', 'list', 'pkg', 'download', 'checksum'}
for _, name in ipairs(names) do
local t = require(cwd .. '.' .. name)
for k, v in pairs(t) do