Skip to content

Commit

Permalink
Updated style & made utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
piranna committed Oct 14, 2015
1 parent d55fd11 commit def6815
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
15 changes: 15 additions & 0 deletions lib/dest/writeContents/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var fs = require('graceful-fs');

function utimes(writePath, stat, cb) {
if (stat.mtime) {
stat.atime = stat.atime || new Date();

return fs.utimes(writePath, stat.atime, stat.mtime, cb);
}

cb();
}

exports.utimes = utimes;
14 changes: 4 additions & 10 deletions lib/dest/writeContents/writeBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var fs = require('graceful-fs');

var utimes = require('./utils').utimes;

function writeBuffer(writePath, file, cb) {
var stat = file.stat;

Expand All @@ -12,19 +14,11 @@ function writeBuffer(writePath, file, cb) {

fs.writeFile(writePath, file.contents, opt, function(error)
{
if(error)
{
if (error) {
return cb(error);
}

if(stat.mtime)
{
stat.atime = stat.atime || new Date();

return fs.utimes(writePath, stat.atime, stat.mtime, cb);
}

cb();
utimes(writePath, stat, cb);
});
}

Expand Down
16 changes: 5 additions & 11 deletions lib/dest/writeContents/writeStream.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

var streamFile = require('../../src/getContents/streamFile');
var fs = require('graceful-fs');

var streamFile = require('../../src/getContents/streamFile');
var utimes = require('./utils').utimes;

function writeStream(writePath, file, cb) {
var stat = file.stat;

Expand All @@ -22,19 +24,11 @@ function writeStream(writePath, file, cb) {
function success() {
streamFile(file, {}, function(error)
{
if(error)
{
if (error) {
return complete(error);
}

if(stat.mtime)
{
stat.atime = stat.atime || new Date();

return fs.utimes(writePath, stat.atime, stat.mtime, complete);
}

complete();
utimes(writePath, stat, complete);
});
}

Expand Down

0 comments on commit def6815

Please sign in to comment.