@@ -1064,9 +1064,19 @@ abstract static class ChmodNode extends PythonBuiltinNode {
1064
1064
1065
1065
@ Specialization
1066
1066
Object chmod (String path , int mode , @ SuppressWarnings ("unused" ) PNone dir_fd , @ SuppressWarnings ("unused" ) PNone follow_symlinks ) {
1067
+ return chmod (path , mode , dir_fd , true );
1068
+ }
1069
+
1070
+ @ Specialization
1071
+ Object chmod (String path , int mode , @ SuppressWarnings ("unused" ) PNone dir_fd , boolean follow_symlinks ) {
1067
1072
Set <PosixFilePermission > permissions = modeToPermissions (mode );
1068
1073
try {
1069
1074
TruffleFile truffleFile = getContext ().getEnv ().getTruffleFile (path );
1075
+ if (!follow_symlinks ) {
1076
+ truffleFile = truffleFile .getCanonicalFile (LinkOption .NOFOLLOW_LINKS );
1077
+ } else {
1078
+ truffleFile = truffleFile .getCanonicalFile ();
1079
+ }
1070
1080
truffleFile .setPosixPermissions (permissions );
1071
1081
} catch (IOException e ) {
1072
1082
gotException .enter ();
@@ -1082,12 +1092,6 @@ private static Set<PosixFilePermission> modeToPermissions(int mode) {
1082
1092
permissions .addAll (Arrays .asList (ownerBitsToPermission [mode >> 6 & 7 ]));
1083
1093
return permissions ;
1084
1094
}
1085
-
1086
- @ SuppressWarnings ("unused" )
1087
- @ Fallback
1088
- Object chmod (Object path , Object mode , Object dir_fd , Object follow_symlinks ) {
1089
- throw raise (NotImplementedError , "chmod" );
1090
- }
1091
1095
}
1092
1096
1093
1097
@ Builtin (name = "utime" , minNumOfPositionalArgs = 1 , keywordArguments = {"times" , "ns" , "dir_fd" , "follow_symlinks" })
0 commit comments