From 51793863317f57b5e1d7d6d05043a8b8d3fee746 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Wed, 26 Jun 2013 08:30:38 +1000 Subject: [PATCH] fixing multiple / in paths --- lib/cache.js | 4 -- lib/maintain.js | 2 +- lib/repo-yum.js | 110 ++++++++++++++++++++++++++++++++---------------------- 3 files changed, 66 insertions(+), 50 deletions(-) diff --git a/lib/cache.js b/lib/cache.js index 464c1b3..5a01871 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -345,10 +345,6 @@ function moveToCleanup(file_or_dir) { fs.renameSync(file_or_dir.replace(/\/$/, ""), toloc); } -function cleanupRoutine() { - -} - exports.serviceDirectory = serviceDirectory; exports.moveToCleanup = moveToCleanup; diff --git a/lib/maintain.js b/lib/maintain.js index cd8ea8b..6ae0429 100644 --- a/lib/maintain.js +++ b/lib/maintain.js @@ -89,7 +89,7 @@ function walkDir(dir, done) { (function next() { var file = list[i++]; if (!file) return done(null, results); - file = path.normalize(dir + "/" + file); + file = path.normalize(dir + "/" + file).replace(/\/+/g, "/"); fs.stat(file, function(err, stat) { if (stat && stat.isDirectory()) { walkDir(file, function(err, res) { diff --git a/lib/repo-yum.js b/lib/repo-yum.js index 98061c9..ab88039 100644 --- a/lib/repo-yum.js +++ b/lib/repo-yum.js @@ -13,59 +13,79 @@ function maintain(name, repoinfo, files) { var metaAge = 24*3600*1000*(repoinfo.updateinterval); var expireAge = 24*3600*1000*(repoinfo.expiretime); + function fileCheck(i) { + var wasExpired = false; + var inDownload = false; + log.debug("checking file: ", files[i]); + log.debug("checking if file is in download mode"); + + // need to check global.repoproxy.downloads + if(typeof global.repoproxy.downloads[files[i]] != "undefined") { + if(global.repoproxy.downloads[files[i]] == 1) { + inDownload=true; + } + } + + // we look for repodata/repomd.xml file, if this is past maturity, we clean that whole directory - if(files[i].match(/.*repodata\/repomd\.xml$/)) { - log.debug("Found repomd.xml file: ", files[i]); - - // strip the repomd file to get the dir - var repomddir = files[i].replace(/repomd\.xml$/, ""); - log.debug("repomd dir is:", repomddir); - - - // do the file stat - fs.stat(files[i], function(err, stats) { - log.debug("stats for file was: ", stats); - var curtime = new Date().getTime(); - var ctime = stats.ctime.getTime(); - log.debug("curtime is ", curtime); - log.debug("ctime is ", ctime); + if(!inDownload) { + if(files[i].match(/.*repodata\/repomd\.xml$/)) { + log.debug("Found repomd.xml file: ", files[i]); - var age = curtime - ctime; - log.debug("age is (%d) for (%d)", age, metaAge); - if(age > metaAge) { - cache.moveToCleanup(repomddir); - log.info("Sending repomd directory to trash for cleanup (%s)", repomddir); - } - }) - - } else { - // STUFF!!! - fs.stat(files[i], function(err, stats) { - log.debug("stats for file was: ", stats); - var curtime = new Date().getTime(); - var atime = stats.atime.getTime(); - log.debug("curtime is ", curtime); - log.debug("ctime is ", atime); + // strip the repomd file to get the dir + var repomddir = files[i].replace(/repomd\.xml$/, ""); + log.debug("repomd dir is:", repomddir); + - var age = curtime - atime; - //log.debug("age is (%d) for (%d)", age, expireAge); - if(age > expireAge) { - // TODO: cleanup singular file - // TODO: cleanup meta too, fuck me - //log.debug("clean up file \n", files[i]); - var metafile = files[i].replace(/(.*)\/(.[^\/]+$)/, "$1/.meta.$2.filesize"); - //log.debug("meta for this file is \n", nfile); - cache.moveToCleanup(files[i]); - cache.moveToCleanup(metafile); - log.info("Sending expired file to trash for cleanup (%s)", files[i]); - } - }) + // do the file stat + fs.stat(files[i], function(err, stats) { + log.debug("stats for file was: ", stats); + var curtime = new Date().getTime(); + var ctime = stats.ctime.getTime(); + log.debug("curtime is ", curtime); + log.debug("ctime is ", ctime); + + var age = curtime - ctime; + log.debug("age is (%d) for (%d)", age, metaAge); + if(age > metaAge) { + cache.moveToCleanup(repomddir); + log.info("Sending repomd directory to trash for cleanup (%s)", repomddir); + wasExpired = true; + } + }) + + } else { + // STUFF!!! + fs.stat(files[i], function(err, stats) { + log.debug("stats for file was: ", stats); + var curtime = new Date().getTime(); + var atime = stats.atime.getTime(); + log.debug("curtime is ", curtime); + log.debug("ctime is ", atime); + + var age = curtime - atime; + //log.debug("age is (%d) for (%d)", age, expireAge); + if(age > expireAge) { + // TODO: cleanup singular file + // TODO: cleanup meta too, fuck me + //log.debug("clean up file \n", files[i]); + var metafile = files[i].replace(/(.*)\/(.[^\/]+$)/, "$1/.meta.$2.filesize"); + //log.debug("meta for this file is \n", nfile); + cache.moveToCleanup(files[i]); + cache.moveToCleanup(metafile); + log.info("Sending expired file to trash for cleanup (%s)", files[i]); + wasExpired = true; + } + }) + } + } else { + log.debug("file %s was ignored as its in download", files[i]); } - if(typeof files[i+1] != "undefined") fileCheck(i+1); + if(typeof files[i+1] != "undefined") fileCheck(i+1); } if(typeof files[0] != 'undefined') fileCheck(0) -- 1.7.0.4