@ -1,12 +1,11 @@
'use strict' ;
var common = require ( '../common' ) ;
var assert = require ( 'assert' ) ;
var path = require ( 'path' ) ;
var fs = require ( 'fs' ) ;
var got_error = false ;
var success_count = 0 ;
var mode_async ;
var mode_sync ;
const common = require ( '../common' ) ;
const assert = require ( 'assert' ) ;
const path = require ( 'path' ) ;
const fs = require ( 'fs' ) ;
let mode_async ;
let mode_sync ;
// Need to hijack fs.open/close to make sure that things
// get closed once they're opened.
@ -19,7 +18,7 @@ fs._closeSync = fs.closeSync;
fs . close = close ;
fs . closeSync = closeSync ;
var openCount = 0 ;
let openCount = 0 ;
function open ( ) {
openCount ++ ;
@ -54,57 +53,49 @@ if (common.isWindows) {
const file1 = path . join ( common . fixturesDir , 'a.js' ) ;
const file2 = path . join ( common . fixturesDir , 'a1.js' ) ;
fs . chmod ( file1 , mode_async . toString ( 8 ) , function ( err ) {
if ( err ) {
got_error = true ;
} else {
fs . chmod ( file1 , mode_async . toString ( 8 ) , common . mustCall ( ( err ) => {
assert . ifError ( err ) ;
console . log ( fs . statSync ( file1 ) . mode ) ;
if ( common . isWindows ) {
assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_async ) ;
} else {
assert . e qual( mode_async , fs . statSync ( file1 ) . mode & 0o777 ) ;
assert . strictE qual( mode_async , fs . statSync ( file1 ) . mode & 0o777 ) ;
}
fs . chmodSync ( file1 , mode_sync ) ;
if ( common . isWindows ) {
assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_sync ) ;
} else {
assert . e qual( mode_sync , fs . statSync ( file1 ) . mode & 0o777 ) ;
assert . strictE qual( mode_sync , fs . statSync ( file1 ) . mode & 0o777 ) ;
}
success_count ++ ;
}
} ) ;
} ) ) ;
fs . open ( file2 , 'a' , common . mustCall ( ( err , fd ) => {
assert . ifError ( err ) ;
fs . fchmod ( fd , mode_async . toString ( 8 ) , common . mustCall ( ( err ) => {
assert . ifError ( err ) ;
fs . open ( file2 , 'a' , function ( err , fd ) {
if ( err ) {
got_error = true ;
console . error ( err . stack ) ;
return ;
}
fs . fchmod ( fd , mode_async . toString ( 8 ) , function ( err ) {
if ( err ) {
got_error = true ;
} else {
console . log ( fs . fstatSync ( fd ) . mode ) ;
if ( common . isWindows ) {
assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_async ) ;
} else {
assert . e qual( mode_async , fs . fstatSync ( fd ) . mode & 0o777 ) ;
assert . strictEqual ( mode_async , fs . fstatSync ( fd ) . mode & 0o777 ) ;
}
fs . fchmodSync ( fd , mode_sync ) ;
if ( common . isWindows ) {
assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_sync ) ;
} else {
assert . e qual( mode_sync , fs . fstatSync ( fd ) . mode & 0o777 ) ;
assert . strictE qual( mode_sync , fs . fstatSync ( fd ) . mode & 0o777 ) ;
}
success_count ++ ;
fs . close ( fd ) ;
}
} ) ;
} ) ;
} ) ) ;
} ) ) ;
// lchmod
if ( fs . lchmod ) {
@ -113,26 +104,20 @@ if (fs.lchmod) {
common . refreshTmpDir ( ) ;
fs . symlinkSync ( file2 , link ) ;
fs . lchmod ( link , mode_async , function ( err ) {
if ( err ) {
got_error = true ;
} else {
fs . lchmod ( link , mode_async , common . mustCall ( ( err ) => {
assert . ifError ( err ) ;
console . log ( fs . lstatSync ( link ) . mode ) ;
assert . e qual( mode_async , fs . lstatSync ( link ) . mode & 0o777 ) ;
assert . strictE qual( mode_async , fs . lstatSync ( link ) . mode & 0o777 ) ;
fs . lchmodSync ( link , mode_sync ) ;
assert . equal ( mode_sync , fs . lstatSync ( link ) . mode & 0o777 ) ;
success_count ++ ;
}
} ) ;
} else {
success_count ++ ;
assert . strictEqual ( mode_sync , fs . lstatSync ( link ) . mode & 0o777 ) ;
} ) ) ;
}
process . on ( 'exit' , function ( ) {
assert . equal ( 3 , success_count ) ;
assert . equal ( 0 , openCount ) ;
assert . equal ( false , got_error ) ;
assert . strictEqual ( 0 , openCount ) ;
} ) ;