Skip to content

Commit

Permalink
Merge cb8707b into 2097948
Browse files Browse the repository at this point in the history
  • Loading branch information
CxRes committed May 13, 2019
2 parents 2097948 + cb8707b commit 34fca2d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -167,6 +167,10 @@ instantiating the watching as chokidar discovers these file paths (before the `r
* `followSymlinks` (default: `true`). When `false`, only the
symlinks themselves will be watched for changes instead of following
the link references and bubbling events through the link's path.
* `reportErrorOnDanglingSymlinks` (default: `false`) When `followSymlinks: true`, Chokidar silently waits for paths under
dangling symlinks to be created. The user might instead want to confine Chokidar to wait for explicitly specified paths only.
When set to `true`, the dangling symlink is reported as an error instead and the absence of underlying symlinked path
is ignored.
* `cwd` (no default). The base directory from which watch `paths` are to be
derived. Paths emitted with events will be relative to this.
* `disableGlobbing` (default: `false`). If set to `true` then the strings passed to `.watch()` and `.add()` are treated as
Expand Down
20 changes: 19 additions & 1 deletion index.js
Expand Up @@ -287,6 +287,9 @@ constructor(_opts) {
if (opts.atomic) this._pendingUnlinks = new Map();

if (undef(opts, 'followSymlinks')) opts.followSymlinks = true;

if (undef(opts, 'reportErrorOnDanglingSymlinks')) opts.reportErrorOnDanglingSymlinks = false;
if (!opts.followSymlinks) opts.reportErrorOnDanglingSymlinks = false;

if (undef(opts, 'awaitWriteFinish')) opts.awaitWriteFinish = false;
if (opts.awaitWriteFinish === true) opts.awaitWriteFinish = {};
Expand Down Expand Up @@ -320,7 +323,7 @@ constructor(_opts) {
}

// You’re frozen when your heart’s not open.
Object.freeze(opts);
Object.freeze(opts); console.log(opts);
}

// Public methods
Expand Down Expand Up @@ -589,6 +592,21 @@ _handleError(error) {
return error || this.closed;
}

/**
* Special handler for dangling symlink errors
* @param {Error} error
* @returns {Boolean} True if Dangling conditions are met
*/
_handleDanglingSymlinkError(error) {
const code = error && error.code;
if (error && this.options.reportErrorOnDanglingSymlinks && code === 'ENOENT') {
error.message = `Dangling Symlink: ${error.message}`;
this.emit('error', error);
return true;
}
}


/**
* Helper utility for throttling
* @param {ThrottleType} actionType type being throttled
Expand Down
16 changes: 12 additions & 4 deletions lib/nodefs-handler.js
Expand Up @@ -515,8 +515,8 @@ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {

// evaluate what is at the path we're being asked to watch
try {
const stats = await statMethods[wh.statMethod](wh.watchPath);
if (this.fsw._isIgnored(wh.watchPath, stats)) {
const stats = await statMethods[wh.statMethod](wh.watchPath);
if (this.fsw._isIgnored(wh.watchPath, stats)) {
ready();
return false;
}
Expand Down Expand Up @@ -547,8 +547,16 @@ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
this.fsw._addPathCloser(path, closer);
return false;

} catch (error) {
if (this.fsw._handleError(error)) return path;
} catch (error) {
if (this.fsw._handleError(error)) {
// If path is a symlink, test if the error is due to a dangling symlink
// Based on the options user might want to report it and move on
// (rather than having to wait for the path to be recreated)
if (this.fsw._symlinkPaths.has(wh.watchPath)) {
if (this.fsw._handleDanglingSymlinkError(error)) ready();
}
return path;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions types/index.d.ts
Expand Up @@ -93,6 +93,15 @@ export interface WatchOptions {
*/
followSymlinks?: boolean;

/**
* When `followSymlinks: true`, Chokidar silently waits for paths under dangling symlinks to be
* created. The user might instead want to confine themselves to watch explicitly specified paths.
*
* If set to `true`, the dangling symlink is reported as an error and Chokidar ignores
* the absence of the underlying path.
*/
reportErrorOnDanglingSymlinks?: boolean;

/**
* The base directory from which watch `paths` are to be derived. Paths emitted with events will
* be relative to this.
Expand Down

0 comments on commit 34fca2d

Please sign in to comment.