1
1
'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 ;
10
9
11
10
// Need to hijack fs.open/close to make sure that things
12
11
// get closed once they're opened.
@@ -19,7 +18,7 @@ fs._closeSync = fs.closeSync;
19
18
fs . close = close ;
20
19
fs . closeSync = closeSync ;
21
20
22
- var openCount = 0 ;
21
+ let openCount = 0 ;
23
22
24
23
function open ( ) {
25
24
openCount ++ ;
@@ -54,57 +53,49 @@ if (common.isWindows) {
54
53
const file1 = path . join ( common . fixturesDir , 'a.js' ) ;
55
54
const file2 = path . join ( common . fixturesDir , 'a1.js' ) ;
56
55
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 ) ;
60
63
} 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 ) ;
62
82
63
83
if ( common . isWindows ) {
64
- assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_async ) ;
84
+ assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_async ) ;
65
85
} else {
66
- assert . equal ( mode_async , fs . statSync ( file1 ) . mode & 0o777 ) ;
86
+ assert . strictEqual ( mode_async , fs . fstatSync ( fd ) . mode & 0o777 ) ;
67
87
}
68
88
69
- fs . chmodSync ( file1 , mode_sync ) ;
89
+ fs . fchmodSync ( fd , mode_sync ) ;
70
90
if ( common . isWindows ) {
71
- assert . ok ( ( fs . statSync ( file1 ) . mode & 0o777 ) & mode_sync ) ;
91
+ assert . ok ( ( fs . fstatSync ( fd ) . mode & 0o777 ) & mode_sync ) ;
72
92
} else {
73
- assert . equal ( mode_sync , fs . statSync ( file1 ) . mode & 0o777 ) ;
93
+ assert . strictEqual ( mode_sync , fs . fstatSync ( fd ) . mode & 0o777 ) ;
74
94
}
75
- success_count ++ ;
76
- }
77
- } ) ;
78
95
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
+ } ) ) ;
108
99
109
100
// lchmod
110
101
if ( fs . lchmod ) {
@@ -113,26 +104,20 @@ if (fs.lchmod) {
113
104
common . refreshTmpDir ( ) ;
114
105
fs . symlinkSync ( file2 , link ) ;
115
106
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 ) ;
122
109
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
+ } ) ) ;
130
117
}
131
118
132
119
133
120
process . 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 ) ;
137
122
} ) ;
138
123
0 commit comments