Include comprehensive error handling in files API (always return true/false)

pull/1/head
Alex Beregszaszi 8 years ago
parent 60fc07ee8f
commit abeccd51e7
  1. 29
      src/app/files.js

@ -10,7 +10,7 @@ function Files (storage) {
this.exists = function (path) {
// NOTE: ignore the config file
if (path === '.browser-solidity.json') {
return
return false
}
if (this.isReadOnly(path)) {
@ -23,7 +23,7 @@ function Files (storage) {
this.get = function (path) {
// NOTE: ignore the config file
if (path === '.browser-solidity.json') {
return
return null
}
if (this.isReadOnly(path)) {
@ -36,25 +36,33 @@ function Files (storage) {
this.set = function (path, content) {
// NOTE: ignore the config file
if (path === '.browser-solidity.json') {
return
return false
}
if (!this.isReadOnly(path)) {
var exists = storage.exists(path)
storage.set(path, content)
if (!storage.set(path, content)) {
return false
}
if (!exists) {
event.trigger('fileAdded', [path])
} else {
event.trigger('fileChanged', [path])
}
return true
}
return false
}
this.addReadOnly = function (path, content) {
if (!storage.exists(path)) {
readonly[path] = content
event.trigger('fileAdded', [path])
return true
}
return false
}
this.isReadOnly = function (path) {
@ -63,22 +71,29 @@ function Files (storage) {
this.remove = function (path) {
if (!this.exists(path)) {
return
return false
}
if (this.isReadOnly(path)) {
readonly[path] = undefined
} else {
storage.remove(path)
if (!storage.remove(path)) {
return false
}
}
event.trigger('fileRemoved', [path])
return true
}
this.rename = function (oldPath, newPath) {
if (!this.isReadOnly(oldPath) && storage.exists(oldPath)) {
storage.rename(oldPath, newPath)
if (!storage.rename(oldPath, newPath)) {
return false
}
event.trigger('fileRenamed', [oldPath, newPath])
return true
}
return false
}
this.list = function () {

Loading…
Cancel
Save