routify icon indicating copy to clipboard operation
routify copied to clipboard

Ignore patterns vs dangling symlinks

Open tv42 opened this issue 3 years ago • 3 comments

Emacs by default uses dangling symbolic links to guard against accidentally editing the same file from two editors: https://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html

In practice, this looks like

$ find -name '.#*' -ls
  6017389      4 lrwxrwxrwx   1 tv       tv             22 Aug 26 09:02 ./src/pages/test/.#foo.svelte -> [email protected]:1597784741

Since these symlinks have the same extension as the original file, they have a long history of triggering bugs in programs that either don't filter out hidden files, or just get very confused about seeing danling symlinks.

This causes routify to log errors like

[Routify] ✖ Failed to watch pages directory [Error: ENOENT: no such file or directory, stat 'src/pages/project/[project]/.#domains.svelte'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: 'src/pages/project/[project]/.#domains.svelte'
}
(node:68) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '/src/src/pages/project/[project]/.#domains.svelte'

and it seems ignore patterns are not used for watching files:

$ cat routify.config.js 
module.exports = {
  routifyDir: "_routify",
  ignore: "**/.#*",
}

Things that could be improved:

  1. ignore config is undocumented and assumes user just knows what's acceptable. The docs don't even say it's a glob pattern.

  2. Watch functionality should obey ignore too.

  3. lib/middleware/generateFileTree.js isAcceptedDir seems to already filter out leading underscores, it could filter out leading . too.

  4. Based on a quick read, lib/middleware/generateFileTree.js applies the filter isIgnored too late; by the time isIgnored is used, the file has already been stat(2)'ed (isDirectory).

  5. Same as above, it seems isIgnored doesn't apply to the else branch of if (isDir) at all.

tv42 avatar Aug 26 '20 15:08 tv42