为什么nodejs可以使用dircortory进行硬链接?

时间:2017-11-08 03:12:48

标签: node.js linux macos hyperlink

os版本:

➜  showlink sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.1
BuildVersion:   17B35a
在执行脚本之前

➜ showlink tree --inodes .
.
└── [9628588]  test
    ├── [9628740]  link.js
    └── [9628707]  src

2 directories, 1 file

nodejs脚本:

const fs = require('fs')
const path = require('path')
const src = path.resolve(__dirname, './src')
//i try to the dist at the same dir with src, but failed 
const dist = path.join(__dirname, '../dist')
fs.link(src, dist, (err) => console.log(err))

后:

➜  showlink tree --inodes  .
.
├── [9628707]  dist
└── [9628588]  test
    ├── [9628740]  link.js
    └── [9628707]  src

3 directories, 1 file

添加一些文件

➜  showlink touch test/src/demo{1..3}

现在:

➜  showlink tree --inodes  .
.
├── [9628707]  dist
│   ├── [9629200]  demo1
│   ├── [9629201]  demo2
│   └── [9629202]  demo3
└── [9628588]  test
    ├── [9628740]  link.js
    └── [9628707]  src
        ├── [9629200]  demo1
        ├── [9629201]  demo2
        └── [9629202]  demo3

3 directories, 7 files

当我搜索谷歌的“硬链接”时,所有答案都告诉我:dir无法建立硬链接。但是...... node.js创建了dir的硬链接(Brackets中的数字是i节点号)。发生了什么? 感谢

0 个答案:

没有答案