Skip to content

A full-featured download manager.

fix: stabilize linux ci and improve scrollbar contrast (#2180)

Dr_rOot4a7424b1b9cd
diff --git a/packages/finalize-fs/src/platform/unix/mod.rs b/packages/finalize-fs/src/platform/unix/mod.rs
index 22c43ea2..ddd4d284 100644
--- a/packages/finalize-fs/src/platform/unix/mod.rs
+++ b/packages/finalize-fs/src/platform/unix/mod.rs
@@ -33,6 +33,7 @@ pub(crate) struct ArtifactHandle {
device: libc::dev_t,
inode: libc::ino_t,
opened_stamp: ArtifactStamp,
+ opened_link_count: libc::nlink_t,
opened_tree: Option<Vec<TreeEntrySnapshot>>,
opened_file_sha256: Option<[u8; 32]>,
}
@@ -203,6 +204,7 @@ fn open_artifact_internal(
device: opened_stat.st_dev,
inode: opened_stat.st_ino,
opened_stamp: artifact_stamp(&opened_stat),
+ opened_link_count: opened_stat.st_nlink,
opened_tree,
opened_file_sha256,
})
diff --git a/packages/finalize-fs/src/platform/unix/publish.rs b/packages/finalize-fs/src/platform/unix/publish.rs
index 84bf2b4c..17183f09 100644
--- a/packages/finalize-fs/src/platform/unix/publish.rs
+++ b/packages/finalize-fs/src/platform/unix/publish.rs
@@ -22,6 +22,8 @@ fn unchanged_file(artifact: &ArtifactHandle) -> io::Result<libc::stat> {
let stat = stat_opened(artifact.artifact.as_raw_fd())?;
if stat.st_mode & libc::S_IFMT != libc::S_IFREG
|| artifact_stamp(&stat) != artifact.opened_stamp
+ // ctime can stay unchanged for multiple mutations within one clock tick.
+ || stat.st_nlink != artifact.opened_link_count
{
return Err(io::Error::new(
io::ErrorKind::InvalidData,
diff --git a/packages/finalize-fs/src/platform/unix/tests.rs b/packages/finalize-fs/src/platform/unix/tests.rs
index 6dacdb41..b6369dba 100644
--- a/packages/finalize-fs/src/platform/unix/tests.rs
+++ b/packages/finalize-fs/src/platform/unix/tests.rs
@@ -227,7 +227,7 @@ fn held_link_is_exclusive_and_preserves_the_source() {
std::fs::write(base.join("source"), b"complete").unwrap();
std::fs::write(base.join("conflict"), b"unrelated").unwrap();
let root = open_root(base.to_str().unwrap()).unwrap();
- let artifact = super::open_artifact_for_rename(&root, "source").unwrap();
+ let mut artifact = super::open_artifact_for_rename(&root, "source").unwrap();
assert_eq!(
super::link_opened_no_replace(&artifact, &root, "conflict")
.unwrap_err()
@@ -238,8 +238,20 @@ fn held_link_is_exclusive_and_preserves_the_source() {
assert_eq!(std::fs::read(base.join("source")).unwrap(), b"complete");
assert_eq!(std::fs::read(base.join("target")).unwrap(), b"complete");
assert_eq!(std::fs::read(base.join("conflict")).unwrap(), b"unrelated");
- // Linking changes ctime. A stale pre-link handle must not authorize another mutation.
- assert!(super::link_opened_no_replace(&artifact, &root, "second").is_err());
+ // Model an inode timestamp tick shared by open and link. A real hard link
+ // changes nlink even when ctime does not advance; never sleep to force it.
+ let linked =
+ super::metadata::stat_opened(std::os::fd::AsRawFd::as_raw_fd(&artifact.artifact)).unwrap();
+ assert_eq!(linked.st_nlink, 2);
+ artifact.opened_stamp.changed_seconds = linked.st_ctime;
+ artifact.opened_stamp.changed_nanoseconds = linked.st_ctime_nsec;
+ assert_eq!(
+ super::link_opened_no_replace(&artifact, &root, "second")
+ .unwrap_err()
+ .kind(),
+ std::io::ErrorKind::InvalidData
+ );
+ assert!(!base.join("second").exists());
std::fs::remove_dir_all(base).unwrap();
}
diff --git a/src/core/engine/aria2/aria2-pause-state.ts b/src/core/engine/aria2/aria2-pause-state.ts
index 124030ba..e369570d 100644
--- a/src/core/engine/aria2/aria2-pause-state.ts
+++ b/src/core/engine/aria2/aria2-pause-state.ts
@@ -17,6 +17,11 @@ export class Aria2PauseState {
this.pending.clear()
}
+ getPendingPause(gid: string): Readonly<PendingPause> | undefined {
+ const pause = this.pending.get(gid)
+ return pause && performance.now() < pause.expiresAt ? pause : undefined
+ }
+
reconcile(
method: string,
params: unknown[],
diff --git a/src/core/engine/aria2/aria2-rpc-client.test.ts b/src/core/engine/aria2/aria2-rpc-client.test.ts
index 3167a35b..9fcb97c3 100644
--- a/src/core/engine/aria2/aria2-rpc-client.test.ts
+++ b/src/core/engine/aria2/aria2-rpc-client.test.ts
@@ -231,6 +231,83 @@ describe('Aria2RpcClient', () => {
expect(await client.tellStatus('gid1')).toEqual(active)
})
+ it('resumes once an accepted graceful pause finishes draining', async () => {
+ vi.useFakeTimers()
+ fakeProtocol.nextResult = 'gid1'
+ await client.pause('gid1')
+ const call = vi.spyOn(fakeProtocol, 'call')
+ call
+ .mockRejectedValueOnce(new Error('GID#gid1 cannot be unpaused now'))
+ .mockRejectedValueOnce(new Error('GID#gid1 cannot be unpaused now'))
+ .mockResolvedValueOnce('gid1')
+ const resuming = client.unpause('gid1')
+ await vi.advanceTimersByTimeAsync(200)
+ await expect(resuming).resolves.toBe('gid1')
+ expect(call).toHaveBeenCalledTimes(3)
+ fakeProtocol.nextResult = active
+ expect(await client.tellStatus('gid1')).toEqual(active)
+ })
+
+ it.each(['none', 'confirmed', 'other-gid'])(
+ 'does not retry a resume without its own unconfirmed pause: %s',
+ async (pause) => {
+ fakeProtocol.nextResult = pause === 'other-gid' ? 'gid2' : 'gid1'
+ if (pause !== 'none')
+ await client.pause(fakeProtocol.nextResult as string)
+ if (pause === 'confirmed') {
+ fakeProtocol.nextResult = { ...active, status: 'paused' }
+ await client.tellStatus('gid1')
+ }
+ const error = new Error('GID#gid1 cannot be unpaused now')
+ const call = vi.spyOn(fakeProtocol, 'call').mockRejectedValue(error)
+ await expect(client.unpause('gid1')).rejects.toBe(error)
+ expect(call).toHaveBeenCalledTimes(1)
+ }
+ )
+
+ it('allows a poll to confirm the pause while resume is waiting', async () => {
+ vi.useFakeTimers()
+ fakeProtocol.nextResult = 'gid1'
+ await client.pause('gid1')
+ const call = vi.spyOn(fakeProtocol, 'call')
+ call.mockRejectedValueOnce(new Error('GID#gid1 cannot be unpaused now'))
+ const resuming = client.unpause('gid1')
+ await vi.advanceTimersByTimeAsync(0)
+ fakeProtocol.nextResult = { ...active, status: 'paused' }
+ await client.tellStatus('gid1')
+ fakeProtocol.nextResult = 'gid1'
+ await vi.advanceTimersByTimeAsync(100)
+ await expect(resuming).resolves.toBe('gid1')
+ })
+
+ it.each(['disconnect', 'new-pause', 'expiry'])(
+ 'stops a pending resume when invalidated by %s',
+ async (invalidation) => {
+ vi.useFakeTimers()
+ fakeProtocol.nextResult = 'gid1'
+ await client.pause('gid1')
+ const error = new Error('GID#gid1 cannot be unpaused now')
+ const call = vi.spyOn(fakeProtocol, 'call').mockRejectedValue(error)
+ const resuming = expect(client.unpause('gid1')).rejects.toBe(error)
+ await vi.advanceTimersByTimeAsync(0)
+ if (invalidation === 'disconnect') client.disconnect()
+ if (invalidation === 'new-pause') {
+ call.mockResolvedValueOnce('gid1')
+ await client.pause('gid1')
+ }
+ const callsBeforeInvalidation = call.mock.calls.length
+ await vi.advanceTimersByTimeAsync(
+ invalidation === 'expiry' ? 30_000 : 100
+ )
+ await resuming
+ if (invalidation !== 'expiry')
+ expect(call).toHaveBeenCalledTimes(callsBeforeInvalidation)
+ const callsAfterInvalidation = call.mock.calls.length
+ await vi.advanceTimersByTimeAsync(1000)
+ expect(call).toHaveBeenCalledTimes(callsAfterInvalidation)
+ }
+ )
+
it('clears pending pauses across engine disconnection', async () => {
fakeProtocol.nextResult = 'gid1'
await client.pause('gid1')
diff --git a/src/core/engine/aria2/aria2-rpc-client.ts b/src/core/engine/aria2/aria2-rpc-client.ts
index 2e87331a..06654b88 100644
--- a/src/core/engine/aria2/aria2-rpc-client.ts
+++ b/src/core/engine/aria2/aria2-rpc-client.ts
@@ -158,8 +158,29 @@ export class Aria2RpcClient {
return this.call<string>('aria2.forcePause', [gid])
}
- unpause(gid: string): Promise<string> {
- return this.call<string>('aria2.unpause', [gid])
+ async unpause(gid: string): Promise<string> {
+ const pause = this.pauseState.getPendingPause(gid)
+ const wasUnconfirmed = pause?.confirmedBy === undefined
+ for (;;) {
+ try {
+ return await this.call<string>('aria2.unpause', [gid])
+ } catch (error) {
+ // A graceful BT pause is acknowledged before tracker requests drain.
+ // Retry only that accepted pause, within its existing settle deadline.
+ if (
+ !pause ||
+ !wasUnconfirmed ||
+ pause !== this.pauseState.getPendingPause(gid) ||
+ !(error instanceof Error) ||
+ error.message !== `GID#${gid} cannot be unpaused now`
+ ) {
+ throw error
+ }
+ await new Promise((resolve) => setTimeout(resolve, 100))
+ // Disconnect, expiry, or a newer pause invalidates this resume intent.
+ if (pause !== this.pauseState.getPendingPause(gid)) throw error
+ }
+ }
}
pauseAll(): Promise<'OK'> {
diff --git a/src/renderer/components/ui/scroll-area.tsx b/src/renderer/components/ui/scroll-area.tsx
index d51e313a..e69d3cf9 100644
--- a/src/renderer/components/ui/scroll-area.tsx
+++ b/src/renderer/components/ui/scroll-area.tsx
@@ -60,7 +60,7 @@ export function ScrollBar({
>
<ScrollAreaPrimitive.Thumb
data-slot="scroll-area-thumb"
- className="relative flex-1 rounded-full bg-foreground/25 hover:bg-foreground/40"
+ className="relative flex-1 rounded-full bg-foreground/70 hover:bg-foreground/85"
/>
</ScrollAreaPrimitive.Scrollbar>
)