...
|
...
|
@@ -19,8 +19,8 @@ const exists = (server, path) => new Promise((resolve, reject) => { |
|
|
|
|
|
client.once('connected', function () {
|
|
|
_exists(client, path).then(stat => {
|
|
|
resolve(stat);
|
|
|
client.close();
|
|
|
resolve(stat);
|
|
|
});
|
|
|
});
|
|
|
|
...
|
...
|
@@ -34,6 +34,7 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) |
|
|
_exists(client, path).then(stat => {
|
|
|
if (stat && iscover) {
|
|
|
client.setData(path, new Buffer(value.toString()), function(err, data, stat) {
|
|
|
client.close();
|
|
|
if (err) {
|
|
|
console.log('update path %s data error');
|
|
|
resolve(false);
|
...
|
...
|
@@ -43,9 +44,11 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) |
|
|
}
|
|
|
});
|
|
|
} else if (stat) {
|
|
|
client.close();
|
|
|
resolve(true);
|
|
|
} else {
|
|
|
client.mkdirp(path, new Buffer(value), (err, path) => {
|
|
|
client.close();
|
|
|
if (err) {
|
|
|
console.log('Node %s create err', path, err.stack);
|
|
|
resolve(false);
|
...
|
...
|
@@ -55,7 +58,6 @@ const creator = (server, path, value, iscover) => new Promise((resolve, reject) |
|
|
}
|
|
|
});
|
|
|
}
|
|
|
client.close();
|
|
|
});
|
|
|
});
|
|
|
|
...
|
...
|
@@ -76,7 +78,6 @@ const getter = (server, path) => new Promise((resolve, reject) => { |
|
|
}
|
|
|
|
|
|
client.close();
|
|
|
|
|
|
resolve(data && data.toString('utf8'));
|
|
|
}
|
|
|
)
|
...
|
...
|
@@ -99,6 +100,7 @@ const setter = (server, path, value) => new Promise((resolve, reject) => { |
|
|
_exists(client, path).then(stat => {
|
|
|
if (stat) {
|
|
|
client.setData(path, new Buffer(val.toString()), function(err, data, stat) {
|
|
|
client.close();
|
|
|
if (err) {
|
|
|
console.log('update path %s data error');
|
|
|
resolve(false);
|
...
|
...
|
@@ -106,10 +108,9 @@ const setter = (server, path, value) => new Promise((resolve, reject) => { |
|
|
console.log('path %s data change to', path, value);
|
|
|
resolve(true);
|
|
|
}
|
|
|
|
|
|
client.close();
|
|
|
});
|
|
|
} else {
|
|
|
client.close();
|
|
|
resolve(false);
|
|
|
}
|
|
|
});
|
...
|
...
|
|