Skip to content

Commit 8e33def

Browse files
committed
BitSum.ProcessLasso.Beta: Detect installer updates by the Last-Modified header, reset
1 parent 9bf3981 commit 8e33def

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

Tasks/BitSum.ProcessLasso.Beta/Script.ps1

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@ $this.CurrentState.Installer += $InstallerX86 = [ordered]@{
1515
InstallerUrl = $Object1.Links.Where({ try { $_.href.EndsWith('.exe') -and $_.href.Contains('beta') -and $_.href.Contains('32') } catch {} }, 'First')[0].href
1616
}
1717
$Object2 = Invoke-WebRequest -Uri $InstallerX86.InstallerUrl -Method Head
18-
$ETag = $Object2.Headers.ETag[0]
18+
# Last Modified
19+
$this.CurrentState.LastModified = $Object2.Headers.'Last-Modified'[0]
1920

2021
# x64
2122
$this.CurrentState.Installer += $InstallerX64 = [ordered]@{
2223
Architecture = 'x64'
2324
InstallerUrl = $Object1.Links.Where({ try { $_.href.EndsWith('.exe') -and $_.href.Contains('beta') -and $_.href.Contains('64') } catch {} }, 'First')[0].href
2425
}
2526
$Object3 = Invoke-WebRequest -Uri $InstallerX64.InstallerUrl -Method Head
26-
$ETagX64 = $Object3.Headers.ETag[0]
27+
# Last Modified
28+
$this.CurrentState.LastModifiedX64 = $Object3.Headers.'Last-Modified'[0]
2729

2830
# Case 0: Force submit the manifest
2931
if ($Global:DumplingsPreference.Contains('Force')) {
3032
$this.Log('Skip checking states', 'Info')
3133

32-
# ETag
33-
$this.CurrentState.ETag = @($ETag)
34-
$this.CurrentState.ETagX64 = @($ETagX64)
35-
3634
Read-Installer
3735

3836
$this.Print()
@@ -46,24 +44,26 @@ if ($Global:DumplingsPreference.Contains('Force')) {
4644
if ($this.Status.Contains('New')) {
4745
$this.Log('New task', 'Info')
4846

49-
# ETag
50-
$this.CurrentState.ETag = @($ETag)
51-
$this.CurrentState.ETagX64 = @($ETagX64)
52-
5347
Read-Installer
5448

5549
$this.Print()
5650
$this.Write()
5751
return
5852
}
5953

60-
# Case 2: The ETag is unchanged
61-
if ($ETag -in $this.LastState.ETag) {
62-
$this.Log("The version $($this.LastState.Version) from the last state is the latest (MSI)", 'Info')
54+
# Case 2: The Last Modified is unchanged
55+
if ([datetime]$this.CurrentState.LastModified -eq [datetime]$this.LastState.LastModified) {
56+
$this.Log("The version $($this.LastState.Version) from the last state is the latest (x86)", 'Info')
57+
return
58+
} elseif ([datetime]$this.CurrentState.LastModified -lt [datetime]$this.LastState.LastModified) {
59+
$this.Log("The last modified datetime from the current state `"$($this.CurrentState.LastModified)`" is older than the one from the last state `"$($this.LastState.LastModified)`" (x86)", 'Warning')
6360
return
6461
}
65-
if ($ETagX64 -in $this.LastState.ETagX64) {
66-
$this.Log("The version $($this.LastState.Version) from the last state is the latest (EXE)", 'Info')
62+
if ([datetime]$this.CurrentState.LastModifiedX64 -eq [datetime]$this.LastState.LastModifiedX64) {
63+
$this.Log("The version $($this.LastState.Version) from the last state is the latest (x64)", 'Info')
64+
return
65+
} elseif ([datetime]$this.CurrentState.LastModifiedX64 -lt [datetime]$this.LastState.LastModifiedX64) {
66+
$this.Log("The last modified datetime from the current state `"$($this.CurrentState.LastModifiedX64)`" is older than the one from the last state `"$($this.LastState.LastModifiedX64)`" (x64)", 'Warning')
6767
return
6868
}
6969

@@ -74,33 +74,25 @@ if ([string]::IsNullOrWhiteSpace($this.CurrentState.Version)) {
7474
throw 'The current state has an invalid version'
7575
}
7676

77-
# Case 4: The ETag has changed, but the SHA256 is not
77+
# Case 4: The Last Modified has changed, but the SHA256 is not
7878
if ($this.CurrentState.Installer[0].InstallerSha256 -eq $this.LastState.Installer[0].InstallerSha256) {
79-
$this.Log('The ETag has changed, but the SHA256 is not', 'Info')
80-
81-
# ETag
82-
$this.CurrentState.ETag = $this.LastState.ETag + $ETag
83-
$this.CurrentState.ETagX64 = $this.LastState.ETagX64 + $ETagX64
79+
$this.Log('The Last Modified has changed, but the SHA256 is not', 'Info')
8480

8581
$this.Write()
8682
return
8783
}
8884

89-
# ETag
90-
$this.CurrentState.ETag = @($ETag)
91-
$this.CurrentState.ETagX64 = @($ETagX64)
92-
9385
switch -Regex ($this.Check()) {
94-
# Case 6: The ETag, the SHA256 and the version have changed
86+
# Case 6: The Last Modified, the SHA256 and the version have changed
9587
'Updated|Rollbacked' {
9688
$this.Print()
9789
$this.Write()
9890
$this.Message()
9991
$this.Submit()
10092
}
101-
# Case 5: The ETag and the SHA256 have changed, but the version is not
93+
# Case 5: The Last Modified and the SHA256 have changed, but the version is not
10294
default {
103-
$this.Log('The ETag and the SHA256 have changed, but the version is not', 'Info')
95+
$this.Log('The Last Modified and the SHA256 have changed, but the version is not', 'Info')
10496
$this.Config.IgnorePRCheck = $true
10597
$this.Print()
10698
$this.Write()

Tasks/BitSum.ProcessLasso.Beta/State.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)