fs.symlink给了我ELOOP错误

时间:2013-12-17 19:04:40

标签: node.js filesystems symlink

> fs.symlinkSync('client', 'build/client', 'dir')

> fs.statSync('build/client/index.js')
Error: ELOOP, too many symbolic links encountered 'build/client/index.js'
    at Object.fs.lstatSync (fs.js:679:18)
    at repl:1:5
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您必须将目标目录设置为相对或绝对:

fs.symlinkSync('../client', 'build/client', 'dir');

我在symlink(2)中使用相同的目录结构和路径名时确认行为相同:

// Directory structure
build/
client/
  –> index.js

// Fails
$ ln -s client build/client 
$ stat build/client/index.js
stat: build/client/index.js: stat: Too many levels of symbolic links

// Works
$ ln -s ../client build/client 
$ stat build/client/index.js
stat: <outputs file stats>

目标HAS是相对的或绝对的。即使在节点中,我们知道client将在需求调用中解析为cwd,甚至fs.read/writefs.symlink中的symlink(2)也不是{ {1}}。

更新

我的推理得到了Unix / Linux人员的证实。 See this post for details