Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 810ceda

Browse files
authored
add realpath (#319)
* add realpath * add test case for symbols * check range is correct as well
1 parent 8c96e46 commit 810ceda

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/storage-file/src/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export async function readFileRange(
3737
let fd: fs.FileHandle | null = null;
3838
let res: Buffer;
3939
try {
40+
// adjust for symbolic links
41+
filePath = await fs.realpath(filePath);
4042
const { size } = await fs.lstat(filePath);
4143
// build offset and length as necessary
4244
if (suffix !== undefined) {

packages/storage-file/test/index.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ test("FileStorage: getRangeMaybeExpired: suffix: returns partial values", async
163163
t.is(utf8Decode(getAll?.value), "123456789");
164164
t.deepEqual(getAll?.range, { offset: 0, length: 9 });
165165
});
166+
test("FileStorage: getRangeMaybeExpired: check that symbolic links are resolved appropriately", async (t) => {
167+
const storage = await storageFactory.factory(t, {});
168+
await storage.put("inner/key", { value: utf8Encode("value") });
169+
// create the symbolic link
170+
await fs.symlink(
171+
// @ts-ignore
172+
path.join(storage.root, "inner/key"),
173+
// @ts-ignore
174+
path.join(storage.root, "key")
175+
);
176+
const getResult = await storage.getRangeMaybeExpired("key", { offset: 0 });
177+
t.is(utf8Decode(getResult?.value), "value");
178+
t.deepEqual(getResult?.range, { offset: 0, length: 5 });
179+
});
166180

167181
async function unsanitisedStorageFactory(
168182
t: ExecutionContext

0 commit comments

Comments
 (0)