Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: zzeroo/nano-couchdb-interface
base: e5204411e4
...
head fork: zzeroo/nano-couchdb-interface
compare: b049ac1673
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 21, 2012
@zzeroo Generic inotify driven watch-dir-script
It watches a dir (~/PDF) for any changes. All inotify events were passed through a callback function.

Signed-off-by: zzeroo <co@zzeroo.com>
0af722e
@zzeroo First version.
The folder is watched.

TODO:
- just watch for pdf files
- add a config file
- parameterize the path of watched dir an file types
- an couchdb stuff
- add an couchdb buffered attachment

Signed-off-by: zzeroo <co@zzeroo.com>
6c47338
@zzeroo Add a TODO file
Signed-off-by: zzeroo <co@zzeroo.com>
b049ac1
Showing with 70 additions and 0 deletions.
  1. +6 −0 TODO
  2. +49 −0 test-inotify.js
  3. +15 −0 watch-dir-and-move-to-db.js
View
6 TODO
@@ -0,0 +1,6 @@
+TODO:
+ - just watch for pdf files
+ - add a config file
+ - parameterize the path of watched dir an file types
+ - an couchdb stuff
+ - add an couchdb buffered attachment
View
49 test-inotify.js
@@ -0,0 +1,49 @@
+var Inotify = require('inotify').Inotify
+var inotify = new Inotify();
+
+var pdf_dir = { path: '/home/smueller/PDF',
+ watch_for: Inotify.IN_ALL_EVENTS,
+ callback: function(event) {
+ var mask = event.mask;
+ var type = mask & Inotify.IN_ISDIR ? 'directory' : 'file ';
+ event.name ? type += ' ' + event.name + ' ': ' ';
+
+ //the porpuse of this hell of 'if'
+ //statements is only illustrative.
+
+ if(mask & Inotify.IN_ACCESS) {
+ console.log(type + 'was accessed ');
+ } else if(mask & Inotify.IN_MODIFY) {
+ console.log(type + 'was modified ');
+ } else if(mask & Inotify.IN_OPEN) {
+ console.log(type + 'was opened ');
+ } else if(mask & Inotify.IN_CLOSE_NOWRITE) {
+ console.log(type + ' opened for reading was closed ');
+ } else if(mask & Inotify.IN_CLOSE_WRITE) {
+ console.log(type + ' opened for writing was closed ');
+ } else if(mask & Inotify.IN_ATTRIB) {
+ console.log(type + 'metadata changed ');
+ } else if(mask & Inotify.IN_CREATE) {
+ console.log(type + 'created');
+ } else if(mask & Inotify.IN_DELETE) {
+ console.log(type + 'deleted');
+ } else if(mask & Inotify.IN_DELETE_SELF) {
+ console.log(type + 'watched deleted ');
+ } else if(mask & Inotify.IN_MOVE_SELF) {
+ console.log(type + 'watched moved');
+ } else if(mask & Inotify.IN_IGNORED) {
+ console.log(type + 'watch was removed');
+ } else if(mask & Inotify.IN_MOVED_FROM) {
+ data = event;
+ data.type = type;
+ } else if(mask & Inotify.IN_MOVED_TO) {
+ if( Object.keys(data).length &&
+ data.cookie === event.cookie) {
+ console.log(type + ' moved to ' + data.type);
+ data = {};
+ }
+ }
+ }};
+
+
+var watch_descriptor = inotify.addWatch(pdf_dir);
View
15 watch-dir-and-move-to-db.js
@@ -0,0 +1,15 @@
+var Inotify = require('inotify').Inotify
+var inotify = new Inotify();
+
+var pdf_dir = { path: '/home/smueller/PDF',
+ callback: function(event) {
+ var mask = event.mask;
+
+ if(mask & Inotify.IN_CREATE ) {
+ // copy event.name to couchdb
+ console.log("copy %s to couchdb...", event.name)
+ };
+ }};
+
+// create watch descriptor
+var wd = inotify.addWatch(pdf_dir);

No commit comments for this range

Something went wrong with that request. Please try again.