Commit abeccd51 authored by Alex Beregszaszi's avatar Alex Beregszaszi

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

parent 60fc07ee
...@@ -10,7 +10,7 @@ function Files (storage) { ...@@ -10,7 +10,7 @@ function Files (storage) {
this.exists = function (path) { this.exists = function (path) {
// NOTE: ignore the config file // NOTE: ignore the config file
if (path === '.browser-solidity.json') { if (path === '.browser-solidity.json') {
return return false
} }
if (this.isReadOnly(path)) { if (this.isReadOnly(path)) {
...@@ -23,7 +23,7 @@ function Files (storage) { ...@@ -23,7 +23,7 @@ function Files (storage) {
this.get = function (path) { this.get = function (path) {
// NOTE: ignore the config file // NOTE: ignore the config file
if (path === '.browser-solidity.json') { if (path === '.browser-solidity.json') {
return return null
} }
if (this.isReadOnly(path)) { if (this.isReadOnly(path)) {
...@@ -36,25 +36,33 @@ function Files (storage) { ...@@ -36,25 +36,33 @@ function Files (storage) {
this.set = function (path, content) { this.set = function (path, content) {
// NOTE: ignore the config file // NOTE: ignore the config file
if (path === '.browser-solidity.json') { if (path === '.browser-solidity.json') {
return return false
} }
if (!this.isReadOnly(path)) { if (!this.isReadOnly(path)) {
var exists = storage.exists(path) var exists = storage.exists(path)
storage.set(path, content) if (!storage.set(path, content)) {
return false
}
if (!exists) { if (!exists) {
event.trigger('fileAdded', [path]) event.trigger('fileAdded', [path])
} else { } else {
event.trigger('fileChanged', [path]) event.trigger('fileChanged', [path])
} }
return true
} }
return false
} }
this.addReadOnly = function (path, content) { this.addReadOnly = function (path, content) {
if (!storage.exists(path)) { if (!storage.exists(path)) {
readonly[path] = content readonly[path] = content
event.trigger('fileAdded', [path]) event.trigger('fileAdded', [path])
return true
} }
return false
} }
this.isReadOnly = function (path) { this.isReadOnly = function (path) {
...@@ -63,22 +71,29 @@ function Files (storage) { ...@@ -63,22 +71,29 @@ function Files (storage) {
this.remove = function (path) { this.remove = function (path) {
if (!this.exists(path)) { if (!this.exists(path)) {
return return false
} }
if (this.isReadOnly(path)) { if (this.isReadOnly(path)) {
readonly[path] = undefined readonly[path] = undefined
} else { } else {
storage.remove(path) if (!storage.remove(path)) {
return false
}
} }
event.trigger('fileRemoved', [path]) event.trigger('fileRemoved', [path])
return true
} }
this.rename = function (oldPath, newPath) { this.rename = function (oldPath, newPath) {
if (!this.isReadOnly(oldPath) && storage.exists(oldPath)) { if (!this.isReadOnly(oldPath) && storage.exists(oldPath)) {
storage.rename(oldPath, newPath) if (!storage.rename(oldPath, newPath)) {
return false
}
event.trigger('fileRenamed', [oldPath, newPath]) event.trigger('fileRenamed', [oldPath, newPath])
return true
} }
return false
} }
this.list = function () { this.list = function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment