check for broken symlinks

This commit is contained in:
Cyberes 2022-09-18 17:28:01 -06:00 committed by GitHub
parent 506f467410
commit e917234eda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -391,9 +391,20 @@
"source": [
"%store -r model_storage_dir\n",
"import os\n",
"\n",
"# Check for broken symlinks and remove them\n",
"for file in os.listdir('/notebooks/stable-diffusion-webui/models/'):\n",
" path = f'/notebooks/stable-diffusion-webui/models/{file}'\n",
" if os.path.islink(path) and not os.path.exists(os.readlink(path)):\n",
" print(f'Symlink broken, removing: {file}')\n",
" os.unlink(path)\n",
"\n",
"# Make symlinks for new files\n",
"for file in os.listdir(model_storage_dir):\n",
" if file.endswith(\"ckpt\"):\n",
" if not os.path.exists(f'/notebooks/stable-diffusion-webui/models/{file}'):\n",
" path = f'/notebooks/stable-diffusion-webui/models/{file}'\n",
" if not os.path.exists(path):\n",
" print(f'New model: {file}')\n",
" !ln -s $model_storage_dir/$file /notebooks/stable-diffusion-webui/models/$file\n",
" !ls -la --block-size=GB /notebooks/stable-diffusion-webui/models/$file"
]
@ -494,6 +505,7 @@
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [