@@ -165,32 +165,20 @@ def write_connection_file(
165
165
f .write (json .dumps (cfg , indent = 2 ))
166
166
167
167
if hasattr (stat , "S_ISVTX" ):
168
- # set the sticky bit on the file and its parent directory
169
- # to avoid periodic cleanup
170
- paths = [fname ]
168
+ # set the sticky bit on the parent directory of the file
169
+ # to ensure only owner can remove it
171
170
runtime_dir = os .path .dirname (fname )
172
171
if runtime_dir :
173
- paths .append (runtime_dir )
174
- for path in paths :
175
- permissions = os .stat (path ).st_mode
172
+ permissions = os .stat (runtime_dir ).st_mode
176
173
new_permissions = permissions | stat .S_ISVTX
177
174
if new_permissions != permissions :
178
175
try :
179
- os .chmod (path , new_permissions )
176
+ os .chmod (runtime_dir , new_permissions )
180
177
except OSError as e :
181
- if e .errno == errno .EPERM and path == runtime_dir :
178
+ if e .errno == errno .EPERM :
182
179
# suppress permission errors setting sticky bit on runtime_dir,
183
180
# which we may not own.
184
181
pass
185
- else :
186
- # failed to set sticky bit, probably not a big deal
187
- warnings .warn (
188
- "Failed to set sticky bit on %r: %s"
189
- "\n Probably not a big deal, but runtime files may be cleaned up "
190
- "periodically." % (path , e ),
191
- RuntimeWarning ,
192
- )
193
-
194
182
return fname , cfg
195
183
196
184
0 commit comments