Node.js symlink junctions are broken on Windows?

允我心安 提交于 2019-12-10 12:02:54

问题


First, here's the code:

const FS = require('fs');
const OS = require('os');
const symlinkType = OS.platform() === 'win32' ? 'junction' : 'file';

FS.symlink(target, path, symlinkType, err => {
    if(err) {
        console.error(`Failed to create ${symlinkType} ${path} -> ${target}`);
    } else {
        console.log(`Created ${symlinkType} ${path} -> ${target}`);
    }
})

This spits out a bunch of messages like this:

Created junction C:\Users\Mark\*snip*\data\Pacific\Midway.txt -> C:\Users\Mark\*snip*\data\Pacific\Pago_Pago.txt
Created junction C:\Users\Mark\*snip*\data\Pacific\Samoa.txt -> C:\Users\Mark\*snip*\data\Pacific\Pago_Pago.txt
Created junction C:\Users\Mark\*snip*\data\Pacific\Ponape.txt -> C:\Users\Mark\*snip*\data\Pacific\Pohnpei.txt

So it looks like it's working. I can see the junctions/shortcuts in Explorer:

But they're all broken. i.e., double clicking them gives me an error message

Cuba.txt is not accessible.
The filename, directory name, or volume label syntax is incorrect.

How come? How can I create symlinks in Node.js on Windows such that the files work like normal (i.e. other programs can read them).


回答1:


As I remember NTFS junction points act like directories, not individual files.

See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365006(v=vs.85).aspx



来源:https://stackoverflow.com/questions/43036970/node-js-symlink-junctions-are-broken-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!