Permalink
Browse files

files: refactor out into dropFile()

  • Loading branch information...
1 parent df441a3 commit 776643a885ebd9e498b667e0aed67d24465cbf6f @astro astro committed Jan 16, 2011
Showing with 9 additions and 4 deletions.
  1. +9 −4 files.js
View
@@ -46,18 +46,23 @@ exports.allocBytes = function(size) {
/* purge */
while(totalSize > MAX_TOTAL_SIZE &&
files.length > 0) {
+ this.dropFile();
+ }
+};
+exports.freeBytes = function(size) {
+ totalSize -= size;
+};
- var drop = files.pop();
+exports.dropFile = function() {
+ var drop;
+ if ((drop = files.pop())) {
exports.freeBytes(drop.size);
var path = FILES_PATH + '/' + drop.id;
console.log('rm old ' + path);
fs.unlink(path);
}
};
-exports.freeBytes = function(size) {
- totalSize -= size;
-};
exports.addFile = function(info) {
info.downloads = 0;

0 comments on commit 776643a

Please sign in to comment.