Skip to content

Commit a1f21c5

Browse files
committed
Fix off-by-one on number of backup files
1 parent cb1ec2e commit a1f21c5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/fileRotator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ class FileRotator extends EventEmitter {
116116

117117
async _deleteFiles() {
118118
const filesToDelete = [];
119-
let fileNumber = 0;
119+
// Only count backups - start at file 1 to ignore current file
120+
let fileNumber = 1;
120121
let bytesTotal = 0;
121122
for (; ; fileNumber++) {
122123
const name = this._getFileName(fileNumber, true);
123124
try {
124125
const result = await fs.stat(name);
125126
bytesTotal += result.size;
126-
if ((this._totalSize && bytesTotal > this._totalSize) || (this._totalFiles && fileNumber > this._totalFiles)) {
127+
if ((this._totalSize && bytesTotal > this._totalSize) || (this._totalFiles && fileNumber >= this._totalFiles)) {
127128
filesToDelete.push(name);
128129
}
129130
} catch (err) {

0 commit comments

Comments
 (0)