@@ -23,13 +23,14 @@ function wipeOut() {
23
23
} ) ;
24
24
}
25
25
26
- var MASK_MODE = parseInt ( '777 ' , 8 ) ;
26
+ var MASK_MODE = parseInt ( '7777 ' , 8 ) ;
27
27
28
28
function masked ( mode ) {
29
29
return mode & MASK_MODE ;
30
30
}
31
31
32
32
var isWindows = ( os . platform ( ) === 'win32' ) ;
33
+ var isDarwin = ( os . platform ( ) === 'darwin' ) ;
33
34
34
35
describe ( '.dest() with custom modes' , function ( ) {
35
36
beforeEach ( wipeOut ) ;
@@ -70,6 +71,46 @@ describe('.dest() with custom modes', function() {
70
71
stream . end ( ) ;
71
72
} ) ;
72
73
74
+
75
+
76
+ it ( 'should set the sticky bit on the mode of a written stream file if set on the vinyl object' , function ( done ) {
77
+ if ( isWindows ) {
78
+ this . skip ( ) ;
79
+ return ;
80
+ }
81
+
82
+ var inputPath = path . join ( __dirname , './fixtures/test.coffee' ) ;
83
+ var inputBase = path . join ( __dirname , './fixtures/' ) ;
84
+ var expectedPath = path . join ( __dirname , './out-fixtures/test.coffee' ) ;
85
+ var expectedContents = fs . readFileSync ( inputPath ) ;
86
+ var expectedMode = parseInt ( '1655' , 8 ) ;
87
+
88
+ var contentStream = through . obj ( ) ;
89
+ var expectedFile = new File ( {
90
+ base : inputBase ,
91
+ cwd : __dirname ,
92
+ path : inputPath ,
93
+ contents : contentStream ,
94
+ stat : {
95
+ mode : expectedMode ,
96
+ } ,
97
+ } ) ;
98
+
99
+ var onEnd = function ( ) {
100
+ expect ( masked ( fs . lstatSync ( expectedPath ) . mode ) ) . toEqual ( expectedMode ) ;
101
+ done ( ) ;
102
+ } ;
103
+
104
+ var stream = vfs . dest ( './out-fixtures/' , { cwd : __dirname } ) ;
105
+ stream . on ( 'end' , onEnd ) ;
106
+ stream . write ( expectedFile ) ;
107
+ setTimeout ( function ( ) {
108
+ contentStream . write ( expectedContents ) ;
109
+ contentStream . end ( ) ;
110
+ } , 100 ) ;
111
+ stream . end ( ) ;
112
+ } ) ;
113
+
73
114
it ( 'should set the mode of a written stream file if set on the vinyl object' , function ( done ) {
74
115
if ( isWindows ) {
75
116
this . skip ( ) ;
@@ -143,6 +184,41 @@ describe('.dest() with custom modes', function() {
143
184
stream . end ( ) ;
144
185
} ) ;
145
186
187
+ it ( 'should set sticky bit on the mode of a written directory if set on the vinyl object' , function ( done ) {
188
+ if ( isWindows ) {
189
+ this . skip ( ) ;
190
+ return ;
191
+ }
192
+
193
+ var inputPath = path . join ( __dirname , './fixtures/test' ) ;
194
+ var inputBase = path . join ( __dirname , './fixtures/' ) ;
195
+ var expectedPath = path . join ( __dirname , './out-fixtures/test' ) ;
196
+ var expectedMode = parseInt ( '1655' , 8 ) ;
197
+
198
+ var expectedFile = new File ( {
199
+ base : inputBase ,
200
+ cwd : __dirname ,
201
+ path : inputPath ,
202
+ contents : null ,
203
+ stat : {
204
+ isDirectory : function ( ) {
205
+ return true ;
206
+ } ,
207
+ mode : expectedMode ,
208
+ } ,
209
+ } ) ;
210
+
211
+ var onEnd = function ( ) {
212
+ expect ( masked ( fs . lstatSync ( expectedPath ) . mode ) ) . toEqual ( expectedMode ) ;
213
+ done ( ) ;
214
+ } ;
215
+
216
+ var stream = vfs . dest ( './out-fixtures/' , { cwd : __dirname } ) ;
217
+ stream . on ( 'end' , onEnd ) ;
218
+ stream . write ( expectedFile ) ;
219
+ stream . end ( ) ;
220
+ } ) ;
221
+
146
222
it ( 'should write new files with the mode specified in options' , function ( done ) {
147
223
if ( isWindows ) {
148
224
this . skip ( ) ;
@@ -255,11 +331,13 @@ describe('.dest() with custom modes', function() {
255
331
return ;
256
332
}
257
333
334
+
258
335
var inputBase = path . join ( __dirname , './fixtures' ) ;
259
336
var inputPath = path . join ( __dirname , './fixtures/wow/suchempty' ) ;
260
337
var expectedBase = path . join ( __dirname , './out-fixtures/wow' ) ;
261
338
var expectedPath = path . join ( __dirname , './out-fixtures/wow/suchempty' ) ;
262
- var expectedDirMode = parseInt ( '755' , 8 ) ;
339
+ // NOTE: Darwin does not set setgid
340
+ var expectedDirMode = isDarwin ? parseInt ( '755' , 8 ) : parseInt ( '2755' , 8 ) ;
263
341
var expectedFileMode = parseInt ( '655' , 8 ) ;
264
342
265
343
var firstFile = new File ( {
@@ -322,7 +400,7 @@ describe('.dest() with custom modes', function() {
322
400
stream . end ( ) ;
323
401
} ) ;
324
402
325
- it ( 'should see a file with special chmod (setuid/setgid/sticky) as matching ' , function ( done ) {
403
+ it ( 'should see a file with special chmod (setuid/setgid/sticky) as distinct ' , function ( done ) {
326
404
if ( isWindows ) {
327
405
this . skip ( ) ;
328
406
return ;
@@ -349,7 +427,7 @@ describe('.dest() with custom modes', function() {
349
427
} ) ;
350
428
351
429
var onEnd = function ( ) {
352
- expect ( fchmodSpy . calls . length ) . toEqual ( 0 ) ;
430
+ expect ( fchmodSpy . calls . length ) . toEqual ( 1 ) ;
353
431
done ( ) ;
354
432
} ;
355
433
0 commit comments