mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
answer realpath from cache instead of round-tripping to the server
This commit is contained in:
@@ -392,22 +392,6 @@ router.get("/access", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/realpath", async (req, res) => {
|
||||
const resolved = guardPath(req, res);
|
||||
|
||||
if (!resolved) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const real = await fs.promises.realpath(resolved);
|
||||
|
||||
res.json({ path: path.relative(req._vaultRoot, real) });
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: e.code || "internal", code: e.code });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/fs/utimes { path, atime, mtime, vault? }
|
||||
router.post("/utimes", async (req, res) => {
|
||||
const resolved = guardPath(req, res, "body");
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
resolvePath,
|
||||
} from "./transforms.js";
|
||||
import { hasVirtualFile, getVirtualFile } from "./virtual-files.js";
|
||||
import { realpathSync } from "./realpath.js";
|
||||
|
||||
export function createFsPromises(metadataCache, contentCache, transport) {
|
||||
return {
|
||||
@@ -260,7 +261,8 @@ export function createFsPromises(metadataCache, contentCache, transport) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
return transport.realpath(path);
|
||||
// No symlinks in the vault FS, so realpath is the identity.
|
||||
return realpathSync(path);
|
||||
},
|
||||
|
||||
async utimes(path, atime, mtime) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { realpath } from "./realpath.js";
|
||||
import { createFsPromises } from "./promises.js";
|
||||
|
||||
describe("fs realpath shim", () => {
|
||||
it("realpath invokes the callback with the path", async () => {
|
||||
@@ -18,3 +19,18 @@ describe("fs realpath shim", () => {
|
||||
expect(result).toBe("/a/b.md");
|
||||
});
|
||||
});
|
||||
|
||||
describe("fs.promises realpath", () => {
|
||||
it("answers locally without touching the transport", async () => {
|
||||
const fs = createFsPromises({}, {}, {});
|
||||
|
||||
expect(await fs.realpath("/a/b.md")).toBe("/a/b.md");
|
||||
});
|
||||
|
||||
it("maps empty and root paths to /", async () => {
|
||||
const fs = createFsPromises({}, {}, {});
|
||||
|
||||
expect(await fs.realpath("")).toBe("/");
|
||||
expect(await fs.realpath(".")).toBe("/");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -177,13 +177,6 @@ export const transport = {
|
||||
return requestJson("GET", "/access", { path: normPath(path) });
|
||||
},
|
||||
|
||||
async realpath(path) {
|
||||
const result = await requestJson("GET", "/realpath", {
|
||||
path: normPath(path),
|
||||
});
|
||||
return result.path;
|
||||
},
|
||||
|
||||
async utimes(path, atime, mtime) {
|
||||
return requestJson("POST", "/utimes", {
|
||||
path: normPath(path),
|
||||
|
||||
Reference in New Issue
Block a user