function fileCheck(i) {
var wasExpired = false;
var inDownload = false;
+ var disappeared = false;
log.debug("checking file: ", files[i]);
log.debug("checking if file is in download mode");
} 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]);
- //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;
+ if(err) {
+ log.debug("some weird problem stating the file");
+ disappeared = true;
+ } else {
+ 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]);
+ //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;
+ }
}
})
}
// make sure we have a metadata file for our file
- fs.stat(metafile, function(err, stats) {
- if(err) {
- log.debug("file (%s) has no metadata file - moving for cleanup");
- cache.moveToCleanup(files[i]);
- cache.moveToCleanup(metafile);
- }
- });
-
- // check meta data
- fs.stat(files[i], function(err, stats) {
- var fsize = stats.size;
- var mfile = fs.createReadStream(metafile);
- var expSize = "";
- mfile.on("data", function(data) {
- expSize += data;
- });
-
- mfile.on("end", function(closed) {
- if(fsize != parseInt(expSize)) {
- log.debug("possible metadata clash for (%s) - (%d),(%s), removing file", files[i], fsize, expSize);
+ if(!disappeared) {
+ fs.stat(metafile, function(err, stats) {
+ if(err) {
+ log.debug("file (%s) has no metadata file - moving for cleanup");
cache.moveToCleanup(files[i]);
cache.moveToCleanup(metafile);
} else {
- log.debug("metadata good for (%s) - (%d),(%s)", files[i], fsize, expSize);
+
+ // check meta data
+ fs.stat(files[i], function(err, stats) {
+ var fsize = stats.size;
+ var mfile = fs.createReadStream(metafile);
+ var expSize = "";
+ mfile.on("data", function(data) {
+ expSize += data;
+ });
+
+ mfile.on("end", function(closed) {
+ if(fsize != parseInt(expSize)) {
+ log.debug("possible metadata clash for (%s) - (%d),(%s), removing file", files[i], fsize, expSize);
+ cache.moveToCleanup(files[i]);
+ cache.moveToCleanup(metafile);
+ } else {
+ log.debug("metadata good for (%s) - (%d),(%s)", files[i], fsize, expSize);
+ }
+ });
+
+ });
}
});
-
- });
+ }
} else {
log.debug("file %s was ignored as its in download", files[i]);