fixing multiple / in paths
authorPaul J R <me@pjr.cc>
Tue, 25 Jun 2013 22:30:38 +0000 (08:30 +1000)
committerPaul J R <me@pjr.cc>
Tue, 25 Jun 2013 22:30:38 +0000 (08:30 +1000)
lib/cache.js
lib/maintain.js
lib/repo-yum.js

index 464c1b3..5a01871 100644 (file)
@@ -345,10 +345,6 @@ function moveToCleanup(file_or_dir) {
        fs.renameSync(file_or_dir.replace(/\/$/, ""), toloc);
 }
 
-function cleanupRoutine() {
-       
-}
-
 
 exports.serviceDirectory = serviceDirectory;
 exports.moveToCleanup = moveToCleanup;
index cd8ea8b..6ae0429 100644 (file)
@@ -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) {
index 98061c9..ab88039 100644 (file)
@@ -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)