jupyter / jupyter_core

Core Jupyter functionality
https://jupyter-core.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
194 stars 180 forks source link

migrated marker may seem not to exist if os.stat not allowed #355

Closed smartass101 closed 1 year ago

smartass101 commented 1 year ago

I came across this issue while running in a read-only home environment (HPC batch job) on AFS.

As far as I can tell, the issue is even documented the Python os module reference

On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.

So what happens is that here

https://github.com/jupyter/jupyter_core/blob/0ae6f9058d971489f95ea8d38b98dba26556ffa6/jupyter_core/application.py#LL171C1-L171C1

it looks like the migrated marker does not exist, so it executes migrate(), which that fails when it tries to write that marker.

I think the most appropriate thing would be for any operations in migrate() to first check if JUPYTER_CONFIG_DIR is actually writable and if not, cancel the migration or fail back to some temp directory, like IPython does

IPython/paths.py:62: UserWarning: IPython dir '...' is not a writable location, using 
a temp directory.