<commit_before>'use strict';

var Promise = require('../../promise.js');
var kbox = require('../../kbox.js');

/*
 * Constants.
 */
var IMAGE_NAME = 'kalabox/syncthing:stable';
var CONTAINER_NAME = 'kalabox_syncthing';

// Query engine to see if syncthing container exists.
var isInstalled = exports.isInstalled = function() {
  return kbox.engine.exists(CONTAINER_NAME);
};

// Query engine to see if syncthing container is running.
exports.isRunning = function() {
  // Inspect.
  return kbox.engine.inspect(CONTAINER_NAME)
  // Return container's running status.
  .then(function(data) {
    return data.State.Running;
  });
};

// Create syncthing container.
exports.create = function(binds) {

  kbox.core.log.debug('SYNC CONTAINER => Binds', binds);

  var opts = {
    Image: IMAGE_NAME,
    name: CONTAINER_NAME,
    HostConfig: {
      Binds: binds,
      NetworkMode: 'bridge',
      PortBindings: {
        '60008/tcp': [{'HostIp': '', 'HostPort': '60008'}],
        '22000/tcp': [{'HostIp': '', 'HostPort': '22000'}],
        '21025/udp': [{'HostIp': '', 'HostPort': '21025'}],
        '21026/udp': [{'HostIp': '', 'HostPort': '21026'}]
      }
    }
  };

  // Create container.
  return kbox.engine.create(opts);

};

/*
 * Remove syncthing container.
 */
var remove = exports.remove = function(counter) {

  // Set default counter.
  if (counter === undefined) {
    counter = 5;
  }

  // Remove container.
  return kbox.engine.remove(CONTAINER_NAME)
  // Check if the container is still installed.
  .then(isInstalled)
  // Keep trying until container is uninstalled or we run out of attempts.
  .then(function(isInstalled) {
    if (isInstalled) {
      if (counter > 0) {
        // Wait 3 seconds, then call this function again.
        return Promise.delay(3 * 1000)
        .then(function() {
          return remove(counter - 1);
        });
      } else {
        // We have run out of attempts, so throw an error.
        throw new Error('Count not remove container ' + CONTAINER_NAME);
      }
    }
  });

};

// Start syncthing container.
exports.start = function(opts) {
  // Start container.
  return kbox.engine.start(CONTAINER_NAME);
};
<commit_msg>Fixed spelling mistake in error message in lib/share/sync/syncContainer.js.<commit_after>'use strict';

var Promise = require('../../promise.js');
var kbox = require('../../kbox.js');

/*
 * Constants.
 */
var IMAGE_NAME = 'kalabox/syncthing:stable';
var CONTAINER_NAME = 'kalabox_syncthing';

// Query engine to see if syncthing container exists.
var isInstalled = exports.isInstalled = function() {
  return kbox.engine.exists(CONTAINER_NAME);
};

// Query engine to see if syncthing container is running.
exports.isRunning = function() {
  // Inspect.
  return kbox.engine.inspect(CONTAINER_NAME)
  // Return container's running status.
  .then(function(data) {
    return data.State.Running;
  });
};

// Create syncthing container.
exports.create = function(binds) {

  kbox.core.log.debug('SYNC CONTAINER => Binds', binds);

  var opts = {
    Image: IMAGE_NAME,
    name: CONTAINER_NAME,
    HostConfig: {
      Binds: binds,
      NetworkMode: 'bridge',
      PortBindings: {
        '60008/tcp': [{'HostIp': '', 'HostPort': '60008'}],
        '22000/tcp': [{'HostIp': '', 'HostPort': '22000'}],
        '21025/udp': [{'HostIp': '', 'HostPort': '21025'}],
        '21026/udp': [{'HostIp': '', 'HostPort': '21026'}]
      }
    }
  };

  // Create container.
  return kbox.engine.create(opts);

};

/*
 * Remove syncthing container.
 */
var remove = exports.remove = function(counter) {

  // Set default counter.
  if (counter === undefined) {
    counter = 5;
  }

  // Remove container.
  return kbox.engine.remove(CONTAINER_NAME)
  // Check if the container is still installed.
  .then(isInstalled)
  // Keep trying until container is uninstalled or we run out of attempts.
  .then(function(isInstalled) {
    if (isInstalled) {
      if (counter > 0) {
        // Wait 3 seconds, then call this function again.
        return Promise.delay(3 * 1000)
        .then(function() {
          return remove(counter - 1);
        });
      } else {
        // We have run out of attempts, so throw an error.
        throw new Error('Could not remove container ' + CONTAINER_NAME);
      }
    }
  });

};

// Start syncthing container.
exports.start = function(opts) {
  // Start container.
  return kbox.engine.start(CONTAINER_NAME);
};

{'fraction_non_alphanumeric': 0.15167269439421338, 'fraction_numerical': 0.022151898734177215, 'mean_word_length': 2.817946505608283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4099215', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1430, 'n_words': 363}