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

Introduce module for constants #172

Merged
merged 1 commit into from
Jun 29, 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
7 changes: 7 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
MASK_MODE: parseInt('7777', 8),
DEFAULT_FILE_MODE: parseInt('0666', 8),
DEFAULT_DIR_MODE: parseInt('0777', 8),
};
12 changes: 5 additions & 7 deletions lib/file-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ var assign = require('object-assign');
var isEqual = require('lodash.isequal');
var isValidDate = require('vali-date');

// TODO shared module
var MASK_MODE = parseInt('7777', 8);
var DEFAULT_FILE_MODE = parseInt('0666', 8);
var DEFAULT_DIR_MODE = parseInt('0777', 8);
var constants = require('./constants');

var APPEND_MODE_REGEXP = /a/;

function closeFd(propagatedErr, fd, callback) {
Expand All @@ -32,7 +30,7 @@ function getModeDiff(fsMode, vinylMode) {
var modeDiff = 0;

if (typeof vinylMode === 'number') {
modeDiff = (vinylMode ^ fsMode) & MASK_MODE;
modeDiff = (vinylMode ^ fsMode) & constants.MASK_MODE;
}

return modeDiff;
Expand Down Expand Up @@ -178,7 +176,7 @@ function writeFile(filepath, data, options, callback) {
}

// Default the same as node
var mode = options.mode || DEFAULT_FILE_MODE;
var mode = options.mode || constants.DEFAULT_FILE_MODE;
var flag = options.flag || 'w';
var position = APPEND_MODE_REGEXP.test(flag) ? null : 0;

Expand All @@ -203,7 +201,7 @@ function mkdirp(dirpath, mode, callback) {
mode = undefined;
}

var m = mode || DEFAULT_DIR_MODE;
var m = mode || constants.DEFAULT_DIR_MODE;
var cb = callback || function() {};
dirpath = path.resolve(dirpath);

Expand Down
10 changes: 7 additions & 3 deletions test/dest-modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var expect = require('expect');
var through = require('through2');

var vfs = require('../');
var constants = require('../lib/constants');

function wipeOut() {
this.timeout(20000);
Expand Down Expand Up @@ -331,14 +332,17 @@ describe('.dest() with custom modes', function() {
return;
}


var inputBase = path.join(__dirname, './fixtures');
var inputPath = path.join(__dirname, './fixtures/wow/suchempty');
var expectedBase = path.join(__dirname, './out-fixtures/wow');
var expectedPath = path.join(__dirname, './out-fixtures/wow/suchempty');
// NOTE: Darwin does not set setgid
var expectedDirMode = (isDarwin ? parseInt('777', 8) : parseInt('2777', 8)) & ~process.umask();
var expectedFileMode = parseInt('677', 8) & ~process.umask();
var expectedDirMode = constants.DEFAULT_DIR_MODE;
if (!isDarwin) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom mkdirp is implemented, do we still need this check? Maybe it needs to be improved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to look into that, but haven't had time... But yes, if the mkdirp change does what I hope it does then this should not be needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll merge this and take a look

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for review and merge!

expectedDirMode |= parseInt('2000', 8);
}
expectedDirMode &= ~process.umask();
var expectedFileMode = constants.DEFAULT_FILE_MODE & ~process.umask();

var firstFile = new File({
base: inputBase,
Expand Down