(value)
| 144 | } |
| 145 | |
| 146 | function writeFile(value) { |
| 147 | var newId = value.id; |
| 148 | delete value.id; |
| 149 | if (typeof value === 'object') value = JSON.stringify(value, null, '\t'); |
| 150 | notifyType(id, 'Changed', resource, ctx.server, function(eventError) { |
| 151 | if(eventError) return ctx.done(eventError); |
| 152 | |
| 153 | fs.writeFile(file, value, function(err) { |
| 154 | if (err) return ctx.done(err); |
| 155 | |
| 156 | if (fileName.lastIndexOf('config.json') === fileName.length - ('config.json').length && |
| 157 | newId && newId !== id) { |
| 158 | //rename |
| 159 | if (newId.indexOf('/') === 0) newId = newId.substring(1); |
| 160 | try { |
| 161 | shell.mkdir('-p', path.join(basepath, 'resources', newId)); |
| 162 | shell.mv(path.join(basepath, 'resources', id, '/*'), path.join(basepath, 'resources', newId, '/')); |
| 163 | |
| 164 | deleteEmptySubdirs(basepath, id); |
| 165 | resource.id = newId; |
| 166 | ctx.done(null, resource); |
| 167 | } catch (err) { |
| 168 | if (err) return ctx.done(err); |
| 169 | } |
| 170 | } else { |
| 171 | resource.id = id; |
| 172 | ctx.done(null, resource); |
| 173 | } |
| 174 | }); |
| 175 | }); |
| 176 | } |
| 177 | |
| 178 | break; |
| 179 | case 'GET': |
no test coverage detected