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

Revert "Set atime, mtime and ctime from contents accessors" #78

Merged
merged 1 commit into from
Jan 18, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,11 @@ function File(file) {
this.cwd = file.cwd || process.cwd();
this.base = file.base || this.cwd;

// Contents = stream, buffer, or null if not read
this.contents = file.contents || null;

// Stat = files stats object
this.stat = file.stat || null;

// Make sure times are proper Date objects
if (this.stat) {
if (typeof this.stat.atime === 'number') {
this.stat.atime = new Date(this.stat.atime);
}
if (typeof this.stat.mtime === 'number') {
this.stat.mtime = new Date(this.stat.mtime);
}
if (typeof this.stat.ctime === 'number') {
this.stat.ctime = new Date(this.stat.ctime);
}
}
// Contents = stream, buffer, or null if not read
this.contents = file.contents || null;

this._isVinyl = true;
}
Expand Down Expand Up @@ -162,24 +149,12 @@ File.isVinyl = function(file) {
// Or stuff with extra logic
Object.defineProperty(File.prototype, 'contents', {
get: function() {
if (this.stat && this.stat.atime) {
this.stat.atime.setTime(Date.now());
}
return this._contents;
},
set: function(val) {
if (!isBuffer(val) && !isStream(val) && !isNull(val)) {
throw new Error('File.contents can only be a Buffer, a Stream, or null.');
}
if (this.stat) {
var now = Date.now();
if (this.stat.mtime) {
this.stat.mtime.setTime(now);
}
if (this.stat.ctime) {
this.stat.ctime.setTime(now);
}
}
this._contents = val;
},
});
Expand Down
41 changes: 0 additions & 41 deletions test/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,47 +651,6 @@ describe('File', function() {
done();
}
});

it('should coerce integer stat.xtime to proper Date objects', function(done) {
var now = Date.now();
var file = new File({
stat: {
atime: now,
mtime: now,
ctime: now,
},
});
(file.stat.atime instanceof Date).should.equal(true);
(file.stat.mtime instanceof Date).should.equal(true);
(file.stat.ctime instanceof Date).should.equal(true);
done();
});

it('should update atime when reading contents', function(done) {
var earlier = Date.now() - 1000;
var file = new File({
stat: {
atime: new Date(earlier),
},
});
var contents = file.contents;
file.stat.atime.getTime().should.be.above(earlier);
done();
});

it('should update mtime and ctime when writing contents', function(done) {
var earlier = Date.now() - 1000;
var file = new File({
stat: {
mtime: new Date(earlier),
ctime: new Date(earlier),
},
});
file.contents = new Buffer('test');
file.stat.mtime.getTime().should.be.above(earlier);
file.stat.ctime.getTime().should.be.above(earlier);
done();
});
});

describe('relative get/set', function() {
Expand Down