@@ -1064,9 +1064,19 @@ abstract static class ChmodNode extends PythonBuiltinNode {
10641064
10651065 @ Specialization
10661066 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 ) {
10671072 Set <PosixFilePermission > permissions = modeToPermissions (mode );
10681073 try {
10691074 TruffleFile truffleFile = getContext ().getEnv ().getTruffleFile (path );
1075+ if (!follow_symlinks ) {
1076+ truffleFile = truffleFile .getCanonicalFile (LinkOption .NOFOLLOW_LINKS );
1077+ } else {
1078+ truffleFile = truffleFile .getCanonicalFile ();
1079+ }
10701080 truffleFile .setPosixPermissions (permissions );
10711081 } catch (IOException e ) {
10721082 gotException .enter ();
@@ -1082,12 +1092,6 @@ private static Set<PosixFilePermission> modeToPermissions(int mode) {
10821092 permissions .addAll (Arrays .asList (ownerBitsToPermission [mode >> 6 & 7 ]));
10831093 return permissions ;
10841094 }
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- }
10911095 }
10921096
10931097 @ Builtin (name = "utime" , minNumOfPositionalArgs = 1 , keywordArguments = {"times" , "ns" , "dir_fd" , "follow_symlinks" })
0 commit comments