Skip to content

Commit

Permalink
feat!: Consider the greater of ctime & mtime when comparing since opt…
Browse files Browse the repository at this point in the history
…ion (#340)
  • Loading branch information
phated committed Jun 11, 2023
1 parent 061d1b3 commit 9f907ba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/src/prepare.js
Expand Up @@ -6,9 +6,11 @@ function prepareRead(optResolver) {
function normalize(file, callback) {
var since = optResolver.resolve('since', file);

// Skip this file if since option is set and current file is too old
if (file.stat && file.stat.mtime <= since) {
return callback();
if (file.stat) {
// Skip this file if since option is set and current file is too old
if (Math.max(file.stat.mtime, file.stat.ctime) <= since) {
return callback();
}
}

return callback(null, file);
Expand Down
36 changes: 36 additions & 0 deletions test/src.js
Expand Up @@ -9,12 +9,15 @@ var sinon = require('sinon');

var vfs = require('../');

var cleanup = require('./utils/cleanup');
var testStreams = require('./utils/test-streams');
var testConstants = require('./utils/test-constants');
var describeStreams = require('./utils/suite');

var inputBase = testConstants.inputBase;
var inputPath = testConstants.inputPath;
var outputBase = testConstants.outputBase;
var outputPath = testConstants.outputPath;
var inputDirpath = testConstants.inputDirpath;
var bomInputPath = testConstants.bomInputPath;
var beBomInputPath = testConstants.beBomInputPath;
Expand All @@ -27,6 +30,8 @@ var encodedContents = testConstants.encodedContents;
var bomContents = testConstants.bomContents;
var contents = testConstants.contents;

var clean = cleanup(outputBase);

describeStreams('.src()', function (stream) {
var from = stream.Readable.from;
var pipeline = stream.pipeline;
Expand All @@ -35,6 +40,9 @@ describeStreams('.src()', function (stream) {
var concatArray = streamUtils.concatArray;
var compareContents = streamUtils.compareContents;

beforeEach(clean);
afterEach(clean);

it('throws on invalid glob (empty)', function (done) {
var stream;
try {
Expand Down Expand Up @@ -687,6 +695,34 @@ describeStreams('.src()', function (stream) {
);
});

it('streams a file with ctime greater than mtime', function (done) {
fs.mkdirSync(outputBase);
fs.copyFileSync(inputPath, outputPath);

var renamedPath = path.join(outputBase, 'foo.txt');

setTimeout(function () {
// rename changes ctime but not mtime
fs.renameSync(outputPath, renamedPath);

var stat = fs.statSync(renamedPath);

expect(+stat.ctime).toBeGreaterThan(+stat.mtime);

var lastMtime = new Date(+stat.mtime);

function assert(files) {
expect(files.length).toEqual(1);
expect(files[0].path).toEqual(renamedPath);
}

pipeline(
[vfs.src(renamedPath, { since: lastMtime }), concatArray(assert)],
done
);
}, 250);
});

it('streams a file with streaming contents', function (done) {
var expectedContent = fs.readFileSync(inputPath);

Expand Down

0 comments on commit 9f907ba

Please sign in to comment.