@codua/codeoutline-win32-x64 0.3.0 → 0.3.2

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.
@@ -34,9 +34,9 @@ end
34
34
  local leases={}
35
35
  -- Returns nil outside an update directory (the initial installation is never pruned).
36
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()
37
+ local root,version=files_root:gsub('\\','/'):match('^(.*)/versions/([^/]+)/files/?$')
38
+ if not root or not c.version(version) or not u.mkdir_p(root .. '/leases') then return nil end
39
+ local path=root .. '/leases/' .. version .. '-' .. token()
40
40
  local handle
41
41
  if windows then
42
42
  handle=io.open(path,'wb');if not handle then return nil end
@@ -67,13 +67,29 @@ function M.open(config)
67
67
  local data=c.read(root .. '/current.json',1048576)
68
68
  if not data then
69
69
  assert(not u.stat(root .. '/current.json').exists,'local state unreadable')
70
- return {schema=1,highSequence=config.minimumSequence or 0}
70
+ return {schema=2,highSequence=config.minimumSequence or 0}
71
71
  end
72
72
  local value=assert(c.decode_json(data),'corrupt local state')
73
- assert(value.schema==1 and type(value.highSequence)=='number' and value.highSequence>=0 and value.highSequence%1==0,'invalid local state')
73
+ assert(type(value.highSequence)=='number' and value.highSequence>=0 and value.highSequence%1==0,'invalid local state')
74
74
  value.highSequence=math.max(value.highSequence,config.minimumSequence or 0)
