Files
ltdrdata-ComfyUI-Manager/glob/node_package.py
T
Dr.Lt.Data 7ab6b39cd7 Recognize a nodepack folder with neither .git nor .tracking as an invalid installation and fix it by reinstalling (#3565)
A folder in custom_nodes with neither .git nor .tracking, left by an
install that broke midway or by a download unpacked by hand, was taken for
a git nodepack: Update All logged "ERROR: An error occurred while updating
..." for it, and its nodepack showed as not installed (#3330).

It is now an invalid installation. Update All and cm-cli update all leave
it alone, the Custom Nodes Manager marks its row INVALID INSTALLATION and
offers Reinstall, /customnode/installed lists it with
invalid_installation: true, and the startup notice names it. By its folder
name it is enabled, disabled and uninstalled as before. An update of the
nodepack alone fails with the guidance to reinstall it, and the console
line of a failed update says why the update failed.

A reinstall, of any nodepack, keeps the folders it replaces until the new
installation is in place, and puts them back when the install fails. It
deleted them first, so a failed download lost the nodepack. cm-cli
reinstall makes the same reinstall and prints [REINSTALLED].

What is in the way of a reinstall, such as a clone of a fork at the install
path or under the name of the nodepack, is moved to
custom_nodes/.disabled/.archived/ and the log says where it is. It is not
deleted and no longer loaded, and it goes back when the install fails. The
reinstall failed there with "Install path already exists".
2026-11-22 18:11:46 +09:00

99 lines
2.7 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
import os
from git_utils import get_commit_hash
IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003
def is_link(path: str) -> bool:
"""
A junction is told by the reparse tag that os.lstat reads on every Python; os.path.isjunction is new in 3.12.
"""
try:
return os.path.islink(path) or getattr(os.lstat(path), 'st_reparse_tag', 0) == IO_REPARSE_TAG_MOUNT_POINT
except OSError:
return False
@dataclass(frozen=True)
class InvalidInstallation:
fullpath: str
unknown_key: str
project_name: str | None
enabled: bool
@dataclass
class InstalledNodePackage:
"""Information about an installed node package."""
id: str
fullpath: str
disabled: bool
version: str
@property
def is_unknown(self) -> bool:
return self.version == "unknown"
@property
def is_nightly(self) -> bool:
return self.version == "nightly"
@property
def is_from_cnr(self) -> bool:
return not self.is_unknown and not self.is_nightly
@property
def is_enabled(self) -> bool:
return not self.disabled
@property
def is_disabled(self) -> bool:
return self.disabled
def get_commit_hash(self) -> str:
return get_commit_hash(self.fullpath)
def is_exempt_from_installation_check(self) -> bool:
name = os.path.basename(self.fullpath)
return ('comfyui-manager' in self.id.lower() or is_link(self.fullpath)
or name.startswith('.') or name in ('__MACOSX', '__pycache__'))
def isValid(self) -> bool:
if self.is_exempt_from_installation_check():
return True
return os.path.exists(os.path.join(self.fullpath, '.git')) or os.path.exists(os.path.join(self.fullpath, '.tracking'))
@staticmethod
def from_fullpath(fullpath: str, resolve_from_path) -> InstalledNodePackage:
parent_folder_name = os.path.basename(os.path.dirname(fullpath))
module_name = os.path.basename(fullpath)
if module_name.endswith(".disabled"):
node_id = module_name[:-9]
disabled = True
elif parent_folder_name == ".disabled":
# Nodes under custom_nodes/.disabled/* are disabled
node_id = module_name
disabled = True
else:
node_id = module_name
disabled = False
info = resolve_from_path(fullpath)
if info is None:
version = 'unknown'
else:
node_id = info['id'] # robust module guessing
version = info['ver']
return InstalledNodePackage(
id=node_id, fullpath=fullpath, disabled=disabled, version=version
)