Example #1
0
var _getPathFromSymlink = function (stdout, cb) {
  // Node's invocation of xcode-select sometimes flakes and returns an empty string.
  // Not clear why. As a workaround, Appium can reliably deduce the version in use by checking
  // the locations xcode-select uses to store the selected version's path. This should be 100%
  // reliable so long as the link locations remain the same. However, since we're relying on
  // hardcoded paths, this approach will break the next time Apple changes the symlink location.
  var symlnkPath = "/var/db/xcode_select_link";
  var legacySymlnkPath = "/usr/share/xcode-select/xcode_dir_path"; //  Xcode < 5.x (?)

  // xcode-select allows users to override its settings with the DEVELOPER_DIR env var,
  // so check that first
  if (util.hasContent(env.DEVELOPER_DIR)) {
    var dir = _hasExpectedSubDir(env.DEVELOPER_DIR) ?
                env.DEVELOPER_DIR :
                env.DEVELOPER_DIR + XCODE_SUBDIR;
    cb(null, dir);
  } else if (fs.existsSync(symlnkPath)) {
    fs.readlink(symlnkPath, cb);
  } else if (fs.existsSync(legacySymlnkPath)) {
    fs.readlink(legacySymlnkPath, cb);
  } else {
    // We should only get here is we failed to capture xcode-select's stdout and our
    // other checks failed. Either Apple has moved the symlink to a new location or the user
    // is using the default install. 99.999% chance it's the latter, so issue a warning
    // should we ever hit the edge case.
    logger.warn("xcode-select returned an invalid path: " + stdout +
                ". No links to alternate versions were detected. Using Xcode's " +
                "default location.");
    var path = "/Applications/Xcode.app" + XCODE_SUBDIR;
    var err = fs.existsSync(path) ? null : new Error("No Xcode installation found.");
    cb(err, path);
  }
};
Example #2
0
function createSDKSymlink (dir, next) {
	var from = common.paths.sdk(), to = path.join(dir, './sdk');

	// If a symlink exists, check that it points to the right location.
	try {
		if (!fs.lstatSync(to).isSymbolicLink()) {
			logger.error('File', to, 'is not a symlink. Please remove this file and retry.');
			process.exit(2);
		}

		fs.readlink(to, function (err, link) {
			if (path.resolve(dir, link) == fs.realpathSync(from)) {
				next();
			} else {
				logger.log('Relinking ./sdk'); 
				fs.unlinkSync(to);
				fs.symlink(from, to,'junction', next);
			}
		});
	} catch (e) {
		if (e.code == "ENOENT") {
			logger.log('Creating symlink ./sdk'); 
			fs.symlink(from, to, 'junction', next);
		} else {
			logger.warn('Unexpected exception trying to create a symlink at', to);
			console.error(e);
		}
	}
}
Example #3
0
Server.prototype._runCurrent = function _runCurrent(cb) {
  debug('run current deployment');

  // On pm start, bring up the last app to be run as 'current'.
  var currentSymlink = this.git.workdir({id: 'current'});
  var self = this;
  fs.readlink(currentSymlink, function(err, id) {
    if (err) {
      debug('no current deployment found');
      return cb();
    }

    // If we find it, it was already prepared (and run) in the past, so emit
    // it as 'prepared', after figuring out the commit metadata.
    var dir = self.git.workdir({id: id});
    var hash = id.split('.')[0];
    // XXX(sam) repo and branch not known at this point, so config won't be
    // correct!  but config will be gone soon, so we don't care for now.
    var commit = cicadaCommit({hash: hash, id: id, dir: dir});
    commit.config = configForCommit(commit);
    commit.env = self.env();
    self.emit('prepared', commit);
    process.nextTick(cb);
  });
};
Example #4
0
  .on('symlink', function(symlink, stat) {
    var walker = this;
    fs.readlink(symlink, function(error, link) {
    if (error) {
      return;
    }

    var destination = path.resolve(path.dirname(symlink), link);

    // Stores symlinks to avoid circular references
    if (~symlinks.indexOf(destination)) {
      return;
    }
    else {
      symlinks.concat(destination);
    }

    fs.stat(destination, function(error, stat) {
      if (error) {
        return;
      }
      else if (stat.isDirectory()) {
        walker.emit('dir', destination, stat);
        return walker.go(destination);
      }
    });
    });
  })
      async.map(files, function (file, callback) {
        var fileName = path.join(dirName, file);
        fs.readlink(fileName, function (err, link) {
          if (err) {
            if (callback) {
              callback(err);
            } else {
              factory.emit('error', err);
            }
            return;
          }

          link = path.resolve(dirName, link);
          exec('/sbin/udevadm info --query=property -p $(/sbin/udevadm info -q path -n ' + link + ')', function (err, stdout) {
            if (err) {
              if (callback) {
                callback(err);
              } else {
                factory.emit('error', err);
              }
              return;
            }

            udev_parser(stdout, callback);
          });
        });
      }, callback);
