14
14
#include <sys/stat.h>
15
15
#include <unistd.h>
16
16
17
- int main () {
17
+ void setup () {
18
18
EM_ASM (
19
19
FS .writeFile ('forbidden' , "" ); FS .chmod ('forbidden' , 0 o000 );
20
20
FS .writeFile ('readable' , "" ); FS .chmod ('readable' , 0 o444 );
21
21
FS .writeFile ('writeable' , "" ); FS .chmod ('writeable' , 0 o222 );
22
22
FS .writeFile ('allaccess' , "" ); FS .chmod ('allaccess' , 0 o777 );
23
- FS .writeFile ('fchmodtest' , "" );
24
23
);
24
+ }
25
25
26
- // Empty path checks #9136 fix
27
- char * files [] = {"readable" , "writeable" ,
28
- "allaccess" , "forbidden" , "nonexistent" , "" };
29
- for (int i = 0 ; i < sizeof files / sizeof files [0 ]; i ++ ) {
30
- printf ("F_OK('%s'): %s\n" , files [i ], access (files [i ], F_OK ) < 0 ? strerror (errno ) : "OK" );
31
- printf ("R_OK('%s'): %s\n" , files [i ], access (files [i ], R_OK ) < 0 ? strerror (errno ) : "OK" );
32
- printf ("X_OK('%s'): %s\n" , files [i ], access (files [i ], X_OK ) < 0 ? strerror (errno ) : "OK" );
33
- printf ("W_OK('%s'): %s\n" , files [i ], access (files [i ], W_OK ) < 0 ? strerror (errno ) : "OK" );
34
- printf ("\n" );
35
- }
36
-
37
- EM_ASM ({FS .writeFile ('filetorename' , 'renametest' );});
26
+ void test_rename () {
27
+ EM_ASM ({FS .writeFile ('filetorename' , 'renametest' );});
38
28
39
29
int rename_ret = rename ("filetorename" , "renamedfile" );
40
30
assert (rename_ret == 0 );
@@ -45,7 +35,10 @@ int main() {
45
35
// Same againt with faccessat
46
36
printf ("F_OK('%s'): %d\n" , "filetorename" , faccessat (AT_FDCWD , "filetorename" , F_OK , 0 ));
47
37
printf ("F_OK('%s'): %d\n" , "renamedfile" , faccessat (AT_FDCWD , "renamedfile" , F_OK , 0 ));
38
+ }
48
39
40
+ void test_fchmod () {
41
+ EM_ASM ({FS .writeFile ('fchmodtest' , "" );});
49
42
chmod ("fchmodtest" , S_IRUGO | S_IWUGO );
50
43
struct stat fileStats ;
51
44
stat ("fchmodtest" , & fileStats );
@@ -60,7 +53,9 @@ int main() {
60
53
);
61
54
stat ("fchmodtest" , & fileStats );
62
55
assert ((fileStats .st_mode & 0777 ) == 0777 );
56
+ }
63
57
58
+ void test_lchmod () {
64
59
#if !defined(NODEFS ) && !defined(NODERAWFS )
65
60
// Node (and indeed linux) does not support lchmod
66
61
// so skip this part of the test.
@@ -74,11 +69,14 @@ int main() {
74
69
lstat ("symlinkfile" , & symlinkStats );
75
70
assert ((symlinkStats .st_mode & 0777 ) == 0777 );
76
71
72
+ struct stat fileStats ;
77
73
stat ("writeable" , & fileStats );
78
- mode = fileStats .st_mode & 0777 ;
74
+ int mode = fileStats .st_mode & 0777 ;
79
75
assert (mode == S_IWUGO || mode == (S_IWUGO | S_IXUGO ));
80
76
#endif
77
+ }
81
78
79
+ void test_chmod_errors () {
82
80
EM_ASM (
83
81
var ex ;
84
82
try {
@@ -102,18 +100,26 @@ int main() {
102
100
}
103
101
assert (ex .name == = "ErrnoError" && ex .errno == = 44 /* ENOENT */ );
104
102
);
103
+ }
105
104
105
+ int main () {
106
+ setup ();
106
107
107
- // Restore full permissions on all created files so that python test runner rmtree
108
- // won't have problems on deleting the files. On Windows, calling shutil.rmtree()
109
- // will fail if any of the files are read-only.
110
- EM_ASM (
111
- FS .chmod ('forbidden' , 0777 );
112
- FS .chmod ('readable' , 0777 );
113
- FS .chmod ('writeable' , 0777 );
114
- FS .chmod ('allaccess' , 0777 );
115
- FS .chmod ('fchmodtest' , 0777 );
116
- );
108
+ // Empty path checks #9136 fix
109
+ char * files [] = {"readable" , "writeable" ,
110
+ "allaccess" , "forbidden" , "nonexistent" , "" };
111
+ for (int i = 0 ; i < sizeof files / sizeof files [0 ]; i ++ ) {
112
+ printf ("F_OK('%s'): %s\n" , files [i ], access (files [i ], F_OK ) < 0 ? strerror (errno ) : "OK" );
113
+ printf ("R_OK('%s'): %s\n" , files [i ], access (files [i ], R_OK ) < 0 ? strerror (errno ) : "OK" );
114
+ printf ("X_OK('%s'): %s\n" , files [i ], access (files [i ], X_OK ) < 0 ? strerror (errno ) : "OK" );
115
+ printf ("W_OK('%s'): %s\n" , files [i ], access (files [i ], W_OK ) < 0 ? strerror (errno ) : "OK" );
116
+ printf ("\n" );
117
+ }
118
+
119
+ test_rename ();
120
+ test_fchmod ();
121
+ test_lchmod ();
122
+ test_chmod_errors ();
117
123
118
124
return 0 ;
119
125
}
0 commit comments