Вход Регистрация
Файл: error-kitty/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/polyfills.js
Строк: 274
<?php
var fs = require('fs')
var 
constants = require('constants')

var 
origCwd process.cwd
var cwd null
process
.cwd = function() {
  if (!
cwd)
    
cwd origCwd.call(process)
  return 
cwd
}
var 
chdir process.chdir
process
.chdir = function(d) {
  
cwd null
  chdir
.call(processd)
}

// (re-)implement some things that are known busted or missing.

// lchmod, broken prior to 0.6.2
// back-port the fix here.
if (constants.hasOwnProperty('O_SYMLINK') &&
    
process.version.match(/^v0.6.[0-2]|^v0.5./)) {
  
fs.lchmod = function (pathmodecallback) {
    
callback callback || noop
    fs
.openpath
           
constants.O_WRONLY constants.O_SYMLINK
           
mode
           
, function (errfd) {
      if (
err) {
        
callback(err)
        return
      }
      
// prefer to return the chmod error, if one occurs,
      // but still try to close, and report closing errors if they occur.
      
fs.fchmod(fdmode, function (err) {
        
fs.close(fd, function(err2) {
          
callback(err || err2)
        })
      })
    })
  }

  
fs.lchmodSync = function (pathmode) {
    var 
fd fs.openSync(pathconstants.O_WRONLY constants.O_SYMLINKmode)

    
// prefer to return the chmod error, if one occurs,
    // but still try to close, and report closing errors if they occur.
    
var errerr2
    
try {
      var 
ret fs.fchmodSync(fdmode)
    } catch (
er) {
      
err er
    
}
    try {
      
fs.closeSync(fd)
    } catch (
er) {
      
err2 er
    
}
    if (
err || err2) throw (err || err2)
    return 
ret
  
}
}


// lutimes implementation, or no-op
if (!fs.lutimes) {
  if (
constants.hasOwnProperty("O_SYMLINK")) {
    
fs.lutimes = function (pathatmtcb) {
      
fs.open(pathconstants.O_SYMLINK, function (erfd) {
        
cb cb || noop
        
if (er) return cb(er)
        
fs.futimes(fdatmt, function (er) {
          
fs.close(fd, function (er2) {
            return 
cb(er || er2)
          })
        })
      })
    }

    
fs.lutimesSync = function (pathatmt) {
      var 
fd fs.openSync(pathconstants.O_SYMLINK)
        , 
err
        
err2
        
ret

      
try {
        var 
ret fs.futimesSync(fdatmt)
      } catch (
er) {
        
err er
      
}
      try {
        
fs.closeSync(fd)
      } catch (
er) {
        
err2 er
      
}
      if (
err || err2) throw (err || err2)
      return 
ret
    
}

  } else if (
fs.utimensat && constants.hasOwnProperty("AT_SYMLINK_NOFOLLOW")) {
    
// maybe utimensat will be bound soonish?
    
fs.lutimes = function (pathatmtcb) {
      
fs.utimensat(pathatmtconstants.AT_SYMLINK_NOFOLLOWcb)
    }

    
fs.lutimesSync = function (pathatmt) {
      return 
fs.utimensatSync(pathatmtconstants.AT_SYMLINK_NOFOLLOW)
    }

  } else {
    
fs.lutimes = function (_a_b_ccb) { process.nextTick(cb) }
    
fs.lutimesSync = function () {}
  }
}


// https://github.com/isaacs/node-graceful-fs/issues/4
// Chown should not fail on einval or eperm if non-root.

fs.chown chownFix(fs.chown)
fs.fchown chownFix(fs.fchown)
fs.lchown chownFix(fs.lchown)

fs.chownSync chownFixSync(fs.chownSync)
fs.fchownSync chownFixSync(fs.fchownSync)
fs.lchownSync chownFixSync(fs.lchownSync)

function 
chownFix (orig) {
  if (!
orig) return orig
  
return function (targetuidgidcb) {
    return 
orig.call(fstargetuidgid, function (erres) {
      if (
chownErOk(er)) er null
      cb
(erres)
    })
  }
}

function 
chownFixSync (orig) {
  if (!
orig) return orig
  
return function (targetuidgid) {
    try {
      return 
orig.call(fstargetuidgid)
    } catch (
er) {
      if (!
chownErOk(er)) throw er
    
}
  }
}

function 
chownErOk (er) {
  
// if there's no getuid, or if getuid() is something other than 0,
  // and the error is EINVAL or EPERM, then just ignore it.
  // This specific case is a silent failure in cp, install, tar,
  // and most other unix tools that manage permissions.
  // When running as root, or if other types of errors are encountered,
  // then it's strict.
  
if (!er || (!process.getuid || process.getuid() !== 0)
      && (
er.code === "EINVAL" || er.code === "EPERM")) return true
}


// if lchmod/lchown do not exist, then make them no-ops
if (!fs.lchmod) {
  
fs.lchmod = function (pathmodecb) {
    
process.nextTick(cb)
  }
  
fs.lchmodSync = function () {}
}
if (!
fs.lchown) {
  
fs.lchown = function (pathuidgidcb) {
    
process.nextTick(cb)
  }
  
fs.lchownSync = function () {}
}



// on Windows, A/V software can lock the directory, causing this
// to fail with an EACCES or EPERM if the directory contains newly
// created files.  Try again on failure, for up to 1 second.
if (process.platform === "win32") {
  var 
rename_ fs.rename
  fs
.rename = function rename (fromtocb) {
    var 
start Date.now()
    
rename_(fromto, function CB (er) {
      if (
er
          
&& (er.code === "EACCES" || er.code === "EPERM")
          && 
Date.now() - start 1000) {
        return 
rename_(fromtoCB)
      }
      
cb(er)
    })
  }
}


// if read() returns EAGAIN, then just try it again.
var read fs.read
fs
.read = function (fdbufferoffsetlengthpositioncallback_) {
  var 
callback
  
if (callback_ && typeof callback_ === 'function') {
    var 
eagCounter 0
    callback 
= function (er___) {
      if (
er && er.code === 'EAGAIN' && eagCounter 10) {
        
eagCounter ++
        return 
read.call(fsfdbufferoffsetlengthpositioncallback)
      }
      
callback_.apply(thisarguments)
    }
  }
  return 
read.call(fsfdbufferoffsetlengthpositioncallback)
}

var 
readSync fs.readSync
fs
.readSync = function (fdbufferoffsetlengthposition) {
  var 
eagCounter 0
  
while (true) {
    try {
      return 
readSync.call(fsfdbufferoffsetlengthposition)
    } catch (
er) {
      if (
er.code === 'EAGAIN' && eagCounter 10) {
        
eagCounter ++
        continue
      }
      throw 
er
    
}
  }
}
?>
Онлайн: 1
Реклама