75
- assert(not value.current or (type(value.current)=='string' and #value.current==64 and value.current:match('^[0-9a-f]+$')),'invalid current')
76
- assert(not value.previous or (type(value.previous)=='string' and #value.previous==64 and value.previous:match('^[0-9a-f]+$')),'invalid previous')
75
+ if value.schema==1 then
76
+ for _, key in ipairs({ 'current', 'previous' }) do
77
+ local identity=value[key]
78
+ assert(not identity or type(identity)=='string' and #identity==64
79
+ and identity:match('^[0-9a-f]+$'), 'invalid legacy ' .. key .. ' identity')
80
+ end
81
+ -- Retire hash-based activation without loading old code or changing
82
+ -- files during startup. The next locked write saves schema 2 while
83
+ -- preserving the replay floor. Old processes may still use the cache.
84
+ return {schema=2,highSequence=value.highSequence}
85
+ end
86
+ assert(value.schema==2, 'unsupported update state')
87
+ for _, key in ipairs({ 'current', 'previous' }) do
88
+ local version, identity = value[key], value[key .. 'Identity']
89
+ assert(not version or c.version(version), 'invalid ' .. key .. ' version')
90
+ assert(not version and not identity or version and type(identity)=='string'
91
+ and #identity==64 and identity:match('^[0-9a-f]+$'), 'invalid ' .. key .. ' identity')
92
+ end
77
93
  return value
78
94
  end
79
95
  local function save(value)c.atomic(root .. '/current.json',assert(u.json_pack(value)))end
@@ -93,12 +109,16 @@ function M.open(config)
93
109
  local now,busy=os.time(),{}
94
110
  for _,entry in ipairs(u.list_dir(root .. '/leases') or {})do
95
111
  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
112
+ local version=entry.name:match('^(%d+%.%d+%.%d+)%-%x+$')
113
+ local legacy=entry.name:match('^(%x+)%-%x+$')
114
+ if not version then
115
+ if not legacy or #legacy~=64 then os.remove(path) end
116
+ elseif lease_alive(path)then busy[version]=true end
99
117
  end
100
118
  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]
119
+ -- Hash-named directories belong to old bootstraps whose leases are
120
+ -- incompatible. Leave them untouched until users stop old processes.
121
+ local removable=entry.dir and c.version(entry.name) and not keep[entry.name] and not busy[entry.name]
102
122
  -- Versions predating leases may still run unseen: delete them only
103
123
  -- after a grace period counted from the first prune that saw them.
104
124
  if removable and config.leased and not config.leased(root .. '/versions/' .. entry.name .. '/files') then
@@ -146,7 +166,8 @@ function M.open(config)
146
166
  local envelope=c.decode_json(assert(c.read(dir .. '/manifest.json',1048576)))
147
167
  local m=verified(envelope)
148
168
  assert(u.stat(dir .. '/complete').exists,'installation incomplete')
149
- assert(u.sha256_hex(envelope.payload)==s.current,'invalid active identity')
169
+ assert(m.version==s.current,'active version directory mismatch')
170
+ assert(u.sha256_hex(envelope.payload)==s.currentIdentity,'invalid active identity')
150
171
  local files=c.bundle(assert(c.read(dir .. '/bundle.json')),m)
151
172
  for _,f in ipairs(files)do assert(c.read(dir .. '/files/' .. f.path)==f.data,'installed file changed')end
152
173
  for path, hash in pairs(m.runtimeFiles or {}) do
@@ -168,9 +189,18 @@ function M.open(config)
168
189
  return locked(function()
169
190
  local s=state()
170
191
  assert(m.sequence>=s.highSequence,'downgrade/replay rejected; use explicit local rollback')
171
- if s.current==identity then return api.current()end
172
- if m.sequence==s.highSequence and s.current then assert(s.previous==identity,'different content at previously accepted sequence')end
173
- local dir=root .. '/versions/' .. identity
192
+ if s.current==m.version then
193
+ assert(s.currentIdentity==identity, 'different content for an installed version; publish a new version number')
194
+ return api.current()
195
+ end
196
+ if m.sequence==s.highSequence and s.current then assert(s.previousIdentity==identity,'different content at previously accepted sequence')end
197
+ local dir=root .. '/versions/' .. m.version
198
+ if u.stat(dir .. '/complete').exists then
199
+ local existing=assert(c.decode_json(c.read(dir .. '/manifest.json',1048576)), 'installed manifest missing')
200
+ local original=verified(existing)
201
+ assert(original.version==m.version and u.sha256_hex(existing.payload)==identity,
202
+ 'different content for an installed version; publish a new version number')
203
+ end
174
204
  if not u.stat(dir .. '/complete').exists then
175
205
  assert(u.mkdir_p(dir .. '/files'))
176
206
  for _,f in ipairs(files)do
@@ -207,25 +237,27 @@ function M.open(config)
207
237
  end
208
238
  if config.validate then assert(config.validate(dir .. '/files',m),'project health validation failed')end
209
239
  local previous=config.keepPrevious~=false and s.current or nil
210
- save({schema=1,highSequence=math.max(s.highSequence,m.sequence),previous=previous,current=identity})
240
+ save({schema=2,highSequence=math.max(s.highSequence,m.sequence),previous=previous,
241
+ previousIdentity=previous and s.currentIdentity or nil,current=m.version,currentIdentity=identity})
211
242
  local ok,result=pcall(api.current)
212
243
  if not ok then save(s);error(result)end
213
244
  -- Cleanup never fails an installation that is already active.
214
- if config.prune then pcall(prune,{[identity]=true,[previous or identity]=true})end
245
+ if config.prune then pcall(prune,{[m.version]=true,[previous or m.version]=true})end
215
246
  return result
216
247
  end)
217
248
  end
218
249
  function api.use_initial()
219
250
  return locked(function()
220
251
  local s=state()
221
- save({schema=1,highSequence=s.highSequence,previous=s.current})
252
+ save({schema=2,highSequence=s.highSequence,previous=s.current,previousIdentity=s.currentIdentity})
222
253
  return {initial=true}
223
254
  end)
224
255
  end
225
256
  function api.rollback()
226
257
  return locked(function()
227
258
  local s=state();assert(s.previous,'no previous version')
228
- save({schema=1,highSequence=s.highSequence,current=s.previous,previous=s.current})
259
+ save({schema=2,highSequence=s.highSequence,current=s.previous,currentIdentity=s.previousIdentity,
260
+ previous=s.current,previousIdentity=s.currentIdentity})
229
261
  local ok,result=pcall(api.current)
230
262
  if not ok then save(s);error(result)end
231
263
  return result
@@ -43,10 +43,10 @@ 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 or m.minUpdater == 2, 'unsupported updater version')
46
+ assert(m.minUpdater == 1 or m.minUpdater == 2 or m.minUpdater == 3, 'unsupported updater version')
47
47
  assert(m.kind == nil or m.kind == 'full' or m.kind == 'scripts', 'invalid package kind')
48
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')
49
+ assert(m.minUpdater >= 2 and type(m.runtimeFiles) == 'table' and M.path(m.runtime), 'script package requires updater 2 or newer and runtime references')
50
50
  local count, seen = 0, {}
51
51
  for path, hash in pairs(m.runtimeFiles) do
52
52
  assert(M.path(path) and type(hash) == 'string' and #hash == 64 and hash:match('^[0-9a-f]+$'), 'invalid runtime reference')
@@ -122,10 +122,15 @@ make_handler = function(state)
122
122
  local h = {}
123
123
 
124
124
  function h.on_connect(conn)
125
+ -- The runtime's default send queue is 10 MiB. A request is sent as a
126
+ -- single buffer, so size this connection's queue for that buffer.
127
+ if #state.request_bytes > 10 * 1024 * 1024 and conn.set_max_send then
128
+ conn:set_max_send(#state.request_bytes)
129
+ end
125
130
  local ok, serr = conn:send_raw(state.request_bytes)
126
131
  if not ok then
127
- conn:close('send_failed')
128
132
  fire_once(state, 'send failed: ' .. tostring(serr))
133
+ conn:close('send_failed')
129
134
  end
130
135
  end
131
136