@codua/codeoutline-win32-x64 0.1.4 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,29 @@
1
1
  -- Background update thread: network, verification and installation stay off the
2
- -- service thread. An installed update applies to the next launch.
2
+ -- service thread. Checks at startup and then hourly while the service runs.
3
3
  local source = assert(xutils.realpath(debug.getinfo(1, 'S').source:sub(2))):gsub('\\', '/')
4
4
  local scripts = assert(source:match('^(.*)/codeoutline/[^/]+$'))
5
5
  package.path = scripts .. '/?.lua;' .. package.path
6
6
  local updater = require('codeoutline.updater')
7
+ local INTERVAL_MS = 3600000
8
+ local checking = false
9
+
10
+ local function check()
11
+ if checking then return end
12
+ checking = true
13
+ local ok, err = pcall(function()
14
+ require('xupgate.client').open(updater.config()).update(function(update_error, result)
15
+ checking = false
16
+ xthread.post(1, 'update_result', update_error, result and result.version)
17
+ end)
18
+ end)
19
+ if not ok then checking = false; xthread.post(1, 'update_result', tostring(err)) end
20
+ end
7
21
 
8
22
  return {
9
23
  __init = function()
10
24
  assert(xnet.init()); xtimer.init(16)
11
- local ok, err = pcall(function()
12
- require('xupgate.client').open(updater.config()).update(function(update_error, result)
13
- xthread.post(1, 'update_result', update_error, result and result.version)
14
- end)
15
- end)
16
- if not ok then xthread.post(1, 'update_result', tostring(err)) end
25
+ check()
26
+ xtimer.add(INTERVAL_MS, check, -1)
17
27
  end,
18
28
  __uninit = function() xnet.uninit() end,
19
29
  __thread_handle = function() end,
@@ -19,6 +19,14 @@ function M.config(options)
19
19
  directory=os.getenv('CODEOUTLINE_UPDATE_DIR') or assert(home,'set CODEOUTLINE_UPDATE_DIR') .. '/.codeoutline/updates',
20
20
  minimumSequence=tonumber(os.getenv('CODEOUTLINE_UPDATE_MIN_SEQUENCE')) or build.updateSequence or 0,
21
21
  http=require('xupgate.http_client'),
22
+ runtimeDirectory=install,
23
+ -- Keep only the active version; npm reinstalls are the way back.
24
+ keepPrevious=false,prune=true,
25
+ -- Versions before 0.1.7 run without leases.
26
+ leased=function(files)
27
+ local sdk=c.read(files .. '/scripts/xupgate/client.lua')
28
+ return sdk~=nil and sdk:find('function M.lease',1,true)~=nil
29
+ end,
22
30
  }
23
31
  cfg.validate=function(root,m)
24
32
  local info=c.decode_json(c.read(root .. '/build-info.json'))
@@ -57,10 +65,6 @@ function M.run(action,options)
57
65
  assert(xnet.init());xtimer.init(16)
58
66
  -- Selection is local only; serve updates in its background thread.
59
67
  if action=='select' then finish(nil)
60
- elseif action=='rollback' then
61
- local ok,result=pcall(api.rollback)
62
- if not ok and tostring(result):find('no previous version',1,true)then ok,result=pcall(api.use_initial)end
63
- finish(not ok and tostring(result) or nil,ok and result or nil)
64
68
  elseif action=='current' then local ok,result=pcall(api.current);finish(not ok and tostring(result) or nil,ok and result or nil)
65
69
  elseif action=='check' then api.check(finish)
66
70
  else api.update(finish)end
@@ -1 +1 @@
1
- return '0.1.4'
1
+ return '0.1.8'
@@ -329,7 +329,11 @@ function Lang:tokenize(src)
329
329
 
330
330
  while pos <= len do
331
331
  local c = src:byte(pos)