Example #6
0
	return new Promise((resolve, reject) => {
		if (typeof commandPath !== 'string' || typeof commandName !== 'string') {
			reject(new TypeError('Expected a string'));
		}

		if (process.platform !== 'darwin') {
			reject(new Error('Your platform is not supported'));
		}

		const destinationPath = path.join('/usr/local/bin', commandName);

			// not catch Error
		fs.readlink(destinationPath, (_, realPath) => {
			if (realPath === commandPath) {
				resolve();
				return;
			}

			fs.unlink(destinationPath, err => {
				if (err && err.code && err.code !== 'ENOENT') {
					reject(err);
				}

				fs.symlink(commandPath, destinationPath, err => {
					if (err) {
						reject(err);
					}
					resolve();
				});
			});
		});
	});
Example #7
0
exports.read_link = function(req, res) {
	var url = req.body.url;
	var size = req.body.size;
	var val = {};

    if (!url || !size) {
        val.status = "error";
        val.message = "Define from and to first";
        utils.info(req, res, val);
        return;
    }
    var real_url = get_real_url(req, url);
	if (!real_url) {
        val.status = "fail";
        val.errno = -1;
		utils.info(req, res, val);
		return ;
	}
	fs.readlink(real_url, function(err, linkString) {
		if (err) {
        	val.status = "error";
			val.errno = err.errno;
        	utils.info(req, res, val);
	    } else {
				//FIXME: not done 
            res.writeHead(200, {'Content-Type': mime.lookup(url)});
            res.end(linkString);
	    }
	});
};
Example #8
0
    fs.lstat(req._filename, function (err, stats) {
        if (err) {
            log.warn(err, 'readlink: lstat failed');
            res.error(nfs.NFS3ERR_IO);
            next(false);
            return;
        }

	if (!stats.isSymbolicLink()) {
            log.warn(err, 'readlink: not a symlink');
            res.error(nfs.NFS3ERR_INVAL);
            next(false);
            return;
	}

        fs.readlink(req._filename, function (l_err, val) {
            if (l_err) {
                log.warn(l_err, 'readlink: failed');
                res.error(nfs.NFS3ERR_IO);
                next(false);
                return;
            }

            log.debug('readlink(%j %s): done', stats, val);
            res.setAttributes(stats);
            res.data = val;
            res.send();
            next();
        });
    });
Example #9
0
 else fs.lstat(dir, function onstat (err, stat) {
     if (emitter._stopped) return;
     if (err) return finish();
     emitter._seen[stat.ino || dir] = true;
     
     if (stat.isSymbolicLink() && opts.followSymlinks) {
         emitter.emit('link', fdir, stat);
         fs.readlink(dir, function (err, rfile) {
             if (emitter._stopped) return;
             if (err) return finish();
             var file_ = path.resolve(dir, rfile);
             emitter.emit('readlink', fdir, file_);
             fs.lstat(file_, onstat);
         });
     }
     else if (stat.isSymbolicLink()) {
         emitter.emit('link', fdir, stat);
         emitter.emit('path', fdir, stat);
         finish();
     }
     else if (stat.isDirectory()) {
         var stopped = false;
         emitter.emit('directory', fdir, stat, function stop () {
             stopped = true;
         });
         emitter.emit('path', fdir, stat);
         if (!stopped) fs.readdir(dir, onreaddir);
         else check()
     }
     else {
         emitter.emit('file', fdir, stat);
         emitter.emit('path', fdir, stat);
         finish();
     }
 });
