From 61e1468b686aa628302d0dda83ef5dfa3b6c99f1 Mon Sep 17 00:00:00 2001 From: Rob Tirserio Date: Thu, 8 Aug 2013 15:41:02 -0400 Subject: [PATCH] use mkdir and a callback rather than mkdirSync when writing the sitemap --- routes/index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/routes/index.js b/routes/index.js index cb8d287..81af78b 100644 --- a/routes/index.js +++ b/routes/index.js @@ -110,8 +110,15 @@ function postAddScraper(req, res) var sitemap_path = "public/sitemaps/"; fs.exists(sitemap_path, function(exists) { if (!exists) { - fs.mkdirSync(sitemap_path); + fs.mkdir(sitemap_path, wrtieSitemap); + } else { + wrtieSitemap(); } + + // Terminate crawling daemon + child.kill(); + }); + function wrtieSitemap() { var filename = "sitemap_"+ data.host +".xml"; fs.writeFile(sitemap_path + filename, data.content, function(err) { @@ -119,11 +126,9 @@ function postAddScraper(req, res) console.log(err); else io.sockets.emit('sitemap-ready', {path: sitemap_path.replace("public/", "")}) + }); - // Terminate crawling daemon - child.kill(); - }); - }); +} break; } })