Tho*_*ggi 6 javascript filesystems hardlink node.js
如何判断文件系统路径是否是与Node.js的硬链接?该功能fs.lstat提供了一个stats对象,给予时硬链接将为返回true stats.isDirectory()和stats.isFile()分别.fs.lstat不提供任何注意正常file或directory链接之间差异的内容.
If my understanding of how linking (ln) works is correct, then a linked file points to the same place on the disk as the original file. This would mean that both the original and linked version are identical, and there is no way to tell the difference between the original file and the linked.
The functionality I'm looking for is as follows:
This is hypothetical pseudo-code for demonstration & communication purposes.
fs.writeFileSync('./file.txt', 'hello world')
fs.linkSync('./file.txt', './link.txt')
fs.isLinkSync('./file.txt') // => false
fs.isLinkSync('./link.txt') // => true
fs.linkChildrenSync('./file.txt') // => ['./link.txt']
fs.linkChildrenSync('./link.txt') // => []
fs.linkParentSync('./link.txt') // => './file.txt'
fs.linkParentSync('./file.txt') // => null
Run Code Online (Sandbox Code Playgroud)
好吧..只是为了好玩...您可以选择通过某个目录中的索引节点查找文件。
一旦你从 stat 对象中获取了 inode ID。
fs.stat('./okay.file', function(err, stats){
var inodeID = stats.ino; // Double check that this is correct
});
Run Code Online (Sandbox Code Playgroud)
然后,您可以迭代文件夹中的所有文件,并使用条件检查 inode ID 是否匹配。获取目录中的所有文件。如果没有,您可以假设没有链接(在当前目录中)。
但是,我们似乎无法通过 inode id 搜索文件。请参阅:nodejs 通过 inode 打开 nfs 文件(或重新打开文件的最快方法)
fs.lstat:https://nodejs.org/api/fs.html#fs_fs_lstat_path_callback
统计对象: https: //nodejs.org/api/fs.html#fs_class_fs_stats
| 归档时间: |
|
| 查看次数: |
600 次 |
| 最近记录: |