umask_sync.js 866 B

12345678910111213141516171819202122232425262728293031
  1. var mkdirp = require('../');
  2. var path = require('path');
  3. var fs = require('fs');
  4. var exists = fs.exists || path.exists;
  5. var test = require('tap').test;
  6. test('umask sync modes', function (t) {
  7. t.plan(4);
  8. var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  9. var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  10. var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  11. var file = '/tmp/' + [x,y,z].join('/');
  12. try {
  13. mkdirp.sync(file);
  14. } catch (err) {
  15. t.fail(err);
  16. return t.end();
  17. }
  18. exists(file, function (ex) {
  19. t.ok(ex, 'file created');
  20. fs.stat(file, function (err, stat) {
  21. t.ifError(err);
  22. t.equal(stat.mode & 0777, (0777 & (~process.umask())));
  23. t.ok(stat.isDirectory(), 'target not a directory');
  24. });
  25. });
  26. });