lib/util.js
function forcelink(src, dest, options, callback) {
    if (!options || !options.cache) throw new Error('options.cache not defined!');
    if (!callback) throw new Error('callback not defined!');
    // uses relative path if linking to cache dir
    if (path.relative) {
        src = path.relative(options.cache, dest).slice(0, 2) !== '..' ? path.relative(path.dirname(dest), src) : src;
    }
    fs.lstat(dest, function(err, stat) {
        // Error.
        if (err && err.code !== 'ENOENT') {
            return callback(err);
        }

        // Path does not exist. Symlink.
        if (err && err.code === 'ENOENT') {
            if (env == 'development') console.error("[millstone] linking '" + dest + "' -> '"  + src + "'");
            return fs.symlink(src, dest, callback);
        }

        // Path exists and is not a symlink. Do nothing.
        if (!stat.isSymbolicLink()) {
            if (env == 'development') console.error("[millstone] skipping re-linking '" + src + "' because '"  + dest + " is already an existing file");
            return callback();
        }

        // Path exists and is a symlink. Check existing link path and update if necessary.
        // NOTE : broken symlinks will pass through this step
        fs.readlink(dest, function(err, old) {
            if (err) return callback(err);
            if (old === src) return callback();
            fs.unlink(dest, function(err) {
                if (err) return callback(err);
                if (env == 'development') console.error("[millstone] re-linking '" + dest + "' -> '"  + src + "'");
                fs.symlink(src, dest, callback);
            });
        });
    });
}
function forcelink(src, dest, options, callback) {
    if (!options || !options.cache) throw new Error('options.cache not defined!');
    if (!callback) throw new Error('callback not defined!');
    // uses relative path if linking to cache dir
    if (path.relative) {
        src = path.relative(options.cache, dest).slice(0, 2) !== '..' ? path.relative(path.dirname(dest), src) : src;
    }
    fs.lstat(dest, function(err, stat) {
        // Error.
        if (err && err.code !== 'ENOENT') {
            return callback(err);
        }

        // Path does not exist. Symlink.
        if (err && err.code === 'ENOENT') {
            if (env == 'development') console.error("[millstone] linking '" + dest + "' -> '"  + src + "'");
            return fs.symlink(src, dest, callback);
        }

        // Path exists and is not a symlink. Do nothing.
        if (!stat.isSymbolicLink()) {
            if (env == 'development') console.error("[millstone] skipping re-linking '" + src + "' because '"  + dest + " is already an existing file");
            return callback();
        }

        // Path exists and is a symlink. Check existing link path and update if necessary.
        // NOTE : broken symlinks will pass through this step
        fs.readlink(dest, function(err, old) {
            if (err) return callback(err);
            if (old === src) return callback();
            fs.unlink(dest, function(err) {
                if (err) return callback(err);
                if (env == 'development') console.error("[millstone] re-linking '" + dest + "' -> '"  + src + "'");
                fs.symlink(src, dest, callback);
            });
        });
    });
}
function forcelink ( src , dest , options , callback ) { if ( ! options || ! options . cache ) throw new Error ( 'options.cache not defined!' ) ; if ( ! callback ) throw new Error ( 'callback not defined!' ) ; // uses relative path if linking to cache dir if ( path . relative ) { src = path . relative ( options . cache , dest ) . slice ( 0 , 2 ) !== '..' ? path . relative ( path . dirname ( dest ) , src ) : src ; } fs . lstat ( dest , function ( err , stat ) { // Error. if ( err && err . code !== 'ENOENT' ) { return callback ( err ) ; } // Path does not exist. Symlink. if ( err && err . code === 'ENOENT' ) { if ( env == 'development' ) console . error ( "[millstone] linking '" + dest + "' -> '" + src + "'" ) ; return fs . symlink ( src , dest , callback ) ; } // Path exists and is not a symlink. Do nothing. if ( ! stat . isSymbolicLink ( ) ) { if ( env == 'development' ) console . error ( "[millstone] skipping re-linking '" + src + "' because '" + dest + " is already an existing file" ) ; return callback ( ) ; } // Path exists and is a symlink. Check existing link path and update if necessary. // NOTE : broken symlinks will pass through this step fs . readlink ( dest , function ( err , old ) { if ( err ) return callback ( err ) ; if ( old === src ) return callback ( ) ; fs . unlink ( dest , function ( err ) { if ( err ) return callback ( err ) ; if ( env == 'development' ) console . error ( "[millstone] re-linking '" + dest + "' -> '" + src + "'" ) ; fs . symlink ( src , dest , callback ) ; } ) ; } ) ; } ) ; }
Like fs.symlink except that it will overwrite stale symlinks at the given path if it exists.
Like fs . symlink except that it will overwrite stale symlinks at the given path if it exists .