Skip to content

Commit 9946461

Browse files
authored
Fix creating tmp files on different volumes (#10)
1 parent def353a commit 9946461

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/hooks/useCellar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function useCellar() {
7575
throw new Error(`not-found:${pkgutils.str(pkg)}`)
7676
})()
7777
if (await vacant(installation.path)) {
78-
throw new Error(`not-found:${pkgutils.str(installation.pkg)}`)
78+
throw new Error(`not-found: ${pkgutils.str(installation.pkg)}`)
7979
}
8080
return installation
8181
}

src/prefab/install.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ export default async function install(pkg: Package, logger?: Logger): Promise<In
4444
const { project, version } = pkg
4545

4646
const cellar = useCellar()
47-
const { prefix: tea_prefix } = useConfig()
48-
const { compression } = useConfig().options
47+
const { prefix: tea_prefix, options: { compression } } = useConfig()
4948
const stowage = StowageNativeBottle({ pkg: { project, version }, compression })
5049
const url = useOffLicense('s3').url(stowage)
5150
const tarball = useCache().path(stowage)
@@ -67,8 +66,8 @@ export default async function install(pkg: Package, logger?: Logger): Promise<In
6766
logger?.downloading({pkg})
6867

6968
const tmpdir = Path.mktemp({
70-
prefix: pkg.project.replaceAll("/", "_") + "_",
71-
dir: tea_prefix.join("local/tmp")
69+
dir: tea_prefix.join("local/tmp").join(pkg.project),
70+
prefix: `v${pkg.version}.`
7271
//NOTE ^^ inside tea prefix to avoid TMPDIR is on a different volume problems
7372
})
7473
const tar_args = compression == 'xz' ? 'xJ' : 'xz' // laughably confusing

src/utils/Path.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { readLines } from "deno/io/read_lines.ts"
33
import * as sys from "deno/path/mod.ts"
44
import { PlainObject } from "is-what"
55
import * as fs from "deno/fs/mod.ts"
6+
import { mkdtempSync } from "node:fs"
7+
import * as os from "node:os"
68

79
// based on https://github.com/mxcl/Path.swift
810

@@ -208,8 +210,12 @@ export default class Path {
208210
}
209211

210212
static mktemp(opts?: { prefix?: string, dir?: Path }): Path {
211-
const {prefix, dir} = opts ?? {}
212-
const rv = Deno.makeTempDirSync({prefix, dir: dir?.mkdir('p').string})
213+
let {prefix, dir} = opts ?? {}
214+
dir ??= new Path(os.tmpdir())
215+
prefix ??= ""
216+
if (!prefix.startsWith('/')) prefix = `/${prefix}`
217+
// not using deno.makeTempDirSync because it's bugg’d and the node shim doesn’t handler `dir`
218+
const rv = mkdtempSync(`${dir.mkdir('p')}${prefix}`)
213219
return new Path(rv)
214220
}
215221

src/utils/semver.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ export default class SemVer {
8484
return this.compare(that) > 0
8585
}
8686

87+
gte(that: SemVer): boolean {
88+
return this.compare(that) >= 0
89+
}
90+
8791
lt(that: SemVer): boolean {
8892
return this.compare(that) < 0
8993
}
9094

95+
lte(that: SemVer): boolean {
96+
return this.compare(that) <= 0
97+
}
98+
9199
compare(that: SemVer): number {
92100
return _compare(this, that)
93101
}

0 commit comments

Comments
 (0)