Tighten comments and docstrings added by the image-generation fixes

This commit is contained in:
Daniel Han 2026-07-13 05:29:09 +00:00
commit e0ef488f47
25 changed files with 140 additions and 252 deletions

View file

@ -401,12 +401,9 @@ def install(
has no ``sd-cli``.
"""
target = install_dir or default_install_dir()
# Decide up front whether this install may claim ownership of ``target``. We only mark a
# directory as Studio-owned (and therefore eligible for the uninstaller's recursive delete)
# when this install actually created it or it was empty -- NEVER when it already held a user's
# own stable-diffusion.cpp checkout or unrelated files. Adopting a pre-existing, unowned,
# non-empty directory would let a later uninstall wipe the user's own work. A directory that
# already carries our marker (a prior Studio install / upgrade) stays owned.
# Only claim ownership of ``target`` (marking it for the uninstaller's recursive delete) when
# this install created it or it was empty, or it already carries our marker -- never adopt a
# pre-existing non-empty dir, else a later uninstall could wipe a user's own checkout.
marker = target / ".unsloth-studio-owned"
_may_own = True
if target.exists():
@ -418,11 +415,9 @@ def install(
_pre_existing_entries = True
# Empty dir, or one we already own, may be (re)claimed; a non-empty unowned dir may not.
_may_own = (not _pre_existing_entries) or marker.is_file()
# Refuse to extract into a pre-existing, non-empty directory we do not own (a user's own
# stable-diffusion.cpp checkout, or unrelated files beside a custom Studio root). Not writing
# the ownership marker only protects the uninstaller; extracting the release here would still
# merge our binaries into the user's working tree and can overwrite same-named files. Fail with
# a clear message so the user points us at a fresh/empty location instead of corrupting theirs.
# Refuse to extract into a pre-existing, non-empty directory we do not own: merging the release
# in would overwrite or mix our binaries into the user's own files. Fail so they point us at a
# fresh/empty location.
if not _may_own:
raise RuntimeError(
f"sd.cpp install target already exists and is not a Studio-managed directory: {target}. "
@ -470,11 +465,8 @@ def install(
_make_executable(sd_server)
if sd_server is not None:
print(f"installed sd-server -> {sd_server}", flush = True)
# Ownership marker (the same one setup.sh/_is_studio_root use, and setup.ps1 writes into the
# Node sibling dir) so the uninstaller can tell a Studio-installed sd.cpp from a user's own
# stable-diffusion.cpp checkout beside a custom Studio root, and delete only ours. Written only
# when this install created the directory or it was empty (see _may_own above): a pre-existing,
# unowned, non-empty directory keeps its unowned status so the uninstaller leaves it alone.
# Ownership marker (the same one setup.sh/_is_studio_root use) so the uninstaller deletes only
# Studio-installed sd.cpp, not a user's own checkout. Written only when _may_own (see above).
if _may_own:
try:
marker.touch()