update createNonClashingName and caller

pull/3094/head
yann300 7 years ago
parent eb48b9204d
commit 130b7d3da2
  1. 21
      src/app.js
  2. 4
      src/app/panels/file-panel.js
  3. 4
      src/app/tabs/run-tab.js
  4. 22
      src/lib/helper.js

@ -3,6 +3,7 @@
var $ = require('jquery')
var csjs = require('csjs-inject')
var yo = require('yo-yo')
var async = require('async')
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
@ -463,15 +464,21 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
function loadFiles (filesSet, fileProvider) {
if (!fileProvider) fileProvider = 'browser'
for (var f in filesSet) {
var name = helper.createNonClashingName(f, filesProviders[fileProvider])
if (helper.checkSpecialChars(name)) {
async.each(Object.keys(filesSet), (file, callback) => {
helper.createNonClashingName(file, filesProviders[fileProvider],
(error, name) => {
if (error) {
modalDialogCustom.alert('Unexpected error loading the file ' + error)
} else if (helper.checkSpecialChars(name)) {
modalDialogCustom.alert('Special characters are not allowed')
return
}
filesProviders[fileProvider].set(name, filesSet[f].content)
} else {
filesProviders[fileProvider].set(name, filesSet[file].content)
}
fileManager.switchFile()
callback()
})
}, (error) => {
if (!error) fileManager.switchFile()
})
}
// Replace early callback with instant response

@ -224,13 +224,15 @@ function filepanel (appAPI, filesProvider) {
function createNewFile () {
modalDialogCustom.prompt(null, 'File Name', 'Untitled.sol', (input) => {
var newName = filesProvider['browser'].type + '/' + helper.createNonClashingName(input, filesProvider['browser'])
filesProvider['browser'].type + '/' + helper.createNonClashingName(input, filesProvider['browser'], (error, newName) => {
if (error) return modalDialogCustom.alert('Failed to create file ' + newName + ' ' + error)
if (!filesProvider['browser'].set(newName, '')) {
modalDialogCustom.alert('Failed to create file ' + newName)
} else {
appAPI.switchFile(newName)
}
})
})
}
/**

@ -161,12 +161,14 @@ function makeRecorder (events, appAPI, appEvents) {
var fileProvider = appAPI.fileProviderOf(path)
if (fileProvider) {
var newFile = path + input
newFile = helper.createNonClashingName(newFile, fileProvider, '.json')
helper.createNonClashingName(newFile, fileProvider, (error, newFile) => {
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
if (!fileProvider.set(newFile, txJSON)) {
modalDialogCustom.alert('Failed to create file ' + newFile)
} else {
appAPI.switchFile(newFile)
}
})
}
})
}

@ -1,3 +1,5 @@
var async = require('async')
module.exports = {
shortenAddress: function (address, etherBalance) {
var len = address.length
@ -9,7 +11,7 @@ module.exports = {
var len = data.length
return data.slice(0, 5) + '...' + data.slice(len - 5, len)
},
createNonClashingName (name, fileProvider) {
createNonClashingName (name, fileProvider, cb) {
var counter = ''
var ext = 'sol'
var reg = /(.*)\.([^.]+)/g
@ -18,10 +20,22 @@ module.exports = {
name = split[1]
ext = split[2]
}
while (fileProvider.exists(name + counter + '.' + ext)) {
counter = (counter | 0) + 1
var exist = true
async.whilst(
() => { return exist },
(callback) => {
fileProvider.exists(name + counter + '.' + ext, (error, currentExist) => {
if (error) {
callback(error)
} else {
exist = currentExist
if (exist) counter = (counter | 0) + 1
callback()
}
return name + counter + '.' + ext
})
},
(error) => { cb(error, name + counter + '.' + ext) }
)
},
checkSpecialChars (name) {
return name.match(/[/:*?"<>\\'|]/) != null

Loading…
Cancel
Save