Skip to content

Commit

Permalink
enh: mode option now also applies do directories
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierpriour committed Nov 30, 2014
1 parent 252d8ab commit 4313897
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
15 changes: 15 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ module.exports = function(grunt) {
src: ['test/fixtures/test2.js'],
dest: 'tmp/mode.js'
},

modeDir: {
options: {
mode: '0777'
},
files: [
{
expand: true,
cwd: 'test/fixtures/',
src: ['time_folder/**'],
dest: 'tmp/copy_test_modeDir/'}
]
},

process: {
options: {
noProcess: ['test/fixtures/beep.wav'],
Expand All @@ -81,6 +95,7 @@ module.exports = function(grunt) {
},
files: [{ expand: true, cwd: 'test/fixtures', src: ['test2.js', 'beep.wav'], dest: 'tmp/process/' }]
},

timestamp: {
options: {
process: function (content, srcpath) {
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# grunt-contrib-copy v0.7.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-copy.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-copy)
# grunt-contrib-copy v0.7.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-copy.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-copy)

> Copy files and folders.
Expand Down Expand Up @@ -50,13 +50,15 @@ Default: `grunt.file.defaultEncoding`
The file encoding to copy files with.

#### mode
Type: `Boolean` or `Number`
Type: `Boolean` or `String`
Default: `false`

Whether to copy or set the existing file permissions. Set to `true` to copy the existing file permissions. Or set to the mode, i.e.: `0644`, that copied files will be set to.
Whether to copy or set the destination file and directory permissions.
Set to `true` to copy the existing file and directories permissions.
Or set to the mode, i.e.: `0644`, that copied files will be set to.

#### timestamp
Type: `Boolean`
Type: `Boolean`
Default: `false`

Whether to preserve the timestamp attributes(`atime` and `mtime`) when copying files. Set to `true` to preserve files timestamp. But timestamp will *not* be preserved when the file contents or name are changed during copying.
Expand Down Expand Up @@ -237,4 +239,4 @@ Aborted due to warnings.

Task submitted by [Chris Talkington](http://christalkington.com/)

*This file was generated on Wed Oct 15 2014 09:29:35.*
*This file was generated on Thu Nov 27 2014 00:17:14.*
6 changes: 4 additions & 2 deletions docs/copy-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ Default: `grunt.file.defaultEncoding`
The file encoding to copy files with.

## mode
Type: `Boolean` or `Number`
Type: `Boolean` or `String`
Default: `false`

Whether to copy or set the existing file permissions. Set to `true` to copy the existing file permissions. Or set to the mode, i.e.: `0644`, that copied files will be set to.
Whether to copy or set the destination file and directory permissions.
Set to `true` to copy the existing file and directories permissions.
Or set to the mode, i.e.: `0644`, that copied files will be set to.

## timestamp
Type: `Boolean`
Expand Down
3 changes: 3 additions & 0 deletions tasks/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ module.exports = function(grunt) {
if (grunt.file.isDir(src)) {
grunt.verbose.writeln('Creating ' + chalk.cyan(dest));
grunt.file.mkdir(dest);
if (options.mode !== false) {
fs.chmodSync(dest, (options.mode === true) ? fs.lstatSync(src).mode : options.mode);
}

if (options.timestamp) {
dirs[dest] = src;
Expand Down
9 changes: 9 additions & 0 deletions test/copy_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ exports.copy = {

test.done();
},

modeDir: function(test) {
'use strict';
test.expect(2);
test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder').mode.toString(8).slice(-3), '777');
test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder/sub_folder').mode.toString(8).slice(-3), '777');
test.done();
},

process: function(test) {
'use strict';

Expand Down

0 comments on commit 4313897

Please sign in to comment.