oc-transcript-save 0.2.1 → 0.2.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.
- package/index.ts +2 -1
- package/package.json +1 -1
- package/transcript-save.ts +14 -2
package/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
toYaml,
|
|
29
29
|
truncateText,
|
|
30
30
|
} from './transcript-save.ts'
|
|
31
|
+
import path from 'node:path'
|
|
31
32
|
|
|
32
33
|
const SERVICE_NAME = 'oc-transcript-save'
|
|
33
34
|
|
|
@@ -218,7 +219,7 @@ function resolveOutputPath(ctx: AnyCtx, snapshot: Snapshot): string {
|
|
|
218
219
|
const timestamp = formatFilenameTimestamp(time.created)
|
|
219
220
|
const id = sanitiseFilename(asString(session.id, 'unknown-session'))
|
|
220
221
|
const root = process.env.OC_TRANSCRIPT_SAVE_PATH || asString(ctx.location?.directory, '') || process.cwd()
|
|
221
|
-
return
|
|
222
|
+
return path.join(root, `${timestamp}-${id}.md`)
|
|
222
223
|
}
|
|
223
224
|
|
|
224
225
|
async function fetchSnapshot(ctx: AnyCtx, sessionID: string): Promise<Snapshot> {
|
package/package.json
CHANGED
package/transcript-save.ts
CHANGED
|
@@ -596,8 +596,20 @@ export async function atomicWrite(filePath: string, content: string): Promise<nu
|
|
|
596
596
|
try {
|
|
597
597
|
await rename(tmpPath, filePath)
|
|
598
598
|
} catch (error) {
|
|
599
|
-
|
|
600
|
-
|
|
599
|
+
// POSIX rename atomically replaces the destination; Windows refuses to
|
|
600
|
+
// rename onto an existing file (EEXIST/EPERM). Remove it and retry.
|
|
601
|
+
if (process.platform === 'win32') {
|
|
602
|
+
await unlink(filePath).catch(() => undefined)
|
|
603
|
+
try {
|
|
604
|
+
await rename(tmpPath, filePath)
|
|
605
|
+
} catch (retryError) {
|
|
606
|
+
await unlink(tmpPath).catch(() => undefined)
|
|
607
|
+
throw retryError
|
|
608
|
+
}
|
|
609
|
+
} else {
|
|
610
|
+
await unlink(tmpPath).catch(() => undefined)
|
|
611
|
+
throw error
|
|
612
|
+
}
|
|
601
613
|
}
|
|
602
614
|
|
|
603
615
|
return Buffer.byteLength(normalised, 'utf8')
|