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

Persisting permission denied error when saving file, after updating permissions #1502

Open
RRosio opened this issue Feb 18, 2025 · 0 comments
Labels

Comments

@RRosio
Copy link

RRosio commented Feb 18, 2025

Originally posted by @WangChangsongGit in the JupyterLab repository: jupyterlab/jupyterlab#17280


Description

When a user opens a file with no write permission and closes the modification, the user chooses to save the file with the same name as the file. An error message is displayed, Permission denied. After modifying the file permission, open the file again, edit the file, and save the file. The error message is still displayed, Permission denied.

Reproduce

  1. Create a file and set the permission to 500.
    -r-x------ 1 naie naie 0 Feb 11 11:54 test.txt
  2. Open the file in Jupyterlab, modify it, and close it.
  3. The system prompts you to save the file. Select save as and use the same name as the file name.
  4. A message is displayed, indicating that the saving fails and Permission is denied. Check the background file list. It is found that a temporary file with no write permission is generated.
    -r-x------ 1 naie naie 0 Feb 11 15:28 .~test.txt
    -r-x------ 1 naie naie 0 Feb 11 11:54 test.txt
  5. Change the file permission to 700 in Terminal.
  6. Open, edit, and save the file. The error message "Permission denied" is still displayed.
    The log is as follows:
    [2025-02-11 15:39:03] [WARNING] [ServerApp] [handlers.py:752] wrote error: 'Permission denied: test.txt'
    Traceback (most recent call last):
    File "/home/naie/.local/lib/python3.11/site-packages/jupyter_server/services/contents/fileio.py", line 229, in perm_to_403
    yield
    File "/home/naie/.local/lib/python3.11/site-packages/jupyter_server/services/contents/fileio.py", line 218, in atomic_writing
    with atomic_writing(os_path, *args, **kwargs) as f:
    File "/usr1/build/lib/python3.11/contextlib.py", line 137, in enter
    File "/home/naie/.local/lib/python3.11/site-packages/jupyter_server/services/contents/fileio.py", line 104, in atomic_writing
    copy2_safe(path, tmp_path, log=log)
    File "/home/naie/.local/lib/python3.11/site-packages/jupyter_server/services/contents/fileio.py", line 38, in copy2_safe
    shutil.copyfile(src, dst)
    File "/usr1/build/lib/python3.11/shutil.py", line 258, in copyfile
    PermissionError: [Errno 13] Permission denied: '/home/naie/work/.~test.txt'

Check the jupyter_server source code services/contents/fileio.py. Before saving the file, it run the shutil.copyfile command to copy the file as a temporary file. In this case, the permission of the temporary file is the same as that of the source file. When an OS error occurs, jupyter_server does not clear the generated temporary files. As a result, jupyter_server does not have the permission to save the files forever.

Expected behavior

Context

  • Operating System and version: Linux 3e82a28714e8 5.10.0-136.12.0.86.h2367
  • Browser and version: Chrome
  • JupyterLab version: 3.6.7
  • jupyter_server version: 2.10.0
Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant