Skip to content

Commit

Permalink
Preserve file mode on actions.template, fixes #464
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Jan 16, 2014
1 parent f58c791 commit 63d8abf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/actions/actions.js
Expand Up @@ -203,18 +203,24 @@ actions.read = function read(filepath, encoding) {
* @param {String} content
*/

actions.write = function write(filepath, content) {
actions.write = function write(filepath, content, fileMode) {
this.checkForCollision(filepath, content, function (err, config) {
if (err) {
config.callback(err);
return this.emit('error', err);
}

var fileOptions = {};

if (fileMode) {
fileOptions.mode = fileMode;
}

// create or force means file write, identical or skip prevent the
// actual write
if (/force|create/.test(config.status)) {
mkdirp.sync(path.dirname(filepath));
fs.writeFileSync(filepath, content);
fs.writeFileSync(filepath, content, fileOptions);
}

config.callback();
Expand Down Expand Up @@ -280,10 +286,16 @@ actions.template = function template(source, destination, data, options) {
data = data || this;
destination = destination || source;

if (!this.isPathAbsolute(source)) {
source = path.join(this.sourceRoot(), source);
}

var body = this.read(source, 'utf8');
var fileMode = fs.statSync(source).mode;

body = this.engine(body, data, options);

this.write(destination, body);
this.write(destination, body, fileMode);
return this;
};

Expand Down

0 comments on commit 63d8abf

Please sign in to comment.