Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Consider the greater of ctime & mtime when comparing since option #340

Merged
merged 4 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/src/prepare.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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