check for broken symlinks

Former-commit-id: 8504da80c171a959e1c35aa553759779e2f29f57 [formerly e917234eda]
Former-commit-id: 34e5840ecb0adaeb33f0476d3f197e4c618d4067
This commit is contained in:
Cyberes 2022-09-18 17:28:01 -06:00 committed by GitHub
parent d79e9474bb
commit 0fc0056f3f
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": [