Пример #1
0
  fs.readFile(self.floo_path, {encoding: "utf8"}, function (err, file) {
    var floo,
      md5;

    if (err) {
      return log.warn(util.format("Can not load .floo file (%s) because %s.  No hooks will be run.", self.floo_path, err));
    }

    md5 = utils.md5(file);
    if (md5 === self.md5) {
      log.log("Ignoring our own change to the .floo file");
      return cb();
    }
    self.md5 = md5;

    log.log("Reloading hooks.");

    try {
      floo = JSON.parse(file);
    } catch (e) {
      floo = {};
    }

    self.load_hooks(floo);
    cb();
  });
Пример #2
0
  request.post(options, function (err, result, body) {
    var data = {};

    if (err) {
      log.log("Error creating workspace:", err);
      return cb(err);
    }
    if (body) {
      body = body.detail || body;
    }

    if (result.statusCode === 401) {
      return cb(new Error(err_start + 'Your credentials are wrong. see https://floobits.com/help/floorc/' + '\nHTTP status ' + result.statusCode + ': ' + body));
    }
    if (result.statusCode === 402) {
      return cb(new Error(err_start + body.toString()));
    }
    if (result.statusCode === 403) {
      return cb(new Error(err_start + 'You do not have permission. see https://floobits.com/help/floorc/'));
    }
    if (result.statusCode === 409) {
      log.warn('This workspace already exists.');
    } else if (result.statusCode >= 400) {
      return cb(new Error(err_start + ' HTTP status ' + result.statusCode + ': ' + body));
    }
    log.log('Created workspace', url);

    data = utils.load_floo();
    data.url = url;
    /*jslint stupid: true */
    fs.writeFileSync(".floo", JSON.stringify(data), 'utf-8');
    /*jslint stupid: false */
    cb();
  }).auth(username, secret);
Пример #3
0
 function shut_down(signal) {
   log.warn("Got %s. Shutting down...", signal);
   server.stop(function () {
     log.log("All done.");
     process.exit(0);
   });
 }
Пример #4
0
 self.on_hooks_change(function () {
   try {
     self.watcher = fs.watchFile(self.floo_path, self.on_hooks_change.bind(self));
     log.log("Watching " + self.floo_path + " for changes");
   } catch (e) {
     log.warn(util.format("Can not watch %s for hooks because %s", self.floo_path, e));
   }
 });
Пример #5
0
FlooConnection.prototype.send_patch = function (buf, after) {
  var self = this,
    patches,
    patch_text,
    md5_after;

  if (self.readonly) {
    return;
  }

  switch (buf.encoding) {
  case 'utf8':
    patches = JS_DMP.patch_make(buf.buf.toString(), after.toString());
    patch_text = JS_DMP.patch_toText(patches);
    break;
  case "base64":
    if (!DMP) {
      return log.warn(util.format("Can't make patch for %s: No native-diff-match-patch module.", buf.path));
    }
    patch_text = DMP.patch_make(buf.buf, after);
    break;
  default:
    return log.warn(util.format("Can't make patch for %s: Unknown encoding %s.", buf.path, buf.encoding));
  }

  md5_after = utils.md5(after);

  self.write('patch', {
    'id': buf.id,
    'md5_after': md5_after,
    'md5_before': buf.md5,
    'path': buf.path,
    'patch': patch_text
  });

  buf.buf = after;
  buf.md5 = md5_after;
};
Пример #6
0
Hook.prototype.load = function () {
  var self = this,
    hook;

  log.log("Loading", self.hook_path);
  try {
    hook = require(self.hook_path);
    if (!_.isFunction(hook)) {
      throw new Error("Not a function: " + hook);
    }
  } catch (e) {
    return log.warn("No hooks found in", self.hook_path, ":", e.toString());
  }
  self.hook = hook;
  log.log("Loaded", self.hook_path);
};
Пример #7
0
  request.post(options, function (err, result, body) {
    var data = {};

    if (err) {
      log.log("Error creating workspace:", err);
      return cb(err);
    }
    if (body) {
      body = body.detail || body;
    }
    console.log(body, result.statusCode);
    if (result.statusCode === 401) {
      err = new Error(err_start + "Your credentials are wrong. see https://floobits.com/help/floorc" + "\nHTTP status " + result.statusCode + ": " + body);
    }
    if (result.statusCode === 402) {
      err = new Error(err_start + body.toString());
    }
    if (result.statusCode === 403) {
      err = new Error(err_start + "You do not have permission. see https://floobits.com/help/floorc");
    }

    if (result.statusCode === 409) {
      log.warn("This workspace already exists.");
    } else if (result.statusCode >= 400) {
      err = err || new Error(err_start + " HTTP status " + result.statusCode + ": " + body);
      err.statusCode = result.statusCode;
      return cb(err);
    }
    log.log("Created workspace", url);

    data = utils.load_floo();
    data.url = url;
    /*jslint stupid: true */
    fs.writeFileSync(".floo", JSON.stringify(data), "utf-8");
    /*jslint stupid: false */
    cb();
  }).auth(username, secret);
Пример #8
0
 self.conn.on('end', function () {
   log.warn('socket is gone');
   self.reconnect();
 });
Пример #9
0
const util = require("util");

const _ = require("lodash");
const fs = require("fs-ext");
const log = require("floorine");

const hooks = require("./hooks");


var fsevents;

if (process.platform === "darwin") {
  try {
    fsevents = require("fsevents");
  } catch (e) {
    log.warn("native fsevents can not be required. This is not good");
  }
}

const IGNORED_FILENAMES = [
  "node_modules"
];

const Listener = function (_path) {
  var self = this;

  self.path = _path;
  self.watchers = {};
  self.running_hooks = {};

  log.log("Watching for changes in", _path);