332
- if c == 10 then
332
+ if c == 10 then -- \n
333
+ -- Newlines outside tokens are counted here; strings and block
334
+ -- comments jump past theirs and add them with count_nl. Indent
335
+ -- mode ends a logical line, but not inside brackets, and blank or
336
+ -- comment-only lines collapse into the previous 'nl'.
333
337
  if indent_mode and depth == 0 and n > 0 and K[n] ~= 'nl' and not skip then
334
338
  push('nl', pos, pos, line)
335
339
  end
@@ -337,21 +341,30 @@ function Lang:tokenize(src)
337
341
  pos = pos + 1
338
342
  bol = true
339
343
  elseif c == 32 or c == 9 or c == 13 or c == 12 or c == 11 then
344
+ -- Space, tab, \r, \f, \v. bol stays set, so indentation and a
345
+ -- directive '#' are still judged at the first real token; the \r
346
+ -- of \r\n is skipped here and its \n counted above.
340
347
  pos = pos + 1
341
348
  elseif indent_mode and c == 92 and (src:byte(pos + 1) == 10
342
349
  or (src:byte(pos + 1) == 13 and src:byte(pos + 2) == 10)) then
343
350
  -- Python `\` continuation: the next line joins this logical line
351
+ -- (no 'nl', and bol stays clear so its indentation is ignored).
344
352
  pos = pos + (src:byte(pos + 1) == 10 and 2 or 3)
345
353
  line = line + 1
346
354
  else
355
+ -- Anything else starts a token, comment or directive. Every token
356
+ -- except 'nl' is pushed below; each case advances pos past what it
357
+ -- consumed, and the operator case always consumes at least a byte.
358
+
347
359
  -- Indentation (Python): measured at the first real token of a line.
348
360
  if indent_mode and bol and depth == 0 then
349
361
  local col_start = pos
350
362
  while col_start > 1 and src:byte(col_start - 1) ~= 10 do col_start = col_start - 1 end
351
- local width = 0
363
+ local width = 0 -- tabs advance to the next multiple of 8
352
364
  for x = col_start, pos - 1 do
353
365
  width = width + ((src:byte(x) == 9) and (8 - width % 8) or 1)
354
366
  end
367
+ -- Comment-only lines do not open or close blocks.
355
368
  local is_comment = false
356
369
  for _, lc in ipairs(self.line_comment) do
357
370
  if starts(src, pos, lc) then is_comment = true end
@@ -402,6 +415,9 @@ function Lang:tokenize(src)
402
415
  end
403
416
  bol = false
404
417
 
418
+ -- The cases below are tried in order; the first match wins.
419
+ -- Line comment: skipped up to (not including) the newline, which
420
+ -- the \n branch then handles.
405
421
  if not handled then
406
422
  for _, lc in ipairs(self.line_comment) do
407
423
  if starts(src, pos, lc) then
@@ -419,6 +435,7 @@ function Lang:tokenize(src)
419
435
  end
420
436
  end
421
437
  end
438
+ -- Lua long string [==[ ... ]==]: one 'str' token.
422
439
  if not handled and long_brackets then
423
440
  local lb = long_open(src, pos)
424
441
  if lb then
@@ -430,11 +447,14 @@ function Lang:tokenize(src)
430
447
  handled = true
431
448
  end
432
449
  end
450
+ -- Block comment: skipped, its newlines still counted. An unclosed
451
+ -- one runs to the end of the file.
433
452
  if not handled then
434
453
  for _, bc in ipairs(self.block_comment) do
435
454
  if starts(src, pos, bc[1]) then
436
455
  local stop
437
456
  if nested_comments then
457
+ -- Rust: /* /* */ */ closes at the outer */
438
458
  local nest, p = 1, pos + #bc[1]
439
459
  while p + #bc[2] - 1 <= len do
440
460
  if starts(src, p, bc[1]) then
@@ -460,6 +480,7 @@ function Lang:tokenize(src)
460
480
  end
461
481
  end
462
482
  end
483
+ -- JS template literal `...${...}...`: one 'str' token, nesting included.
463
484
  if not handled and template_literals and c == 96 then
464
485
  local stop = skip_template(src, pos)
465
486
  local l0 = line
@@ -468,6 +489,8 @@ function Lang:tokenize(src)
468
489
  pos = stop + 1
469
490
  handled = true
470
491
  end
492
+ -- JS regex literal: only where an operand may start; when the line
493
+ -- ends before the closing '/', it falls through as a division.
471
494
  if not handled and regex_literals and c == 47 and regex_allowed(src, K, S, E, n, ctrl_close) then
472
495
  local stop = scan_regex(src, pos, id_char)
473
496
  if stop then
@@ -476,6 +499,7 @@ function Lang:tokenize(src)
476
499
  handled = true
477
500
  end
478
501
  end
502
+ -- Rust lifetime 'a: an 'id', so it is not read as an unclosed char.
479
503
  if not handled and lifetimes and c == 39 then
480
504
  local stop = scan_lifetime(src, pos, id_start, id_char)
481
505
  if stop then
@@ -484,6 +508,8 @@ function Lang:tokenize(src)
484
508
  handled = true
485
509
  end
486
510
  end
511
+ -- Rust raw string r"..", r#".."#, br"..", cr"..": one 'str' token.
512
+ -- Otherwise r/b/c fall through to an identifier.
487
513
  if not handled and raw_strings and (c == 114 or c == 98 or c == 99) then
488
514
  local stop = scan_raw_string(src, pos, id_char)
489
515
  if stop then
@@ -496,6 +522,9 @@ function Lang:tokenize(src)
496
522
  end
497
523
  if not handled then
498
524
  -- String, optionally after a prefix (r"", b'', f"""...""").
525
+ -- A prefix counts only at the start of a word (not the end of
526
+ -- `abc"`). A single-line string stops at the newline, so a
527
+ -- stray quote cannot swallow the rest of the file.
499
528
  local q = pos
