Skip to content

Commit

Permalink
Updated lastModifiedDate when 'write' or 'append' methods called
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 14, 2017
1 parent 36442c0 commit d5a5f9e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
20 changes: 18 additions & 2 deletions lib/resource/physical/PhysicalFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,26 @@ var PhysicalFile = (function (_super) {
});
};
PhysicalFile.prototype.append = function (data, callback) {
fs.appendFile(this.realPath, data, callback);
var _this = this;
fs.appendFile(this.realPath, data, function (e) {
if (e)
callback(e);
else {
_this.updateLastModified();
callback(null);
}
});
};
PhysicalFile.prototype.write = function (data, callback) {
fs.writeFile(this.realPath, data, callback);
var _this = this;
fs.writeFile(this.realPath, data, function (e) {
if (e)
callback(e);
else {
_this.updateLastModified();
callback(null);
}
});
};
PhysicalFile.prototype.read = function (callback) {
fs.readFile(this.realPath, callback);
Expand Down
2 changes: 2 additions & 0 deletions lib/resource/virtual/VirtualFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ var VirtualFile = (function (_super) {
for (var i = 0; i < data.length; ++i)
newContent[i + this.content.length] = data[i];
this.content = newContent;
this.updateLastModified();
callback(null);
};
VirtualFile.prototype.write = function (data, callback) {
this.content = data;
this.updateLastModified();
callback(null);
};
VirtualFile.prototype.read = function (callback) {
Expand Down
20 changes: 18 additions & 2 deletions src/resource/physical/PhysicalFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,27 @@ export class PhysicalFile extends PhysicalResource
// ****************************** Content ****************************** //
append(data : Int8Array, callback : SimpleCallback)
{
fs.appendFile(this.realPath, data, callback);
fs.appendFile(this.realPath, data, (e) => {
if(e)
callback(e);
else
{
this.updateLastModified();
callback(null);
}
});
}
write(data : Int8Array, callback : SimpleCallback)
{
fs.writeFile(this.realPath, data, callback);
fs.writeFile(this.realPath, data, (e) => {
if(e)
callback(e);
else
{
this.updateLastModified();
callback(null);
}
});
}
read(callback : ReturnCallback<Int8Array>)
{
Expand Down
2 changes: 2 additions & 0 deletions src/resource/virtual/VirtualFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export class VirtualFile extends VirtualResource
newContent[i + this.content.length] = data[i];

this.content = newContent;
this.updateLastModified();
callback(null);
}
write(data : Int8Array, callback : SimpleCallback)
{
this.content = data;
this.updateLastModified();
callback(null);
}
read(callback : ReturnCallback<Int8Array>)
Expand Down

0 comments on commit d5a5f9e

Please sign in to comment.