mirror of
https://github.com/stablyai/orca.git
synced 2026-10-22 00:03:47 +00:00
fix(windows): restore fresh-profile startup after durable fsync (#14173)
Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
Co-authored-by: DHTheOne <238933622+DHTheOne@users.noreply.github.com>
Co-authored-by: Anton Tupitsyn <70199858+PLUTONYY@users.noreply.github.com>
Co-authored-by: 7loop <48346764+7loop@users.noreply.github.com>
(cherry picked from commit e8044b1b30)
This commit is contained in:
@@ -424,8 +424,12 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Test Windows PowerShell CLI boundary
|
||||
run: pnpm exec vitest run --config config/vitest.config.ts src/main/cli/wsl-cli-powershell-boundary.test.ts
|
||||
- name: Test Windows-specific boundaries
|
||||
run: >-
|
||||
pnpm exec vitest run --config config/vitest.config.ts
|
||||
src/main/cli/wsl-cli-powershell-boundary.test.ts
|
||||
src/main/orca-profiles/profile-index-store.test.ts
|
||||
src/shared/secure-file-fsync-flags.test.ts
|
||||
|
||||
- name: Build package inputs
|
||||
run: pnpm run build:release
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import type * as NodeFs from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const openedPaths = vi.hoisted(() => [] as { path: string; flags: string | number }[])
|
||||
|
||||
vi.mock('node:fs', async () => {
|
||||
const actual = await vi.importActual<typeof NodeFs>('node:fs')
|
||||
return {
|
||||
...actual,
|
||||
openSync: (path: NodeFs.PathLike, flags: string | number, mode?: NodeFs.Mode) => {
|
||||
openedPaths.push({ path: String(path), flags })
|
||||
return actual.openSync(path, flags, mode)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
import { bestEffortFsyncDirectorySync, fsyncFileSync } from './secure-file'
|
||||
|
||||
const createdPaths: string[] = []
|
||||
|
||||
afterEach(() => {
|
||||
openedPaths.length = 0
|
||||
for (const path of createdPaths.splice(0)) {
|
||||
rmSync(path, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
describe('secure file fsync flags', () => {
|
||||
it('opens files read/write before fsync', () => {
|
||||
const directory = mkdtempSync(join(tmpdir(), 'orca-file-fsync-'))
|
||||
createdPaths.push(directory)
|
||||
const path = join(directory, 'record.json')
|
||||
writeFileSync(path, '{}')
|
||||
|
||||
fsyncFileSync(path)
|
||||
|
||||
expect(openedPaths).toEqual([{ path, flags: 'r+' }])
|
||||
})
|
||||
|
||||
const posixIt = process.platform === 'win32' ? it.skip : it
|
||||
posixIt('opens directories read-only before fsync', () => {
|
||||
const directory = mkdtempSync(join(tmpdir(), 'orca-directory-fsync-'))
|
||||
createdPaths.push(directory)
|
||||
|
||||
bestEffortFsyncDirectorySync(directory)
|
||||
|
||||
expect(openedPaths).toEqual([{ path: directory, flags: 'r' }])
|
||||
})
|
||||
})
|
||||
@@ -133,8 +133,8 @@ export function writeSecureFile(
|
||||
}
|
||||
}
|
||||
|
||||
export function fsyncFileSync(path: string): void {
|
||||
const descriptor = openSync(path, 'r')
|
||||
function fsyncPathSync(path: string, flags: 'r' | 'r+'): void {
|
||||
const descriptor = openSync(path, flags)
|
||||
try {
|
||||
fsyncSync(descriptor)
|
||||
} finally {
|
||||
@@ -142,12 +142,17 @@ export function fsyncFileSync(path: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function fsyncFileSync(path: string): void {
|
||||
// FlushFileBuffers requires a write-capable handle on Windows.
|
||||
fsyncPathSync(path, 'r+')
|
||||
}
|
||||
|
||||
export function bestEffortFsyncDirectorySync(directory: string): void {
|
||||
if (process.platform === 'win32') {
|
||||
return
|
||||
}
|
||||
try {
|
||||
fsyncFileSync(directory)
|
||||
fsyncPathSync(directory, 'r')
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
|
||||
Reference in New Issue
Block a user