Skip to content

Commit d1fc52a

Browse files
committed
Updater: do not mark installs/updates of optional requirements as failure when no suitable feed or download is found
1 parent f226cae commit d1fc52a

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

modules/DependencyControl.moon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ class DependencyControl
364364
if ._missing
365365
record = @@{moduleName:.moduleName, name:.name or .moduleName,
366366
version:-1, url:.url, feed:.feed, virtual:true}
367-
._ref, code, extErr = @@updater\require record, .version, addFeeds
368-
if ._ref
367+
._ref, code, extErr = @@updater\require record, .version, addFeeds, .optional
368+
if ._ref or .optional
369369
._updated, ._missing = true, false
370370
else
371371
._reason = @@updater\getUpdaterErrorMsg code, .name or .moduleName, true, true, extErr
@@ -388,7 +388,7 @@ class DependencyControl
388388
ref, code, extErr = @@updater\require record, .version, addFeeds
389389
if ref
390390
._ref = ref
391-
else
391+
elseif not .optional
392392
._outdated = true
393393
._reason = @@updater\getUpdaterErrorMsg code, .name or .moduleName, true, false, extErr
394394
else

modules/DependencyControl/Updater.moon

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class UpdaterBase
1414
[2]: "Skipping %s of %s '%s': namespace '%s' doesn't conform to rules."
1515
[3]: "Skipping %s of unmanaged %s '%s'."
1616
[4]: "No remaining feed available to %s %s '%s' from."
17-
[6]: "Couldn't retrieve data required to %s %s '%s'. Required version: %s."
17+
[6]: "The %s of %s '%s' failed because no suitable package could be found %s."
1818
[5]: "Skipped %s of %s '%s': Another update initiated by %s is already running."
1919
[10]: "Skipped %s of %s '%s': the update task is already running."
2020
[15]: "Couldn't %s %s '%s' because its requirements could not be satisfied:"
@@ -63,8 +63,11 @@ class UpdateTask extends UpdaterBase
6363
feedTrying: "Checking feed %d/%d (%s)..."
6464
upToDate: "%s '%s' is up-to-date (v%s)."
6565
alreadyUpdated: "%s v%s has already been installed."
66-
noFeedAvailExt: "%s (installed: %s; available: %s)"
66+
noFeedAvailExt: "(required: %s; installed: %s; available: %s)"
6767
noUpdate: "Feed has no new update."
68+
skippedOptional: "Skipped %s of optional dependency '%s': %s"
69+
optionalNoFeed: "No feed available to download module from."
70+
optionalNoUpdate: "No suitable download could be found %s."
6871
}
6972

7073
performUpdate: {
@@ -85,7 +88,7 @@ class UpdateTask extends UpdaterBase
8588
}
8689
}
8790

88-
new: (@record, targetVersion = 0, @addFeeds, @exhaustive, @channel, @updater) =>
91+
new: (@record, targetVersion = 0, @addFeeds, @exhaustive, @channel, @optional, @updater) =>
8992
DependencyControl or= require "l0.DependencyControl"
9093
assert @record.__class == DependencyControl, "First parameter must be a #{DependencyControl.__name} object."
9194

@@ -96,7 +99,7 @@ class UpdateTask extends UpdaterBase
9699
return nil, -1 unless @@config.c.updaterEnabled
97100
return nil, -2 unless @record\validateNamespace!
98101

99-
set: (targetVersion, @addFeeds, @exhaustive, @channel) =>
102+
set: (targetVersion, @addFeeds, @exhaustive, @channel, @optional) =>
100103
@targetVersion = @record\getVersionNumber targetVersion
101104
return @
102105

@@ -167,7 +170,13 @@ class UpdateTask extends UpdaterBase
167170
unless @triedFeeds[feed] or haveFeeds[feed]
168171
feeds[#feeds+1] = feed
169172

170-
return logUpdateError -4 if #feeds == 0
173+
if #feeds == 0
174+
if @optional
175+
@@logger\log msgs.run.skippedOptional, @record.name,
176+
@record.virtual and "download" or "update", msgs.run.optionalNoFeed
177+
return 3
178+
179+
return logUpdateError -4
171180

172181
-- get a lock on the updater
173182
success, otherHost = @updater\getLock waitLock
@@ -212,6 +221,12 @@ class UpdateTask extends UpdaterBase
212221
res = msgs.run.noFeedAvailExt\format @targetVersion == 0 and "any" or @record\getVersionString(@targetVersion),
213222
@record.virtual and "no" or @record\getVersionString!,
214223
maxVer<1 and "none" or @record\getVersionString maxVer
224+
225+
if @optional
226+
@@logger\log msgs.run.skippedOptional, @record.name, @record.virtual and "download" or "update",
227+
msgs.run.optionalNoUpdate\format res
228+
return 3
229+
215230
return logUpdateError -6, res
216231

217232
code, res = @performUpdate updateRecord
@@ -386,7 +401,7 @@ class Updater extends UpdaterBase
386401
super.config = globalConfig
387402
super.logger = logger if logger
388403

389-
addTask: (record, targetVersion, addFeeds = {}, exhaustive, channel) =>
404+
addTask: (record, targetVersion, addFeeds = {}, exhaustive, channel, optional) =>
390405
DependencyControl or= require "l0.DependencyControl"
391406
if record.__class != DependencyControl
392407
depRec = {saveRecordToConfig: false, readGlobalScriptVars: false}
@@ -395,9 +410,9 @@ class Updater extends UpdaterBase
395410

396411
task = @tasks[record.type][record.namespace]
397412
if task
398-
return task\set targetVersion, addFeeds, exhaustive, channel
413+
return task\set targetVersion, addFeeds, exhaustive, channel, optional
399414
else
400-
task = UpdateTask record, targetVersion, addFeeds, exhaustive, channel, @
415+
task = UpdateTask record, targetVersion, addFeeds, exhaustive, channel, optional, @
401416
@tasks[record.type][record.namespace] = task
402417
return task, err
403418

0 commit comments

Comments
 (0)