Skip to content

Commit

Permalink
refactor(fs/watch): validate path/id in 'fs.Watcher'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Oct 30, 2023
1 parent 069e70f commit 581fe4e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ Chages ownership of link at `path` with `uid` and `gid.

## [`link(src, dest, )`](https://github.com/socketsupply/socket/blob/master/api/fs/index.js#L368)

Creates a link to `dest` from `dest`.
Creates a link to `dest` from `src`.

| Argument | Type | Default | Optional | Description |
| :--- | :--- | :---: | :---: | :--- |
Expand Down
4 changes: 2 additions & 2 deletions api/fs/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export class Dir {
}

/**
* `true` if closeing, otherwise `false`.
* `true` if closing, otherwise `false`.
* @ignore
* @type {boolean}
*/
get closing () {
return Boolean(this.handle?.closig)
return Boolean(this.handle?.closing)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/fs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export function lchown (path, uid, gid, callback) {
}

/**
* Creates a link to `dest` from `dest`.
* Creates a link to `dest` from `src`.
* @param {string} src
* @param {string} dest
* @param {function}
Expand Down
8 changes: 8 additions & 0 deletions api/fs/watcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter } from '../events.js'
import { FileHandle } from './handle.js'
import { AbortError } from '../errors.js'
import { rand64 } from '../crypto.js'
import { Buffer } from '../buffer.js'
Expand Down Expand Up @@ -32,6 +33,13 @@ function encodeFilename (watcher, filename) {
* @return {Promise}
*/
async function start (watcher) {
// throws if not accessible
await FileHandle.access(watcher.path)

if (!watcher.id || typeof watcher.id !== 'string') {
throw new TypeError('Expectig fs.Watcher to have a id.')
}

const result = await ipc.send('fs.watch', {
path: watcher.path,
id: watcher.id
Expand Down
4 changes: 2 additions & 2 deletions api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ declare module "socket:fs/dir" {
*/
get closed(): boolean;
/**
* `true` if closeing, otherwise `false`.
* `true` if closing, otherwise `false`.
* @ignore
* @type {boolean}
*/
Expand Down Expand Up @@ -2955,7 +2955,7 @@ declare module "socket:fs/index" {
*/
export function lchown(path: string, uid: number, gid: number, callback: Function): void;
/**
* Creates a link to `dest` from `dest`.
* Creates a link to `dest` from `src`.
* @param {string} src
* @param {string} dest
* @param {function}
Expand Down

0 comments on commit 581fe4e

Please sign in to comment.