add callback to provider set

pull/1/head
yann300 7 years ago
parent 77929cefab
commit e78ed7e680
  1. 4
      src/app/files/browser-files-tree.js
  2. 7
      src/app/files/browser-files.js

@ -53,11 +53,12 @@ function FilesTree (name, storage) {
return content return content
} }
this.set = function (path, content) { this.set = function (path, content, cb) {
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
updateRefs(unprefixedpath, 'add') updateRefs(unprefixedpath, 'add')
var exists = storage.exists(unprefixedpath) var exists = storage.exists(unprefixedpath)
if (!storage.set(unprefixedpath, content)) { if (!storage.set(unprefixedpath, content)) {
if (cb) cb('error updating ' + path)
return false return false
} }
if (!exists) { if (!exists) {
@ -65,6 +66,7 @@ function FilesTree (name, storage) {
} else { } else {
event.trigger('fileChanged', [this.type + '/' + unprefixedpath]) event.trigger('fileChanged', [this.type + '/' + unprefixedpath])
} }
if (cb) cb()
return true return true
} }

@ -38,16 +38,18 @@ function Files (storage) {
return content return content
} }
this.set = function (path, content) { this.set = function (path, content, cb) {
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
// NOTE: ignore the config file // NOTE: ignore the config file
if (path === '.remix.config') { if (path === '.remix.config') {
if (cb) cb('change not allowed')
return false return false
} }
if (!this.isReadOnly(unprefixedpath)) { if (!this.isReadOnly(unprefixedpath)) {
var exists = storage.exists(unprefixedpath) var exists = storage.exists(unprefixedpath)
if (!storage.set(unprefixedpath, content)) { if (!storage.set(unprefixedpath, content)) {
if (cb) cb('error updating ' + path)
return false return false
} }
if (!exists) { if (!exists) {
@ -55,9 +57,10 @@ function Files (storage) {
} else { } else {
event.trigger('fileChanged', [this.type + '/' + unprefixedpath]) event.trigger('fileChanged', [this.type + '/' + unprefixedpath])
} }
if (cb) cb()
return true return true
} }
if (cb) cb('is read only')
return false return false
} }

Loading…
Cancel
Save