diff backends/directory.js @ 30:b2faacfefb90

Rewrite of the module manager; fix of some modules; fix of the directory backend.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 04 Nov 2010 17:50:52 +0100
parents e007a6364bf0
children 62cbb1c49bc5
line wrap: on
line diff
--- a/backends/directory.js
+++ b/backends/directory.js
@@ -54,26 +54,19 @@ backend.save = function(dir) {
 
 			var inspect = require('sys').inspect;
 
+			for (var nodeID in data)
+				fs.writeFile(dir+'/'+nodeID+'.json', inspect(data[nodeID], false, null));
+
 			var toDelete = [];
 
 			for (var i in files) {
-				var nodeID = files[i];
-				if (nodeID in data) {
-					fs.writeFile(dir+'/'+nodeID+'.json', inspect(data[nodeID], false, null));
-					delete data[nodeID];
-				} else
-					toDelete.push(nodeID);
+				var file = files[i];
+				if (!(file.replace(/\.json$/, '') in data))
+					toDelete.push(file);
 			}
 
-			for (var nodeID in data) {
-				inspect(nodeID);
-				inspect(data[nodeID]);
-				fs.writeFile(dir+'/'+nodeID+'.json', inspect(data[nodeID], false, null));
-			}
-
-			for (var nodeID in toDelete) {
-				fs.unlink(toDelete[nodeID]);
-			}
+			for (var nodeID in toDelete)
+				fs.unlink(dir+'/'+toDelete[nodeID]);
 		});
 	});
 }