11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
4- var path = require ( 'path' ) ;
5- var fs = require ( 'fs' ) ;
6- var got_error = false ;
7- var success_count = 0 ;
8- var mode_async ;
9- var mode_sync ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const path = require ( 'path' ) ;
5+ const fs = require ( 'fs' ) ;
6+
7+ let mode_async ;
8+ let mode_sync ;
109
1110// Need to hijack fs.open/close to make sure that things
1211// get closed once they're opened.
@@ -19,7 +18,7 @@ fs._closeSync = fs.closeSync;
1918fs . close = close ;
2019fs . closeSync = closeSync ;
2120
22- var openCount = 0 ;
21+ let openCount = 0 ;
2322
2423function open ( ) {
2524 openCount ++ ;
@@ -54,57 +53,49 @@ if (common.isWindows) {
5453const file1 = path . join ( common . fixturesDir , 'a.js' ) ;
5554const file2 = path . join ( common . fixturesDir , 'a1.js' ) ;
5655
57- fs . chmod ( file1 , mode_async . toString ( 8 ) , function ( err ) {
58- if ( err ) {
59- got_error = true ;
56+ fs . chmod ( file1 , mode_async . toString ( 8 ) , common . mustCall ( ( err ) => {
57+ assert . ifError ( err ) ;
58+
59+ console . log ( fs . statSync ( file1 ) . mode ) ;
60+
61+ if ( common . isWindows ) {
62+ assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_async ) ;
6063 } else {
61- console . log ( fs . statSync ( file1 ) . mode ) ;
64+ assert . strictEqual ( mode_async , fs . statSync ( file1 ) . mode & 0o777 ) ;
65+ }
66+
67+ fs . chmodSync ( file1 , mode_sync ) ;
68+ if ( common . isWindows ) {
69+ assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_sync ) ;
70+ } else {
71+ assert . strictEqual ( mode_sync , fs . statSync ( file1 ) . mode & 0o777 ) ;
72+ }
73+ } ) ) ;
74+
75+ fs . open ( file2 , 'a' , common . mustCall ( ( err , fd ) => {
76+ assert . ifError ( err ) ;
77+
78+ fs . fchmod ( fd , mode_async . toString ( 8 ) , common . mustCall ( ( err ) => {
79+ assert . ifError ( err ) ;
80+
81+ console . log ( fs . fstatSync ( fd ) . mode ) ;
6282
6383 if ( common . isWindows ) {
64- assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_async ) ;
84+ assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_async ) ;
6585 } else {
66- assert . equal ( mode_async , fs . statSync ( file1 ) . mode & 0o777 ) ;
86+ assert . strictEqual ( mode_async , fs . fstatSync ( fd ) . mode & 0o777 ) ;
6787 }
6888
69- fs . chmodSync ( file1 , mode_sync ) ;
89+ fs . fchmodSync ( fd , mode_sync ) ;
7090 if ( common . isWindows ) {
71- assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_sync ) ;
91+ assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_sync ) ;
7292 } else {
73- assert . equal ( mode_sync , fs . statSync ( file1 ) . mode & 0o777 ) ;
93+ assert . strictEqual ( mode_sync , fs . fstatSync ( fd ) . mode & 0o777 ) ;
7494 }
75- success_count ++ ;
76- }
77- } ) ;
7895
79- fs . open ( file2 , 'a' , function ( err , fd ) {
80- if ( err ) {
81- got_error = true ;
82- console . error ( err . stack ) ;
83- return ;
84- }
85- fs . fchmod ( fd , mode_async . toString ( 8 ) , function ( err ) {
86- if ( err ) {
87- got_error = true ;
88- } else {
89- console . log ( fs . fstatSync ( fd ) . mode ) ;
90-
91- if ( common . isWindows ) {
92- assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_async ) ;
93- } else {
94- assert . equal ( mode_async , fs . fstatSync ( fd ) . mode & 0o777 ) ;
95- }
96-
97- fs . fchmodSync ( fd , mode_sync ) ;
98- if ( common . isWindows ) {
99- assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_sync ) ;
100- } else {
101- assert . equal ( mode_sync , fs . fstatSync ( fd ) . mode & 0o777 ) ;
102- }
103- success_count ++ ;
104- fs . close ( fd ) ;
105- }
106- } ) ;
107- } ) ;
96+ fs . close ( fd ) ;
97+ } ) ) ;
98+ } ) ) ;
10899
109100// lchmod
110101if ( fs . lchmod ) {
@@ -113,26 +104,20 @@ if (fs.lchmod) {
113104 common . refreshTmpDir ( ) ;
114105 fs . symlinkSync ( file2 , link ) ;
115106
116- fs . lchmod ( link , mode_async , function ( err ) {
117- if ( err ) {
118- got_error = true ;
119- } else {
120- console . log ( fs . lstatSync ( link ) . mode ) ;
121- assert . equal ( mode_async , fs . lstatSync ( link ) . mode & 0o777 ) ;
107+ fs . lchmod ( link , mode_async , common . mustCall ( ( err ) => {
108+ assert . ifError ( err ) ;
122109
123- fs . lchmodSync ( link , mode_sync ) ;
124- assert . equal ( mode_sync , fs . lstatSync ( link ) . mode & 0o777 ) ;
125- success_count ++ ;
126- }
127- } ) ;
128- } else {
129- success_count ++ ;
110+ console . log ( fs . lstatSync ( link ) . mode ) ;
111+ assert . strictEqual ( mode_async , fs . lstatSync ( link ) . mode & 0o777 ) ;
112+
113+ fs . lchmodSync ( link , mode_sync ) ;
114+ assert . strictEqual ( mode_sync , fs . lstatSync ( link ) . mode & 0o777 ) ;
115+
116+ } ) ) ;
130117}
131118
132119
133120process . on ( 'exit' , function ( ) {
134- assert . equal ( 3 , success_count ) ;
135- assert . equal ( 0 , openCount ) ;
136- assert . equal ( false , got_error ) ;
121+ assert . strictEqual ( 0 , openCount ) ;
137122} ) ;
138123
0 commit comments