500
529
  while self.prefixes[src:byte(q)] and q - pos < 2 do q = q + 1 end
501
530
  for _, st in ipairs(self.strings) do
@@ -529,12 +558,16 @@ function Lang:tokenize(src)
529
558
  end
530
559
  end
531
560
  if not handled then
561
+ -- Identifier or keyword: the longest run of identifier bytes
562
+ -- (bytes >= 0x80 included, so UTF-8/GBK names stay whole).
532
563
  if id_start[c] then
533
564
  local p = pos + 1
534
565
  while p <= len and id_char[src:byte(p)] do p = p + 1 end
535
566
  local word = src:sub(pos, p - 1)
536
567
  push(keywords[word] and 'kw' or 'id', pos, p - 1, line)
537
568
  pos = p
569
+ -- Number: a digit, or '.' then a digit. Takes identifier
570
+ -- bytes, '.' and the C++14 separator ' (0x1F, 1.5f, 1'000).
538
571
  elseif (c >= 48 and c <= 57) or (c == 46 and (src:byte(pos + 1) or 0) >= 48 and (src:byte(pos + 1) or 0) <= 57) then
539
572
  local p = pos + 1
540
573
  while p <= len do
@@ -551,6 +584,8 @@ function Lang:tokenize(src)
551
584
  push('num', pos, p - 1, line)
552
585
  pos = p
553
586
  else
587
+ -- Operator or punctuation: the longest configured operator
588
+ -- starting with this byte, else the single byte itself.
554
589
  local w = 1
555
590
  local list = ops[c]
556
591
  if list then
@@ -558,11 +593,15 @@ function Lang:tokenize(src)
558
593
  if starts(src, pos, op) then w = #op; break end
559
594
  end
560
595
  end
596
+ -- Bracket depth: indent mode ignores newlines inside brackets,
597
+ -- and directives use it to choose which #if arms to keep.
561
598
  if w == 1 and not skip then
562
599
  if OPEN[c] then depth = depth + 1
563
600
  elseif CLOSE[c] and depth > 0 then depth = depth - 1 end
564
601
  end
565
602
  push('op', pos, pos + w - 1, line)
