From 613c944f0c7e451eca3f2102537fecd17c451d63 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Mon, 16 Feb 2015 23:18:42 -0800 Subject: [PATCH] Fixing rename bugs --- gulpfile.js | 9 +++--- package.json | 2 +- src/ContainerSettingsGeneral.react.js | 44 ++++++++++++++++++++------- src/ContainerStore.js | 21 ++++++++----- src/LogStore.js | 7 ++++- src/MenuTemplate.js | 5 --- src/SetupStore.js | 1 - 7 files changed, 58 insertions(+), 31 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 7a8ba4d0cd..484b9a97ab 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -29,16 +29,15 @@ var options = { gulp.task('js', function () { return gulp.src('src/**/*.js') + .pipe(plumber(function(error) { + gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.message)); + })) .pipe(gulpif(options.dev || options.test, sourcemaps.init())) .pipe(react()) .pipe(babel({blacklist: ['regenerator']})) .pipe(gulpif(options.dev || options.test, sourcemaps.write('.'))) .pipe(gulp.dest((options.dev || options.test) ? './build' : './dist/osx/' + options.filename + '/Contents/Resources/app/build')) - .pipe(gulpif(options.dev, livereload())) - .pipe(plumber(function(error) { - gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.message)); - this.emit('end'); - })); + .pipe(gulpif(options.dev, livereload())); }); gulp.task('images', function() { diff --git a/package.json b/package.json index f805ea6c29..ccb23f3beb 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "babel": "^4.0.1", "bluebird": "^2.9.6", "bugsnag-js": "^2.4.7", - "dockerode": "2.0.4", + "dockerode": "^2.0.7", "download": "^4.0.0", "exec": "0.1.2", "jquery": "^2.1.3", diff --git a/src/ContainerSettingsGeneral.react.js b/src/ContainerSettingsGeneral.react.js index c529b18bea..56654428f7 100644 --- a/src/ContainerSettingsGeneral.react.js +++ b/src/ContainerSettingsGeneral.react.js @@ -31,6 +31,7 @@ var ContainerSettingsGeneral = React.createClass({ getInitialState: function () { return { slugName: null, + nameError: null, env: {}, pendingEnv: {} }; @@ -48,6 +49,7 @@ var ContainerSettingsGeneral = React.createClass({ } this.setState({ env: ContainerUtil.env(container), + nameError: null }); }, handleNameChange: function (e) { @@ -61,7 +63,8 @@ var ContainerSettingsGeneral = React.createClass({ }); } else { this.setState({ - slugName: containerNameSlugify(newName) + slugName: containerNameSlugify(newName), + nameError: null }); } }, @@ -75,20 +78,35 @@ var ContainerSettingsGeneral = React.createClass({ if (newName === this.props.container.Name) { return; } - if (fs.existsSync(path.join(process.env.HOME, 'Kitematic', this.props.container.Name))) { - fs.renameSync(path.join(process.env.HOME, 'Kitematic', this.props.container.Name), path.join(process.env.HOME, 'Kitematic', newName)); - } + this.setState({ slugName: null }); - ContainerStore.updateContainer(this.props.container.Name, { - name: newName - }, function (err) { - this.transitionTo('containerSettingsGeneral', {name: newName}); - if (err) { - console.error(err); + var oldName = this.props.container.Name; + if (ContainerStore.container(newName)) { + this.setState({ + nameError: 'A container already exists with this name.' + }); + return; + } + var oldPath = path.join(process.env.HOME, 'Kitematic', oldName); + var newPath = path.join(process.env.HOME, 'Kitematic', newName); + rimraf(newPath, () => { + if (fs.existsSync(oldPath)) { + fs.renameSync(oldPath, newPath); } - }.bind(this)); + var binds = _.pairs(this.props.container.Volumes).map(function (pair) { + return pair[1] + ':' + pair[0]; + }); + var newBinds = binds.map(b => { + return b.replace(path.join(process.env.HOME, 'Kitematic', oldName), path.join(process.env.HOME, 'Kitematic', newName)); + }); + ContainerStore.updateContainer(oldName, {Binds: newBinds, name: newName}, err => { + this.transitionTo('containerSettingsGeneral', {name: newName}); + rimraf(oldPath, () => {}); + console.log(err); + }); + }); }, handleSaveEnvVar: function () { var $rows = $('.env-vars .keyval-row'); @@ -172,6 +190,10 @@ var ContainerSettingsGeneral = React.createClass({ btnSaveName = ( Save ); + } else if (this.state.nameError) { + willBeRenamedAs = ( +

{this.state.nameError}

+ ); } var rename = (
diff --git a/src/ContainerStore.js b/src/ContainerStore.js index ff71eee3ce..200df9b35d 100644 --- a/src/ContainerStore.js +++ b/src/ContainerStore.js @@ -5,6 +5,7 @@ var path = require('path'); var assign = require('object-assign'); var docker = require('./Docker'); var registry = require('./Registry'); +var LogStore = require('./LogStore'); var _placeholders = {}; var _containers = {}; @@ -207,13 +208,10 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), { callback(); } var placeholderData = JSON.parse(localStorage.getItem('store.placeholders')); - console.log(placeholderData); - console.log(_.keys(_containers)); if (placeholderData) { _placeholders = _.omit(placeholderData, _.keys(_containers)); localStorage.setItem('store.placeholders', JSON.stringify(_placeholders)); } - console.log(_placeholders); this.emit(this.CLIENT_CONTAINER_EVENT); this._resumePulling(); this._startListeningToEvents(); @@ -242,7 +240,13 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), { callback(err); return; } - async.map(containers, function (container, callback) { + var names = new Set(_.map(containers, container => container.Names[0].replace('/', ''))); + _.each(_.keys(_containers), name => { + if (!names.has(name)) { + delete _containers[name]; + } + }); + async.each(containers, function (container, callback) { self.fetchContainer(container.Id, function (err) { callback(err); }); @@ -267,8 +271,6 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), { Downloading: true } }; - console.log(_placeholders); - console.log(JSON.stringify(_placeholders)); localStorage.setItem('store.placeholders', JSON.stringify(_placeholders)); self.emit(self.CLIENT_CONTAINER_EVENT, containerName, 'create'); @@ -289,13 +291,18 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), { callback(null, containerName); }, updateContainer: function (name, data, callback) { - _muted[name] = true; if (!data.name) { data.name = data.Name; } + _muted[name] = true; + _muted[data.name] = true; + if (name !== data.name) { + LogStore.rename(name, data.name); + } var fullData = assign(_containers[name], data); this._createContainer(name, fullData, function (err) { _muted[name] = false; + _muted[data.name] = false; this.emit(this.CLIENT_CONTAINER_EVENT, name); callback(err); }.bind(this)); diff --git a/src/LogStore.js b/src/LogStore.js index 27d9f2bbe2..5d57eed441 100644 --- a/src/LogStore.js +++ b/src/LogStore.js @@ -34,7 +34,7 @@ var LogStore = assign(Object.create(EventEmitter.prototype), { if (err) { return; } - _logs[name] = []; + _logs[name] = _logs[name] || []; stream.setEncoding('utf8'); var timeout; stream.on('data', function (buf) { @@ -64,6 +64,11 @@ var LogStore = assign(Object.create(EventEmitter.prototype), { this.fetchLogs(name); } return _logs[name] || []; + }, + rename: function (name, newName) { + if (_logs[name]) { + _logs[newName] = _logs[name]; + } } }); diff --git a/src/MenuTemplate.js b/src/MenuTemplate.js index c5a0095663..642a445574 100644 --- a/src/MenuTemplate.js +++ b/src/MenuTemplate.js @@ -64,11 +64,6 @@ var MenuTemplate = [ { label: 'File', submenu: [ - { - label: 'New Container', - accelerator: 'Command+N', - selector: 'undo:' - }, { type: 'separator' }, diff --git a/src/SetupStore.js b/src/SetupStore.js index 3f36d06201..e7f8dcbc6c 100644 --- a/src/SetupStore.js +++ b/src/SetupStore.js @@ -165,7 +165,6 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), { run: Promise.coroutine(function* () { yield this.updateBinaries(); var steps = yield this.requiredSteps(); - console.log(steps); for (let step of steps) { console.log(step.name); _currentStep = step;