Skip to content

Commit f453b51

Browse files
authored
Set sticky bit only on the directory (#711)
* Set sticky bit only on the directory Remove the unnecessary for loop, set the sticky bit only on the directory containing the .json file.
1 parent 8ca558f commit f453b51

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

jupyter_client/connect.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,32 +165,20 @@ def write_connection_file(
165165
f.write(json.dumps(cfg, indent=2))
166166

167167
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
171170
runtime_dir = os.path.dirname(fname)
172171
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
176173
new_permissions = permissions | stat.S_ISVTX
177174
if new_permissions != permissions:
178175
try:
179-
os.chmod(path, new_permissions)
176+
os.chmod(runtime_dir, new_permissions)
180177
except OSError as e:
181-
if e.errno == errno.EPERM and path == runtime_dir:
178+
if e.errno == errno.EPERM:
182179
# suppress permission errors setting sticky bit on runtime_dir,
183180
# which we may not own.
184181
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-
"\nProbably not a big deal, but runtime files may be cleaned up "
190-
"periodically." % (path, e),
191-
RuntimeWarning,
192-
)
193-
194182
return fname, cfg
195183

196184

0 commit comments

Comments
 (0)