Example #10
0
 fs.lstat(file, function (err, stat) {
   if (err) {
     checkNext(err, index);
   } else if (stat.isSymbolicLink()) {
     if (server.followSymlink) {
       fs.readlink(file, function (err, fileRef) {
         if (err) {
           checkNext(err, index);
         } else {
           server.emit('symbolicLInk', fileRef, link);
           next(fileRef, index);
         }
       });
     } else {
       callback(new Error('Symbolic link not allowed'));
     }
   } else if (stat.isDirectory()) {
     if (!dirFound) {
       dirFound = file;
       dirStat = stat;
       dirIndex = index;
     }
     checkNext(null, index);
   } else {
     callback(null, stat, file, index);
   }
 });
Example #11
0
Container.prototype.runCurrent = function(callback) {
  var self = this;
  var currentSymlink = self.git.workdir({id: 'current'});
  self.debug('run current deployment %j', currentSymlink);
  fs.readlink(currentSymlink, function(err, id) {
    if (err) {
      self.debug('no current deployment found');
      return callback();
    }

    // If we find it, it was already prepared (and run) in the past, so emit
    // it as 'prepared', after figuring out the commit metadata.
    var dir = self.git.workdir({id: id});
    var hash = id.split('.')[0];
    var commit = cicadaCommit({
      dir: dir,
      hash: hash,
      id: id,
      repo: self.instanceId,
      branch: 'default', // XXX(sam) should stop logging branch, its meaningless
    });
    self.server.getInstanceEnv(self.instanceId, function(err, env) {
      if (err) return callback(err);
      commit.env = env;
      commit.container = self;

      self.emit('prepared', commit);
      callback();
    });

  });
};
Example #12
0
proto.exe = function(cb) {
    var self = this;
    var basePath = '/proc/' + self.pid;
    var path = basePath + '/exe';

    if (cb && typeof cb == 'function') {
        fs.readlink(path, function(err, data) {
            if (err) {
                fs.readdir(basePath, function(err, data) {
                    if (err) {
                        cb(err);
                        return;
                    }
                    cb(null, '');
                });
                return;
            }
            var _exe = __proto_exe_handle(data);
            cb(null, _exe);
        });
        return;
    }

    var _exe;
    if (fs.existsSync(path)) {
        _exe = fs.readlinkSync(path);
    } else {
        if (fs.existsSync(basePath)) {
            return '';
        }
        throw "[err] no such process " + self.pid;
    }
    return __proto_exe_handle(_exe);
};
Example #13
0
 [SYMLINK] () {
   fs.readlink(this.absolute, (er, linkpath) => {
     if (er)
       return this.emit('error', er)
     this[ONREADLINK](linkpath)
   })
 }
Example #14
0
 fs.lstat(to, function (er, stat) {
   if (!er) return fs.readlink(to, function (active) {
     cb(new Error("Implicit deactivate failed.\n"+
       pkg+"@"+path.dirname(active)+" still active."))
   })
   else cb()
 })
Example #15
0
 FileSystem.lstat(runtimeJsonFilename, function(err, stats) {
   if(stats.isSymbolicLink()) {
     FileSystem.readlink(runtimeJsonFilename, function(err, realPath) {
         runtimeJsonFilename = realPath;
     });
   }
 });
Example #16
0
 fs.lstat(dir, function (e, stat) {
   if (!e) {
     if (stat.isSymbolicLink()) {
       var source = dir
       fs.readlink(source, function (e, link) {
         if (!e) {
           var dest = link
           if (dest[0] !== '/') {
             while (dest.substr(0, 3) === '../') {
               dest = dest.substr(3)
               source = source.replace(/\/[^\/]+$/, '')
             }
             if (dest.substr(0, 2) === './') {
               dest = dest.substr(2)
             }
             dest = source + '/' + dest
           }
           watch(dest)
         }
       })
     } else if (stat.isDirectory()) {
       addDir(dir, stat)
     } else {
       dir = dirname(dir)
       map[dir] = Math.max(map[dir], stat.mtime.getTime())
     }
   }
 })
