You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit cbe59d1
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/path.md
+15-8Lines changed: 15 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ import {
17
17
} from"@openclaw/fs-safe/path";
18
18
```
19
19
20
-
These helpers are also re-exported from the main entry; the `/path` subpath is for callers that want the smallest possible import.
20
+
Only `root()`, `FsSafeError`, and the Python helper config live on the main entry. Path helpers are deliberately a subpath import so the main entry stays small.
Async. Same as `isPathInside`, but resolves both inputs through `realpath` first. Use this when you want the canonical answer and either input might be a symlink.
39
+
Synchronous. Same as `isPathInside`, but resolves both inputs through `realpath` first. Use this when you want the canonical answer and either input might be a symlink.
Throws on `realpath` failure for either input. Catch with `isNotFoundPathError(err)` if you want missing inputs to be a "no" rather than an exception.
45
+
```ts
46
+
typeOptions= {
47
+
requireRealpath?:boolean; // default true
48
+
cache?:Map<string, string>;
49
+
};
50
+
```
51
+
52
+
Does not throw on missing inputs — `realpath` failures are absorbed by the underlying `safeRealpathSync`. By default (`requireRealpath: true`) the function returns `false` when either input cannot be resolved. Pass `{ requireRealpath: false }` to fall back to the lexical answer from `isPathInside` instead.
46
53
47
54
### `isWithinDir(rootDir, targetPath)`
48
55
@@ -60,14 +67,14 @@ const base = resolveSafeBaseDir("/srv/uploads/."); // "/srv/uploads"
60
67
61
68
### `safeRealpathSync(targetPath, cache?)`
62
69
63
-
Synchronous `realpath` that returns `null` instead of throwing on missing paths. Pass an optional `Map<string, string>` to cache results across calls within a single operation.
70
+
Synchronous `realpath` that returns `null` instead of throwing on any error. Pass an optional `Map<string, string>` to cache results across calls within a single operation.
64
71
65
72
```ts
66
73
const real =safeRealpathSync("/srv/uploads/photo.jpg");
67
74
if (real===null) returnnotFound();
68
75
```
69
76
70
-
Errors other than `ENOENT` propagate normally.
77
+
All `realpath` failures collapse to `null` — there is no distinction between `ENOENT`, `EACCES`, and other I/O errors. Use `fs.realpathSync` directly if you need to branch on the error code.
71
78
72
79
### `safeStatSync(targetPath)`
73
80
@@ -133,7 +140,7 @@ try {
133
140
if (isNotFoundPathError(err)) returnreply(404);
134
141
throwerr;
135
142
}
136
-
if (!awaitisPathInsideWithRealpath("/srv/uploads", canonical)) {
143
+
if (!isPathInsideWithRealpath("/srv/uploads", canonical)) {
0 commit comments