603
+ -- Track which ')' closes an if/while/for/with condition:
604
+ -- a '/' right after one starts a regex, not a division.
566
605
  if regex_literals and w == 1 and not skip then
567
606
  if c == 40 then
568
607
  local prev = n - 1
@@ -11,6 +11,47 @@ end
11
11
  local function command_ok(command)
12
12
  local ok=os.execute(command);return ok==true or ok==0
13
13
  end
14
+ -- A lease marks an installed version as used by a live process; pruning keeps
15
+ -- leased versions. Windows holds the lease file open, so it cannot be deleted
16
+ -- until the process exits; elsewhere the file names a PID checked with kill -0.
17
+ local windows=package.config:sub(1,1)=='\\'
18
+ local LEGACY_GRACE=7*86400
19
+ local function token()
20
+ return u.sha256_hex(tostring(os.time()) .. tostring(os.clock()) .. tostring({}) .. tostring(math.random())):sub(1,16)
21
+ end
22
+ local function process_id()
23
+ local pipe=io.popen('echo $PPID');if not pipe then return nil end
24
+ local pid=pipe:read('a');pipe:close()
25
+ return tonumber(pid:match('^%s*(%d+)%s*$'))
26
+ end
27
+ -- A lease whose owner has exited is removed and reported free.
28
+ local function lease_alive(path)
29
+ if windows then return not os.remove(path)end
30
+ local pid=tonumber((c.read(path,64) or ''):match('^(%d+)'))
31
+ if pid and pid>1 and command_ok('kill -0 ' .. pid .. ' 2>/dev/null')then return true end
32
+ os.remove(path);return false
33
+ end
34
+ local leases={}
35
+ -- Returns nil outside an update directory (the initial installation is never pruned).
36
+ function M.lease(files_root)
37
+ local root,identity=files_root:gsub('\\','/'):match('^(.*)/versions/(%x+)/files/?$')
38
+ if not root or #identity~=64 or not u.mkdir_p(root .. '/leases') then return nil end
39
+ local path=root .. '/leases/' .. identity .. '-' .. token()
40
+ local handle
41
+ if windows then
42
+ handle=io.open(path,'wb');if not handle then return nil end
43
+ else
44
+ local pid=process_id();if not pid or not pcall(c.write,path,pid .. '\n')then return nil end
45
+ end
46
+ local lease={}
47
+ function lease.release()
48
+ if handle then handle:close();handle=nil end
49
+ os.remove(path);leases[lease]=nil
50
+ end
51
+ -- Referenced here so garbage collection never closes the held handle.
52
+ leases[lease]=true
53
+ return lease
54
+ end
14
55
  function M.open(config)
15
56
  assert(c.id(config.project) and c.id(config.platform),'invalid project/platform')
16
57
  assert(type(config.publicKey)=='string','pinned publicKey required')
@@ -46,11 +87,59 @@ function M.open(config)
46
87
  if not ok then error(result) end
47
88
  return result
48
89
  end
