Implement files.listAsTree()

pull/1/head
Alex Beregszaszi 8 years ago
parent ba5051fced
commit 09bbcf54b4
  1. 41
      src/app/files.js

@ -107,6 +107,47 @@ function Files (storage) {
return files return files
} }
//
// Tree model for files
// {
// 'a': { }, // empty directory 'a'
// 'b': {
// 'c': {}, // empty directory 'b/c'
// 'd': { '/readonly': true, '/content': 'Hello World' } // files 'b/c/d'
// 'e': { '/readonly': false, '/path': 'b/c/d' } // symlink to 'b/c/d'
// 'f': { '/readonly': false, '/content': '<executable>', '/mode': 0755 }
// }
// }
//
this.listAsTree = function () {
function hashmapize (obj, path, val) {
var nodes = path.split('/')
var i = 0
for (; i < nodes.length - 1; i++) {
var node = nodes[i]
if (obj[node] === undefined) {
obj[node] = {}
}
obj = obj[node]
}
obj[nodes[i]] = val
}
var tree = {}
var self = this
storage.keys().forEach(function (path) {
hashmapize(tree, path, {
'/readonly': self.isReadOnly(path),
'/content': self.get(path)
})
})
return tree
}
// rename .browser-solidity.json to .remix.config // rename .browser-solidity.json to .remix.config
if (this.exists('.browser-solidity.json')) { if (this.exists('.browser-solidity.json')) {
this.rename('.browser-solidity.json', '.remix.config') this.rename('.browser-solidity.json', '.remix.config')

Loading…
Cancel
Save