fix(config): handle unavailable config directories (#35632)
Co-authored-by: James Long <jlongster@users.noreply.github.com>
This commit is contained in:
@@ -60,9 +60,10 @@ export namespace FSUtil {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const readFileStringSafe = Effect.fn("FileSystem.readFileStringSafe")(function* (path: string) {
|
const readFileStringSafe = Effect.fn("FileSystem.readFileStringSafe")(function* (path: string) {
|
||||||
return yield* fs
|
return yield* fs.readFileString(path).pipe(
|
||||||
.readFileString(path)
|
Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(undefined)),
|
||||||
.pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(undefined)))
|
Effect.catchReason("PlatformError", "PermissionDenied", () => Effect.succeed(undefined)),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const isDir = Effect.fn("FileSystem.isDir")(function* (path: string) {
|
const isDir = Effect.fn("FileSystem.isDir")(function* (path: string) {
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ const layer = Layer.effect(
|
|||||||
})
|
})
|
||||||
|
|
||||||
const ensureGitignore = Effect.fn("Config.ensureGitignore")(function* (dir: string) {
|
const ensureGitignore = Effect.fn("Config.ensureGitignore")(function* (dir: string) {
|
||||||
|
yield* fs.ensureDir(dir)
|
||||||
const gitignore = path.join(dir, ".gitignore")
|
const gitignore = path.join(dir, ".gitignore")
|
||||||
const hasIgnore = yield* fs.existsSafe(gitignore)
|
const hasIgnore = yield* fs.existsSafe(gitignore)
|
||||||
if (!hasIgnore) {
|
if (!hasIgnore) {
|
||||||
|
|||||||
@@ -923,6 +923,31 @@ it.effect("does not try to install dependencies in read-only OPENCODE_CONFIG_DIR
|
|||||||
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(LayerNode.compile(CrossSpawnSpawner.node))),
|
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(LayerNode.compile(CrossSpawnSpawner.node))),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
it.effect("ignores an inaccessible OPENCODE_CONFIG_DIR", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
if (process.platform === "win32") return
|
||||||
|
|
||||||
|
const dir = yield* tmpdirScoped()
|
||||||
|
const configDir = path.join(dir, "inaccessible")
|
||||||
|
yield* FSUtil.use.ensureDir(configDir)
|
||||||
|
yield* FSUtil.use.chmod(configDir, 0o000)
|
||||||
|
yield* Effect.addFinalizer(() => FSUtil.use.chmod(configDir, 0o755).pipe(Effect.ignore))
|
||||||
|
|
||||||
|
yield* withProcessEnv("OPENCODE_CONFIG_DIR", configDir, Config.use.get().pipe(provideInstanceEffect(dir)))
|
||||||
|
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(LayerNode.compile(CrossSpawnSpawner.node))),
|
||||||
|
)
|
||||||
|
|
||||||
|
it.effect("creates a missing OPENCODE_CONFIG_DIR", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const dir = yield* tmpdirScoped()
|
||||||
|
const configDir = path.join(dir, "configdir")
|
||||||
|
|
||||||
|
yield* withProcessEnv("OPENCODE_CONFIG_DIR", configDir, Config.use.get().pipe(provideInstanceEffect(dir)))
|
||||||
|
|
||||||
|
expect(yield* FSUtil.use.readFileString(path.join(configDir, ".gitignore"))).toContain("node_modules")
|
||||||
|
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(LayerNode.compile(CrossSpawnSpawner.node))),
|
||||||
|
)
|
||||||
|
|
||||||
it.effect("installs dependencies in writable OPENCODE_CONFIG_DIR", () =>
|
it.effect("installs dependencies in writable OPENCODE_CONFIG_DIR", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const dir = yield* tmpdirScoped()
|
const dir = yield* tmpdirScoped()
|
||||||
|
|||||||
Reference in New Issue
Block a user