Skip to content

Commit aca211c

Browse files
committed
set sticky bit on connection dir
in addition to connection file to avoid cleanup of empty dir during long-idle servers
1 parent 97a0f83 commit aca211c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

jupyter_client/connect.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,21 @@ def write_connection_file(fname=None, shell_port=0, iopub_port=0, stdin_port=0,
137137
f.write(json.dumps(cfg, indent=2))
138138

139139
if hasattr(stat, 'S_ISVTX'):
140-
# set the sticky bit to avoid periodic cleanup
141-
permissions = os.stat(fname).st_mode
142-
new_permissions = permissions | stat.S_ISVTX
143-
if new_permissions != permissions:
144-
try:
145-
os.chmod(fname, permissions)
146-
except OSError as e:
147-
# failed to set sticky bit,
148-
# probably not a big deal
149-
warnings.warn(
150-
"Failed to set sticky bit on %r: %s" % (fname, e),
151-
RuntimeWarning,
152-
)
140+
# set the sticky bit on the file and its parent directory
141+
# to avoid periodic cleanup
142+
for path in [fname, os.path.dirname(fname)]:
143+
permissions = os.stat(path).st_mode
144+
new_permissions = permissions | stat.S_ISVTX
145+
if new_permissions != permissions:
146+
try:
147+
os.chmod(path, permissions)
148+
except OSError as e:
149+
# failed to set sticky bit,
150+
# probably not a big deal
151+
warnings.warn(
152+
"Failed to set sticky bit on %r: %s" % (path, e),
153+
RuntimeWarning,
154+
)
153155

154156
return fname, cfg
155157

0 commit comments

Comments
 (0)