Mercurial > psgxs
comparison backends/directory.js @ 55:fd69d35cf2e6
Move default storage directory; better naming of nodes; fix notification sending.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 25 Jul 2011 17:35:32 -0700 |
parents | 023f767662d3 |
children | 99bd1d1ac071 |
comparison
equal
deleted
inserted
replaced
54:c2c9c06d6e9d | 55:fd69d35cf2e6 |
---|---|
23 var Node = require('../nodes').Node; | 23 var Node = require('../nodes').Node; |
24 var backend = exports; | 24 var backend = exports; |
25 | 25 |
26 backend.save = function(dir) { | 26 backend.save = function(dir) { |
27 if (!dir) | 27 if (!dir) |
28 dir = 'storage'; | 28 dir = 'data'; |
29 | 29 |
30 fs.stat(dir, function(err, stats) { | 30 fs.stat(dir, function(err, stats) { |
31 if (err) | 31 if (err) |
32 fs.mkdir(dir, 509); // 0755 in decimal | 32 fs.mkdir(dir, 509); // 0755 in decimal |
33 else if (!stats.isDirectory()) { | 33 else if (!stats.isDirectory()) { |
55 var data = sanitize(backend.list); | 55 var data = sanitize(backend.list); |
56 | 56 |
57 var inspect = require('sys').inspect; | 57 var inspect = require('sys').inspect; |
58 | 58 |
59 for (var nodeID in data) | 59 for (var nodeID in data) |
60 fs.writeFile(dir+'/'+nodeID+'.json', inspect(data[nodeID], false, null)); | 60 fs.writeFile(dir+'/'+encodeURI(nodeID).replace('/', '%2f')+'.json', inspect(data[nodeID], false, null)); |
61 | 61 |
62 var toDelete = []; | 62 var toDelete = []; |
63 | 63 |
64 for (var i in files) { | 64 for (var i in files) { |
65 var file = files[i]; | 65 var file = files[i]; |
66 if (!(file.replace(/\.json$/, '') in data)) | 66 if (!(file.replace(/\.json$/, '') in data)) |
67 toDelete.push(file); | 67 toDelete.push(file); |
68 } | 68 } |
69 | 69 |
70 for (var nodeID in toDelete) | 70 for (var nodeID in toDelete) |
71 fs.unlink(dir+'/'+toDelete[nodeID]); | 71 fs.unlink(dir+'/'+encodeURI(toDelete[nodeID]).replace('/', '%2f')); |
72 }); | 72 }); |
73 }); | 73 }); |
74 } | 74 } |
75 | 75 |
76 backend.load = function(dir) { | 76 backend.load = function(dir) { |
77 if (!dir) | 77 if (!dir) |
78 dir = 'storage'; | 78 dir = 'data'; |
79 | 79 |
80 fs.stat(dir, function(err, stats) { | 80 fs.stat(dir, function(err, stats) { |
81 if (err) | 81 if (err) |
82 fs.mkdir(dir, 509); // 0755 in decimal | 82 fs.mkdir(dir, 509); // 0755 in decimal |
83 else if (!stats.isDirectory()) { | 83 else if (!stats.isDirectory()) { |
118 for (var i in files) { | 118 for (var i in files) { |
119 var file = files[i]; | 119 var file = files[i]; |
120 if (/^\./.test(file)) | 120 if (/^\./.test(file)) |
121 continue; | 121 continue; |
122 | 122 |
123 var nodeID = file.replace(/\.json$/, ''); | 123 var nodeID = decodeURI(file.replace(/\.json$/, '').replace('%2f', '/')); |
124 | 124 |
125 var data = fs.readFileSync(dir+'/'+file).toString(); | 125 var data = fs.readFileSync(dir+'/'+file).toString(); |
126 | 126 |
127 var obj = eval('('+data+')'); | 127 var obj = eval('('+data+')'); |
128 backend.list[nodeID] = endParsing(obj); | 128 backend.list[nodeID] = endParsing(obj); |