90
+ -- Remove versions other than keep that no live process leases, then the
91
+ -- runtime cache, which only feeds installation.
92
+ local function prune(keep)
93
+ local now,busy=os.time(),{}
94
+ for _,entry in ipairs(u.list_dir(root .. '/leases') or {})do
95
+ local path=root .. '/leases/' .. entry.name
96
+ local identity=entry.name:match('^(%x+)%-%x+$')
97
+ if not identity then os.remove(path)
98
+ elseif lease_alive(path)then busy[identity]=true end
99
+ end
100
+ for _,entry in ipairs(u.list_dir(root .. '/versions') or {})do
101
+ local removable=entry.dir and not keep[entry.name] and not busy[entry.name]
102
+ -- Versions predating leases may still run unseen: delete them only
103
+ -- after a grace period counted from the first prune that saw them.
104
+ if removable and config.leased and not config.leased(root .. '/versions/' .. entry.name .. '/files') then
105
+ local marker=root .. '/retired/' .. entry.name
106
+ local info=u.stat(marker)
107
+ if not (info and info.exists) then c.write(marker,now .. '\n');removable=false
108
+ else removable=now-(info.mtime or now)>=(config.legacyGrace or LEGACY_GRACE) end
109
+ end
110
+ if removable then
111
+ -- Moving first keeps a half-deleted tree out of versions/.
112
+ assert(u.mkdir_p(root .. '/trash'))
113
+ os.rename(root .. '/versions/' .. entry.name,root .. '/trash/' .. entry.name .. '-' .. token())
114
+ end
115
+ end
116
+ for _,entry in ipairs(u.list_dir(root .. '/trash') or {})do u.rmtree(root .. '/trash/' .. entry.name)end
117
+ for _,entry in ipairs(u.list_dir(root .. '/retired') or {})do
118
+ if not u.stat(root .. '/versions/' .. entry.name).exists then os.remove(root .. '/retired/' .. entry.name)end
119
+ end
120
+ if u.stat(root .. '/runtime-cache').exists then u.rmtree(root .. '/runtime-cache')end
121
+ end
49
122
  local function verified(envelope)
50
123
  local m=c.manifest(envelope,config.publicKey)
51
124
  assert(m.project==config.project and m.platform==config.platform,'manifest target mismatch')
52
125
  return m
53
126
  end
127
+ function api.cache_runtime(envelope, data, scripts)
128
+ local full = verified(envelope)
129
+ local reference = assert(scripts.runtimeRelease, 'runtime release reference missing')
130
+ assert(scripts.kind == 'scripts' and full.kind ~= 'scripts' and full.version == reference.version
131
+ and full.sequence == reference.sequence and full.sha256 == reference.sha256, 'runtime release mismatch')
132
+ local source_files = {}
133
+ for _, file in ipairs(c.bundle(data, full)) do source_files[file.path] = file.data end
134
+ for path, hash in pairs(scripts.runtimeFiles) do
135
+ assert(source_files[path] and u.sha256_hex(source_files[path]) == hash, 'runtime release file mismatch')
136
+ end
137
+ return locked(function()
138
+ local directory = root .. '/runtime-cache/' .. reference.sha256 .. '/files'
139
+ for path in pairs(scripts.runtimeFiles) do c.write(directory .. '/' .. path, source_files[path]) end
140
+ return directory
141
+ end)
142
+ end
54
143
  function api.current()
55
144
  local s=state();if not s.current then return nil end
56
145
  local dir=root .. '/versions/' .. s.current
@@ -60,7 +149,10 @@ function M.open(config)
60
149
  assert(u.sha256_hex(envelope.payload)==s.current,'invalid active identity')
61
150
  local files=c.bundle(assert(c.read(dir .. '/bundle.json')),m)
62
151
  for _,f in ipairs(files)do assert(c.read(dir .. '/files/' .. f.path)==f.data,'installed file changed')end
63
- return {version=m.version,sequence=m.sequence,root=dir .. '/files',entry=m.entry,runtime=m.runtime,sha256=m.sha256}
152
+ for path, hash in pairs(m.runtimeFiles or {}) do
153
+ assert(u.sha256_hex(assert(c.read(dir .. '/files/' .. path), 'runtime file missing')) == hash, 'installed runtime changed')
154
+ end
155
+ return {version=m.version,sequence=m.sequence,root=dir .. '/files',entry=m.entry,runtime=m.runtime,sha256=m.sha256,kind=m.kind or 'full'}
64
156
  end
65
157
  function api.install(envelope,data)
66
158
  local m=verified(envelope);local files=c.bundle(data,m)
@@ -77,14 +169,41 @@ function M.open(config)
77
169
  c.write(dir .. '/files/' .. f.path,f.data)
78
170
  if f.executable and package.config:sub(1,1)~='\\' then assert(command_ok('chmod 755 ' .. shell_path(dir .. '/files/' .. f.path)),'chmod failed')end
79
171
  end
