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 = (