Example #17
0
 fs.stat(file, function(err, stat) { //拷贝快捷方式与文件
     if (stat.isSymbolicLink()) fs.readlink(file, function(err, link) {
         fs.symlink(link, newFile, after);
     });
     else fs.readFile(file, function(err, data) {
         fs.writeFile(newFile, data, after);
     });
 });
Example #18
0
function realish(p, cb) {
  fs.readlink(p, function (er, r) {
    if (er) {
      return cb(er);
    }
    return cb(null, path.resolve(path.dirname(p), r));
  });
}
Example #19
0
    fs.stat(base, function(err) {
      if (err) return cb(err);

      fs.readlink(base, function(err, target) {
        if (!isWindows) seenLinks[id] = target;
        gotTarget(err, target);
      });
    });
Example #20
0
LocalSource.prototype.installedInto = function(path, fn) {
  var self = this;
  
  fs.readlink(path, function(err, linkPath) {
    // will obviously not work if there's an err (ie path isn't a symlink)
    fn(linkPath === self.path);
  });
};
Example #21
0
 fs.lstat(p, function(err, s){
   if(err) return reject(err);
   if(!s.isSymbolicLink()) return resolve();
   fs.readlink(p, function(err, linkTo){
     if(err) return reject(err);
     resolve(linkTo);
   });
 });
Example #22
0
 return new Promise((resolve, reject) => {
   fs.readlink(path, (err, result) => {
     if (err == null) {
       resolve(result);
     } else {
       reject(err);
     }
   });
 });
Example #23
0
 function onLink(link) {
   var target = link.replace(currentPath, targetPath);
   fs.readlink(link, function(err, resolvedPath) {
     if (err) {
       return onError(err);
     }
     checkLink(resolvedPath, target);
   });
 }
Example #24
0
 isSymbolicLink(from, function (err, isLink) {
   if (err) return done(err)
   if (!isLink) return done(null, false)
   fs.readlink(from, function (err, currentLink) {
     if (err) return done(err)
     currentLink = path.resolve(path.dirname(from), currentLink)
     return done(null, currentLink === to)
   })
 })
Example #25
0
    carrier.carry(findConfig.stdout, function (line) {
      fs.readlink(line, function (err, target) {
        // probably not a link, try to proceed with the original file
        if (err) return deferred.resolve(path.dirname(path.dirname(line)));

        var installPath = path.dirname(path.dirname(path.resolve(path.dirname(line),
                                                                 target)));
        return deferred.resolve(installPath);
      });
    });
Example #26
0
fs.symlink(linkData, linkPath, function(err){
  if (err) throw err;
  puts('symlink done');
  // todo: fs.lstat?
  fs.readlink(linkPath, function(err, destination) {
    if (err) throw err;
    assert.equal(destination, linkData);
    completed++;
  })
});
Example #27
0
 api.get("/update", function(req, res, next) {
     res.writeHead(200, {
         "Content-Type": "application/javascript", 
         "Access-Control-Allow-Origin": "*"
     });
     var path = resolve(__dirname + "/../../build/output/latest.tar.gz");
     fs.readlink(path, function(err, target) {
         res.end((target || "").split(".")[0]);
     });
 });
 fs.exists(linkName, function (exists) {
     if (exists) {
         fs.readlink(linkName, function (err, dst) {
             if (dst != filename) {
                 fs.unlink(linkName, link);
             }
         });
     } else {
         link();
     }
 });
Example #29
0
 files.forEach(function(v) {
     var link = path + '/' + v;
     fs.readlink(link, function(err2, data) {
         if (!err2 && data.indexOf('/') >= 0 && fs.statSync(data).isFile) {
             arr.push(data);
         }
         if (0 == --count) {
             cb(null, arr);
         }
     });
 });
Example #30
0
 path.exists(file, function(exists) {
   if (exists) {
     fs.readlink(file, function(err, resolvedPath) {
       if (err) {
         em.emit('error', err);
       } else {
         finder(path.resolve(path.dir(file), resolvedPath));
       }
     });
   }
 });