172
+ if m.kind == 'scripts' then
173
+ local candidates = { config.runtimeDirectory }
174
+ if s.current then candidates[#candidates + 1] = root .. '/versions/' .. s.current .. '/files' end
175
+ if s.previous then candidates[#candidates + 1] = root .. '/versions/' .. s.previous .. '/files' end
176
+ if m.runtimeRelease then candidates[#candidates + 1] = root .. '/runtime-cache/' .. m.runtimeRelease.sha256 .. '/files' end
177
+ local runtime_root
178
+ for _, candidate in ipairs(candidates) do
179
+ local matches = true
180
+ for path, hash in pairs(m.runtimeFiles) do
181
+ local bytes = c.read(candidate .. '/' .. path)
182
+ if not bytes or u.sha256_hex(bytes) ~= hash then matches = false; break end
183
+ end
184
+ if matches then runtime_root = candidate; break end
185
+ end
186
+ assert(runtime_root, 'compatible local runtime missing; install a full update first')
187
+ for path, hash in pairs(m.runtimeFiles) do
188
+ local bytes = assert(c.read(runtime_root .. '/' .. path))
189
+ assert(u.sha256_hex(bytes) == hash, 'runtime changed during installation')
190
+ c.write(dir .. '/files/' .. path, bytes)
191
+ if package.config:sub(1,1) ~= '\\' and (path == m.runtime or path:match('^bin/')) then
192
+ assert(command_ok('chmod 755 ' .. shell_path(dir .. '/files/' .. path)), 'chmod failed')
193
+ end
194
+ end
195
+ end
80
196
  c.write(dir .. '/bundle.json',data)
81
197
  c.write(dir .. '/manifest.json',assert(u.json_pack(envelope)))
82
198
  c.atomic(dir .. '/complete','1\n')
83
199
  end
84
200
  if config.validate then assert(config.validate(dir .. '/files',m),'project health validation failed')end
85
- save({schema=1,highSequence=math.max(s.highSequence,m.sequence),previous=s.current,current=identity})
201
+ local previous=config.keepPrevious~=false and s.current or nil
202
+ save({schema=1,highSequence=math.max(s.highSequence,m.sequence),previous=previous,current=identity})
86
203
  local ok,result=pcall(api.current)
87
204
  if not ok then save(s);error(result)end
205
+ -- Cleanup never fails an installation that is already active.
206
+ if config.prune then pcall(prune,{[identity]=true,[previous or identity]=true})end
88
207
  return result
89
208
  end)
90
209
  end
@@ -126,6 +245,33 @@ function M.open(config)
126
245
  if download_error then callback(download_error);return end
127
246
  if resp.status~=200 then callback('package HTTP ' .. resp.status);return end
128
247
  local ok,result=pcall(api.install,update.envelope,resp.body)
248
+ if not ok and update.manifest.runtimeRelease and tostring(result):find('compatible local runtime missing', 1, true) then
249
+ local scripts_data = resp.body
250
+ local reference = update.manifest.runtimeRelease
251
+ http.request({url=base .. '/api/v1/projects/' .. config.project .. '/releases/' .. reference.version .. '/' .. config.platform,
252
+ timeout_ms=15000,max_redirects=0,verify=true,ca_file=config.caFile},function(reference_error,reference_response)
253
+ if reference_error then callback(reference_error);return end
254
+ if reference_response.status~=200 then callback('runtime reference HTTP ' .. reference_response.status);return end
255
+ local valid, envelope = pcall(function()
256
+ local envelope = assert(c.decode_json(reference_response.body))
257
+ local full = verified(envelope)
258
+ assert(full.kind ~= 'scripts' and full.version == reference.version and full.sequence == reference.sequence
259
+ and full.sha256 == reference.sha256, 'runtime reference mismatch')
260
+ return envelope
261
+ end)
262
+ if not valid then callback(tostring(envelope));return end
263
+ http.request({url=base .. '/packages/' .. reference.sha256 .. '.json',timeout_ms=120000,max_redirects=0,
264
+ verify=true,ca_file=config.caFile,decompress=false},function(runtime_error,runtime_response)
265
+ if runtime_error then callback(runtime_error);return end
266
+ if runtime_response.status~=200 then callback('runtime package HTTP ' .. runtime_response.status);return end
267
+ local cached, failure = pcall(api.cache_runtime, envelope, runtime_response.body, update.manifest)
268
+ if not cached then callback(tostring(failure));return end
269
+ local installed, current = pcall(api.install, update.envelope, scripts_data)
270
+ callback(not installed and tostring(current) or nil, installed and current or nil)
271
+ end)
272
+ end)
273
+ return
274
+ end
129
275
  callback(not ok and tostring(result) or nil,ok and result or nil)
130
276
  end)
131
277
  end)
