Class UninstallPlanner
- Namespace
- FishMMO.Installer
- Assembly
- FishMMO-Installer.dll
Builds the uninstall plan for PostgreSQL. Pure: it reads nothing, runs nothing, and deletes nothing.
public static class UninstallPlanner
- Inheritance
-
UninstallPlanner
- Inherited Members
Remarks
The planning is separated from the doing on purpose. Every command and every path this
installer would run rm -rf or an unattended uninstaller over is decided here, by
functions that can be called and asserted without a PostgreSQL anywhere near them — and the
same list is what the operator is shown before being asked to confirm. A plan that is shown
and a plan that is run cannot drift apart, because they are the same object.
The two platforms never mix. A Linux plan contains no uninstaller executable and a
Windows plan contains no sudo, systemctl or rm -rf. Distribution layouts
differ too: /etc/postgresql/ is the Debian layout and does not exist on Arch, where the
configuration lives inside the data directory, so it appears only in the apt-get plan.
Fields
LinuxServiceName
PostgreSQL's own systemd unit name on every supported distribution.
public const string LinuxServiceName = "postgresql"
Field Value
WindowsDefaultInstallRoot
Where EnterpriseDB's one-click installer puts PostgreSQL by default.
public const string WindowsDefaultInstallRoot = "C:\\Program Files\\PostgreSQL"
Field Value
Remarks
The install path (InstallPostgreSQLWindows) accepts the installer's default prefix,
which is this directory with a version-numbered subdirectory under it.
WindowsUninstallerFileName
The uninstaller EnterpriseDB leaves in each version directory.
public const string WindowsUninstallerFileName = "uninstall-postgresql.exe"
Field Value
Methods
BuildLinuxPlan(PackageManagerKind, IReadOnlyList<string>?)
Builds the Linux uninstall: stop, disable, remove the packages, then remove the data and configuration directories — in that order, because each step depends on the one before it.
public static PostgreSQLUninstallPlan BuildLinuxPlan(PackageManagerKind kind, IReadOnlyList<string>? dependantUnitsToStop = null)
Parameters
kindPackageManagerKindThe detected package manager.
dependantUnitsToStopIReadOnlyList<string>FishMMO and pooler units to stop first. Only units observed to be running should be listed; their failure does not abort the run.
Returns
BuildWindowsPlan(string, string, string?, IReadOnlyList<string>?)
Builds the Windows uninstall around EnterpriseDB's own uninstaller, which is the supported way to undo the one-click installer the install path runs.
public static PostgreSQLUninstallPlan BuildWindowsPlan(string installRoot, string version, string? serviceName = null, IReadOnlyList<string>? dependantServicesToStop = null)
Parameters
installRootstringThe directory holding the version subdirectories, normally WindowsDefaultInstallRoot.
versionstringThe installed version directory name, for example
16.serviceNamestringThe Windows service name, when it was discovered. Defaults to EnterpriseDB's
postgresql-x64-<version>.dependantServicesToStopIReadOnlyList<string>FishMMO services observed running, stopped first.
Returns
Remarks
Deleting the program files by hand would leave the registry entries and the service behind.
The uninstaller removes both; what it routinely leaves is the data directory, which
is why that is a separate, separately confirmed step.
Exceptions
- ArgumentException
If the version or install root is empty or malformed. An empty version is the accident this throws for: it would aim the leftover-data step at the whole PostgreSQL directory.
DataAndConfigDirectories(PackageManagerKind)
The directories PostgreSQL's data and configuration live in for the given manager, in removal order.
public static IReadOnlyList<(string Path, string What)> DataAndConfigDirectories(PackageManagerKind kind)
Parameters
kindPackageManagerKind
Returns
Remarks
Only Debian keeps configuration in /etc/postgresql/. On Arch and on RHEL the
configuration files live inside the data directory, so naming /etc/postgresql there
would be a recursive delete aimed at a directory the distribution never created.
IsRemovablePath(string?, UninstallPlatform, out string)
Decides whether a path may be handed to a recursive delete.
public static bool IsRemovablePath(string? path, UninstallPlatform platform, out string refusal)
Parameters
pathstringCandidate directory.
platformUninstallPlatformWhich layout rules apply.
refusalstringWhy it was refused, when this returns false.
Returns
- bool
True when the path is specific enough to delete.
Remarks
The accident this exists to prevent is an unset or empty value interpolated into a delete:
an empty version turning C:\Program Files\PostgreSQL<version>\data into
C:\Program Files\PostgreSQL, or an empty path turning rm -rf $DIR into
rm -rf with whatever the shell puts next. Nothing is deleted without passing here
first, and this refuses on the safe side.
LinuxDirectoryRemovalCommand(string)
The Linux command that removes one directory, with its own existence test built in.
public static string LinuxDirectoryRemovalCommand(string path)
Parameters
pathstringDirectory to remove. Must have passed IsRemovablePath(string?, UninstallPlatform, out string).
Returns
Remarks
The if test -d is not redundant with the caller's existence check. The caller often
cannot see inside /var/lib/postgres (mode 700, owned by postgres) without root, so
its answer can be "unknown"; this form deletes only what is actually there and exits 0
either way, so an absent directory reads as "nothing to remove" rather than a failure that
aborts the run.
PackageRemovalCommand(PackageManagerKind)
The command that removes the PostgreSQL packages for the given manager.
public static string PackageRemovalCommand(PackageManagerKind kind)
Parameters
kindPackageManagerKind
Returns
PostgreSQLPackageNames()
The package names the install path installs, keyed by manager. Passed to DetectAsync(Dictionary<string, string>) so detection here picks the same manager the install picked.
public static Dictionary<string, string> PostgreSQLPackageNames()
Returns
TryResolvePackageManagerKind(string?, out PackageManagerKind)
Maps the human-readable name DetectAsync(Dictionary<string, string>) reports onto the kind the plan is built from.
public static bool TryResolvePackageManagerKind(string? managerName, out PackageManagerKind kind)
Parameters
managerNamestringFor example
"pacman (Arch/CachyOS)".kindPackageManagerKindThe matching kind when this returns true.
Returns
- bool
True when the name is recognised.
WindowsDirectoryRemovalCommand(string)
The Windows command that removes one leftover directory.
public static string WindowsDirectoryRemovalCommand(string path)
Parameters
pathstring