24
24
25
25
'use strict' ;
26
26
27
- const constants = process . binding ( 'constants' ) . fs ;
28
- const { S_IFIFO , S_IFLNK , S_IFMT , S_IFREG , S_IFSOCK } = constants ;
27
+ const { fs : constants } = process . binding ( 'constants' ) ;
28
+ const {
29
+ S_IFIFO ,
30
+ S_IFLNK ,
31
+ S_IFMT ,
32
+ S_IFREG ,
33
+ S_IFSOCK ,
34
+ F_OK ,
35
+ R_OK ,
36
+ W_OK ,
37
+ X_OK ,
38
+ O_WRONLY ,
39
+ O_SYMLINK ,
40
+ UV_FS_COPYFILE_EXCL ,
41
+ UV_FS_COPYFILE_FICLONE ,
42
+ UV_FS_COPYFILE_FICLONE_FORCE
43
+ } = constants ;
29
44
const util = require ( 'util' ) ;
30
45
const pathModule = require ( 'path' ) ;
31
46
const { isUint8Array } = require ( 'internal/util/types' ) ;
32
47
const { createPromise, promiseResolve } = process . binding ( 'util' ) ;
33
48
34
49
const binding = process . binding ( 'fs' ) ;
35
50
const fs = exports ;
36
- const { Buffer } = require ( 'buffer' ) ;
51
+ const { Buffer, kMaxLength } = require ( 'buffer' ) ;
37
52
const errors = require ( 'internal/errors' ) ;
38
53
const {
39
54
ERR_FS_FILE_TOO_LARGE ,
@@ -58,6 +73,7 @@ const {
58
73
preprocessSymlinkDestination,
59
74
Stats,
60
75
getStatsFromBinding,
76
+ realpathCacheKey,
61
77
stringToFlags,
62
78
stringToSymlinkType,
63
79
toUnixTimestamp,
@@ -103,7 +119,6 @@ function lazyAssert() {
103
119
}
104
120
105
121
const kMinPoolSpace = 128 ;
106
- const { kMaxLength } = require ( 'buffer' ) ;
107
122
108
123
const isWindows = process . platform === 'win32' ;
109
124
@@ -179,16 +194,16 @@ function isFileType(stats, fileType) {
179
194
180
195
// Don't allow mode to accidentally be overwritten.
181
196
Object . defineProperties ( fs , {
182
- F_OK : { enumerable : true , value : constants . F_OK || 0 } ,
183
- R_OK : { enumerable : true , value : constants . R_OK || 0 } ,
184
- W_OK : { enumerable : true , value : constants . W_OK || 0 } ,
185
- X_OK : { enumerable : true , value : constants . X_OK || 0 } ,
197
+ F_OK : { enumerable : true , value : F_OK || 0 } ,
198
+ R_OK : { enumerable : true , value : R_OK || 0 } ,
199
+ W_OK : { enumerable : true , value : W_OK || 0 } ,
200
+ X_OK : { enumerable : true , value : X_OK || 0 } ,
186
201
} ) ;
187
202
188
203
fs . access = function ( path , mode , callback ) {
189
204
if ( typeof mode === 'function' ) {
190
205
callback = mode ;
191
- mode = fs . F_OK ;
206
+ mode = F_OK ;
192
207
}
193
208
194
209
path = getPathFromURL ( path ) ;
@@ -205,7 +220,7 @@ fs.accessSync = function(path, mode) {
205
220
validatePath ( path ) ;
206
221
207
222
if ( mode === undefined )
208
- mode = fs . F_OK ;
223
+ mode = F_OK ;
209
224
else
210
225
mode = mode | 0 ;
211
226
@@ -222,7 +237,7 @@ fs.exists = function(path, callback) {
222
237
}
223
238
224
239
try {
225
- fs . access ( path , fs . FS_OK , suppressedCallback ) ;
240
+ fs . access ( path , F_OK , suppressedCallback ) ;
226
241
} catch ( err ) {
227
242
return callback ( false ) ;
228
243
}
@@ -244,7 +259,7 @@ Object.defineProperty(fs.exists, internalUtil.promisify.custom, {
244
259
// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
245
260
fs . existsSync = function ( path ) {
246
261
try {
247
- fs . accessSync ( path , fs . FS_OK ) ;
262
+ fs . accessSync ( path , F_OK ) ;
248
263
return true ;
249
264
} catch ( e ) {
250
265
return false ;
@@ -1054,10 +1069,10 @@ fs.fchmodSync = function(fd, mode) {
1054
1069
handleErrorFromBinding ( ctx ) ;
1055
1070
} ;
1056
1071
1057
- if ( constants . O_SYMLINK !== undefined ) {
1072
+ if ( O_SYMLINK !== undefined ) {
1058
1073
fs . lchmod = function ( path , mode , callback ) {
1059
1074
callback = maybeCallback ( callback ) ;
1060
- fs . open ( path , constants . O_WRONLY | constants . O_SYMLINK , function ( err , fd ) {
1075
+ fs . open ( path , O_WRONLY | O_SYMLINK , function ( err , fd ) {
1061
1076
if ( err ) {
1062
1077
callback ( err ) ;
1063
1078
return ;
@@ -1073,7 +1088,7 @@ if (constants.O_SYMLINK !== undefined) {
1073
1088
} ;
1074
1089
1075
1090
fs . lchmodSync = function ( path , mode ) {
1076
- const fd = fs . openSync ( path , constants . O_WRONLY | constants . O_SYMLINK ) ;
1091
+ const fd = fs . openSync ( path , O_WRONLY | O_SYMLINK ) ;
1077
1092
1078
1093
// Prefer to return the chmod error, if one occurs,
1079
1094
// but still try to close, and report closing errors if they occur.
@@ -1110,10 +1125,10 @@ fs.chmodSync = function(path, mode) {
1110
1125
handleErrorFromBinding ( ctx ) ;
1111
1126
} ;
1112
1127
1113
- if ( constants . O_SYMLINK !== undefined ) {
1128
+ if ( O_SYMLINK !== undefined ) {
1114
1129
fs . lchown = function ( path , uid , gid , callback ) {
1115
1130
callback = maybeCallback ( callback ) ;
1116
- fs . open ( path , constants . O_WRONLY | constants . O_SYMLINK , function ( err , fd ) {
1131
+ fs . open ( path , O_WRONLY | O_SYMLINK , function ( err , fd ) {
1117
1132
if ( err ) {
1118
1133
callback ( err ) ;
1119
1134
return ;
@@ -1129,7 +1144,7 @@ if (constants.O_SYMLINK !== undefined) {
1129
1144
} ;
1130
1145
1131
1146
fs . lchownSync = function ( path , uid , gid ) {
1132
- const fd = fs . openSync ( path , constants . O_WRONLY | constants . O_SYMLINK ) ;
1147
+ const fd = fs . openSync ( path , O_WRONLY | O_SYMLINK ) ;
1133
1148
let ret ;
1134
1149
try {
1135
1150
ret = fs . fchownSync ( fd , uid , gid ) ;
@@ -1631,7 +1646,7 @@ fs.realpathSync = function realpathSync(p, options) {
1631
1646
validatePath ( p ) ;
1632
1647
p = pathModule . resolve ( p ) ;
1633
1648
1634
- const cache = options [ internalFS . realpathCacheKey ] ;
1649
+ const cache = options [ realpathCacheKey ] ;
1635
1650
const maybeCachedResult = cache && cache . get ( p ) ;
1636
1651
if ( maybeCachedResult ) {
1637
1652
return maybeCachedResult ;
@@ -1936,14 +1951,14 @@ fs.mkdtempSync = function(prefix, options) {
1936
1951
1937
1952
// Define copyFile() flags.
1938
1953
Object . defineProperties ( fs . constants , {
1939
- COPYFILE_EXCL : { enumerable : true , value : constants . UV_FS_COPYFILE_EXCL } ,
1954
+ COPYFILE_EXCL : { enumerable : true , value : UV_FS_COPYFILE_EXCL } ,
1940
1955
COPYFILE_FICLONE : {
1941
1956
enumerable : true ,
1942
- value : constants . UV_FS_COPYFILE_FICLONE
1957
+ value : UV_FS_COPYFILE_FICLONE
1943
1958
} ,
1944
1959
COPYFILE_FICLONE_FORCE : {
1945
1960
enumerable : true ,
1946
- value : constants . UV_FS_COPYFILE_FICLONE_FORCE
1961
+ value : UV_FS_COPYFILE_FICLONE_FORCE
1947
1962
}
1948
1963
} ) ;
1949
1964
0 commit comments