Skip to content

Commit

Permalink
Update: Introduce module for constants (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkemperman authored and phated committed Nov 30, 2017
1 parent 4857cad commit 992c3e5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
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) {
expectedDirMode |= parseInt('2000', 8);
}
expectedDirMode &= ~process.umask();
var expectedFileMode = constants.DEFAULT_FILE_MODE & ~process.umask();

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

0 comments on commit 992c3e5

Please sign in to comment.