@@ -43,7 +43,24 @@ function M.manifest(envelope, public_key)
43
43
  assert(require('xupgate.signature').verify(public_key, envelope.payload, sig), 'manifest signature invalid')
44
44
  local m = assert(M.decode_json(envelope.payload), 'invalid manifest JSON')
45
45
  assert(m.schema == 1 and M.id(m.project) and M.version(m.version) and M.id(m.platform), 'invalid manifest identity')
46
- assert(m.minUpdater == 1, 'unsupported updater version')
46
+ assert(m.minUpdater == 1 or m.minUpdater == 2, 'unsupported updater version')
47
+ assert(m.kind == nil or m.kind == 'full' or m.kind == 'scripts', 'invalid package kind')
48
+ if m.kind == 'scripts' then
49
+ assert(m.minUpdater == 2 and type(m.runtimeFiles) == 'table' and M.path(m.runtime), 'script package requires updater 2 and runtime references')
50
+ local count, seen = 0, {}
51
+ for path, hash in pairs(m.runtimeFiles) do
52
+ assert(M.path(path) and type(hash) == 'string' and #hash == 64 and hash:match('^[0-9a-f]+$'), 'invalid runtime reference')
53
+ assert(not seen[path:lower()], 'duplicate runtime reference'); seen[path:lower()] = true
54
+ count = count + 1
55
+ end
56
+ assert(count > 0 and count <= 1000 and m.runtimeFiles[m.runtime], 'runtime reference missing')
57
+ if m.runtimeRelease then
58
+ local r = m.runtimeRelease
59
+ assert(type(r) == 'table' and M.version(r.version) and type(r.sequence) == 'number'
60
+ and r.sequence > 0 and r.sequence % 1 == 0 and r.sequence < m.sequence
61
+ and type(r.sha256) == 'string' and #r.sha256 == 64 and r.sha256:match('^[0-9a-f]+$'), 'invalid runtime release reference')
62
+ end
63
+ else assert(m.runtimeFiles == nil and m.runtimeRelease == nil, 'runtime references require a script package') end
47
64
  assert(type(m.sha256) == 'string' and #m.sha256 == 64 and m.sha256:match('^[0-9a-f]+$'), 'invalid package hash')
48
65
  assert(type(m.size) == 'number' and m.size > 0 and m.size <= 50331648 and m.size % 1 == 0, 'invalid package size')
49
66
  assert(type(m.sequence) == 'number' and m.sequence >= 1 and m.sequence % 1 == 0, 'invalid release sequence')
@@ -65,6 +82,11 @@ function M.bundle(data, manifest)
65
82
  decoded[#decoded+1] = { path = f.path, data = bytes, executable = f.executable == true }
66
83
  if f.path == manifest.entry then entry = true end
67
84
  end
85
+ if manifest.kind == 'scripts' then
86
+ for path in pairs(manifest.runtimeFiles) do
87
+ local key = path:lower(); assert(not seen[key], 'runtime/script file collision'); seen[key] = true
88
+ end
89
+ end
68
90
  for key in pairs(seen) do
69
91
  local prefix = key:match('^(.*)/[^/]+$')
70
92
  while prefix do assert(not seen[prefix], 'file/directory collision'); prefix = prefix:match('^(.*)/[^/]+$') end