From b7051553920006266ecce46b02c1ffe467d066cd Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sat, 28 Apr 2012 01:04:59 +0400 Subject: example: async reading and async writing of /etc/hosts --- examples/async-write-etc-hosts.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/async-write-etc-hosts.js (limited to 'examples/async-write-etc-hosts.js') diff --git a/examples/async-write-etc-hosts.js b/examples/async-write-etc-hosts.js new file mode 100644 index 0000000..70640ab --- /dev/null +++ b/examples/async-write-etc-hosts.js @@ -0,0 +1,29 @@ +var aug = require('../build/Release/libaugeas'); + +// NOTE: +// running this example as non-root user will probably fail, +// but for the goodness sake we set AUG_SAVE_NEWFILE flag here, +// so your /etc/hosts will be kept untouched :-) +aug.createAugeas( + {lens: 'hosts', incl: '/etc/hosts', flags:aug.AUG_SAVE_NEWFILE}, + function(aug) { + if (!aug.error()) { + console.log('Making changes ...'); + aug.set('/files/etc/hosts/1/ipaddr', '127.0.0.2'); + aug.set('/files/etc/hosts/1/canonical', 'localhost'); + aug.save(function(success) { + if (success) { + console.log('Saved! Take a look at /etc/hosts.augnew'); + } else { + console.log('Failed :-( Here is the reason:'); + console.log(aug.get('/augeas/files/etc/hosts/error/message')); + } + }); + console.log('Saving started!'); + } else { + console.log('Sad, but true :-('); + } + } +); +console.log('Waiting for Augeas ...'); + -- cgit v1.2.3