Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set sticky bit only on the directory #711

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions jupyter_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,32 +165,20 @@ def write_connection_file(
f.write(json.dumps(cfg, indent=2))

if hasattr(stat, "S_ISVTX"):
# set the sticky bit on the file and its parent directory
# to avoid periodic cleanup
paths = [fname]
# set the sticky bit on the parent directory of the file
# to ensure only owner can remove it
runtime_dir = os.path.dirname(fname)
if runtime_dir:
paths.append(runtime_dir)
for path in paths:
permissions = os.stat(path).st_mode
permissions = os.stat(runtime_dir).st_mode
new_permissions = permissions | stat.S_ISVTX
if new_permissions != permissions:
try:
os.chmod(path, new_permissions)
os.chmod(runtime_dir, new_permissions)
except OSError as e:
if e.errno == errno.EPERM and path == runtime_dir:
if e.errno == errno.EPERM:
# suppress permission errors setting sticky bit on runtime_dir,
# which we may not own.
pass
else:
# failed to set sticky bit, probably not a big deal
warnings.warn(
"Failed to set sticky bit on %r: %s"
"\nProbably not a big deal, but runtime files may be cleaned up "
"periodically." % (path, e),
RuntimeWarning,
)

return fname, cfg


Expand Down