简体   繁体   English

在node.js中,无法摆脱不良的符号链接

[英]in node.js, cannot get rid of a bad symlink

I have an uglify function that creates a file lib-0.1.4-min.js and then symlinks that to lib-production-min.js . 我有一个uglify函数,该函数创建文件lib-0.1.4-min.js ,然后将其符号链接到lib-production-min.js 0.1.4 is the current version. 当前版本为0.1.4

due to synchronization of this directory, sometimes the lib-production-min.js is a broken link. 由于此目录的同步,有时lib-production-min.js是断开的链接。

when I run the compile function, fs.existsSync( "lib-production-min.js" ) returns false. 当我运行编译功能时, fs.existsSync( "lib-production-min.js" )返回false。 when I try to create the symlink later, node errs out with file already exists . 当我稍后尝试创建符号链接时, node错误并file already exists

var version = 'lib-0.1.4-min.j';
var prod = 'lib-production-min.js';

// if production exists, get rid of it
if( fs.existsSync(prod) ) fs.unlinkSync( prod );  // not exists - not deleted

// link version to production
fs.symlinkSync( version, prod );                  // ERROR: file already exists
  1. how do I check if this deadlink is in the directory? 如何检查此死链接是否在目录中?

  2. will normal fs.unlinkSync( "lib-production-min.js" ) delete it? 正常的fs.unlinkSync( "lib-production-min.js" )会将其删除吗?

fs.lstat() or fs.lstatSync() might help you. fs.lstat()fs.lstatSync()可能会对您有所帮助。 They are supposed to bring the information about the link itself, not following it. 他们应该带来有关链接本身的信息,而不是关注它。

Use fs.readlinkSync(symlinkPath) to get the file pointed by the symlink, and then use fs.existsSync with that path. 使用fs.readlinkSync(symlinkPath)获取符号链接指向的文件,然后将fs.existsSync与该路径一起使用。

The problem is that the link file exists, is the destination of the link the one that is missing. 问题是链接文件存在,是链接的目的地是丢失的那个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM