Sha256: 61ea4823cfb1abd1c3f3bbc51ed284d4d7a73f9d074efccee06cd4d64eaebfb6

Contents?: true

Size: 1.53 KB

Versions: 23

Compression:

Stored size: 1.53 KB

Contents

'use strict'

const u = require('universalify').fromCallback
const path = require('path')
const fs = require('graceful-fs')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists

function createLink (srcpath, dstpath, callback) {
  function makeLink (srcpath, dstpath) {
    fs.link(srcpath, dstpath, err => {
      if (err) return callback(err)
      callback(null)
    })
  }

  pathExists(dstpath, (err, destinationExists) => {
    if (err) return callback(err)
    if (destinationExists) return callback(null)
    fs.lstat(srcpath, (err) => {
      if (err) {
        err.message = err.message.replace('lstat', 'ensureLink')
        return callback(err)
      }

      const dir = path.dirname(dstpath)
      pathExists(dir, (err, dirExists) => {
        if (err) return callback(err)
        if (dirExists) return makeLink(srcpath, dstpath)
        mkdir.mkdirs(dir, err => {
          if (err) return callback(err)
          makeLink(srcpath, dstpath)
        })
      })
    })
  })
}

function createLinkSync (srcpath, dstpath) {
  const destinationExists = fs.existsSync(dstpath)
  if (destinationExists) return undefined

  try {
    fs.lstatSync(srcpath)
  } catch (err) {
    err.message = err.message.replace('lstat', 'ensureLink')
    throw err
  }

  const dir = path.dirname(dstpath)
  const dirExists = fs.existsSync(dir)
  if (dirExists) return fs.linkSync(srcpath, dstpath)
  mkdir.mkdirsSync(dir)

  return fs.linkSync(srcpath, dstpath)
}

module.exports = {
  createLink: u(createLink),
  createLinkSync
}

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
appmap-0.72.2 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.72.1 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.72.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.71.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.70.2 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.70.1 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.70.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.69.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.68.2 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.68.1 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.68.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.67.1 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.67.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.66.2 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.66.1 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.66.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.65.1 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.65.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.64.0 ./node_modules/fs-extra/lib/ensure/link.js
appmap-0.63.0 ./node_modules/fs-extra/lib/ensure/link.js