Skip to content

Commit 516ab98

Browse files
author
Matt Berther
committed
swallowing exceptions if unable to unlink log file
1 parent 82d7b17 commit 516ab98

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,13 @@ DailyRotateFile.prototype._getFile = function (inc) {
585585
if (this.maxFiles && (this._created >= (this.maxFiles - 1))) {
586586
remaining = this._created - (this.maxFiles - 1);
587587
if (remaining === 0) {
588-
fs.unlinkSync(path.join(this.dirname, filename));
588+
try {
589+
fs.unlinkSync(path.join(this.dirname, filename));
590+
} catch (e) {}
589591
} else {
590-
fs.unlinkSync(path.join(this.dirname, filename + '.' + remaining));
592+
try {
593+
fs.unlinkSync(path.join(this.dirname, filename + '.' + remaining));
594+
} catch (e) {}
591595
}
592596
}
593597

test/simple.tests.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ var MemoryStream = require('./memory-stream');
1414
var DailyRotateFile = require('../');
1515

1616
var fixturesDir = path.join(__dirname, 'fixtures');
17-
rimraf.sync(fixturesDir);
18-
mkdirp(fixturesDir);
1917

2018
var transports = {
2119
'file': new DailyRotateFile({
@@ -39,10 +37,15 @@ var transports = {
3937
};
4038

4139
describe('winston/transports/daily-rotate-file', function () {
40+
before(function () {
41+
rimraf.sync(fixturesDir);
42+
mkdirp.sync(fixturesDir);
43+
});
44+
4245
describe('an instance of the transport', function () {
4346
describe('with default datePatterns', function () {
4447
it('should have a proper filename when prepend option is false', function () {
45-
var now = moment().format('YYYY-MM-DD');
48+
var now = moment().utc().format('YYYY-MM-DD');
4649
var transport = new DailyRotateFile({
4750
filename: path.join(fixturesDir, 'prepend-false.log'),
4851
prepend: false
@@ -52,7 +55,7 @@ describe('winston/transports/daily-rotate-file', function () {
5255
});
5356

5457
it('should have a proper filename when prepend options is true', function () {
55-
var now = moment().format('YYYY-MM-DD');
58+
var now = moment().utc().format('YYYY-MM-DD');
5659
var transport = new DailyRotateFile({
5760
filename: path.join(fixturesDir, 'prepend-true.log'),
5861
prepend: true
@@ -62,7 +65,7 @@ describe('winston/transports/daily-rotate-file', function () {
6265
});
6366

6467
it('should remove leading dot if one is provided with datePattern', function () {
65-
var now = moment().format('YYYYMMDD');
68+
var now = moment().utc().format('YYYYMMDD');
6669
var transport = new DailyRotateFile({
6770
filename: path.join(fixturesDir, 'prepend-false.log'),
6871
prepend: false,
@@ -73,7 +76,7 @@ describe('winston/transports/daily-rotate-file', function () {
7376
});
7477

7578
it('should not add leading dot if one is not provided with datePattern', function () {
76-
var now = moment().format('YYYY-MM-DD');
79+
var now = moment().utc().format('YYYY-MM-DD');
7780
var transport = new DailyRotateFile({
7881
filename: path.join(fixturesDir, 'log'),
7982
datePattern: '-yyyy-MM-dd.log'
@@ -83,7 +86,7 @@ describe('winston/transports/daily-rotate-file', function () {
8386
});
8487

8588
it('should remove leading dot if one is provided with datePattern when prepend option is true', function () {
86-
var now = moment().format('YYYY-MM-DD');
89+
var now = moment().utc().format('YYYY-MM-DD');
8790
var transport = new DailyRotateFile({
8891
filename: path.join(fixturesDir, 'prepend-true.log'),
8992
prepend: true,

0 commit comments

Comments
 (0)