Skip to content

Commit e133b21

Browse files
evadotbapt
authored andcommitted
Add unregister
The goal of unregister is to remove the record from the database that a package is install but to no touch the files (or even run the scripts as we want to keep the generated data for example). This will allow people to migrate from a pkgbase to a non-pkgbase install. Sponsored by: Beckhoff Automation GmbH & Co. KG
1 parent 97530dd commit e133b21

File tree

12 files changed

+601
-6
lines changed

12 files changed

+601
-6
lines changed

docs/Makefile.autosetup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ MAN8= pkg-add.8 \
3737
pkg-ssh.8 \
3838
pkg-stats.8 \
3939
pkg-triggers.8 \
40+
pkg-unregister.8 \
4041
pkg-update.8 \
4142
pkg-updating.8 \
4243
pkg-upgrade.8 \

docs/pkg-unregister.8

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
.\"
2+
.\" FreeBSD pkg - a next generation package for the installation and maintenance
3+
.\" of non-core utilities.
4+
.\"
5+
.\" Redistribution and use in source and binary forms, with or without
6+
.\" modification, are permitted provided that the following conditions
7+
.\" are met:
8+
.\" 1. Redistributions of source code must retain the above copyright
9+
.\" notice, this list of conditions and the following disclaimer.
10+
.\" 2. Redistributions in binary form must reproduce the above copyright
11+
.\" notice, this list of conditions and the following disclaimer in the
12+
.\" documentation and/or other materials provided with the distribution.
13+
.\"
14+
.\"
15+
.\" @(#)pkg.8
16+
.\"
17+
.Dd December 2, 2025
18+
.Dt PKG-UNREGISTER 8
19+
.Os
20+
.Sh NAME
21+
.Nm "pkg unregister"
22+
.Nd deletes packages records from the database
23+
.Sh SYNOPSIS
24+
.Nm
25+
.Op Fl fnqRy
26+
.Op Fl Cgix
27+
.Ar pkg-name ...
28+
.Nm
29+
.Op Fl Dnqy
30+
.Fl a
31+
.Pp
32+
.Nm
33+
.Op Cm --{force,dry-run,quiet,recursive,yes}
34+
.Op Cm --{case-sensitive,glob,case-insensitive,regex}
35+
.Ar pkg-name ...
36+
.Nm
37+
.Op Cm --{dry-run,quiet,yes}
38+
.Cm --all
39+
.Sh DESCRIPTION
40+
.Nm
41+
is used for deleting installed packages from the database.
42+
.Nm
43+
creates a work-list of all the installed packages matching the package
44+
names on the command line.
45+
The list is presented to the user.
46+
If the user confirms that they do want to remove those packages
47+
from the db, or if the
48+
.Cm ASSUME_ALWAYS_YES
49+
configuration option is set,
50+
.Nm
51+
proceeds to remove from the db the listed packages.
52+
.Pp
53+
If the set of packages to be unregistered would leave installed packages
54+
with unfulfilled dependencies,
55+
.Nm
56+
will add the packages with unfulfilled dependencies to the list of
57+
packages to be unregistered, unless forced to proceed without unregistering any
58+
other packages by the
59+
.Fl f
60+
option.
61+
.Pp
62+
.Nm
63+
avoids deleting itself unless named specifically on the command line.
64+
So, for instance,
65+
.Nm Fl a
66+
will unregister all packages from the db except for the
67+
.Xr pkg 8
68+
package.
69+
To force all packages to be unregistered from the db without exception, use
70+
.Nm Fl fa .
71+
.Sh OPTIONS
72+
The following options are supported by
73+
.Nm :
74+
.Bl -tag -width recursive
75+
.It Fl a , Cm --all
76+
Deletes all installed packages from the db except for
77+
.Xr pkg 8
78+
from the system and cleans the database of information related to removed
79+
packages.
80+
.It Fl C , Cm --case-sensitive
81+
Make the standard or regular expression
82+
.Fl ( x )
83+
matching against
84+
.Ar pkg-name
85+
case sensitive.
86+
.It Fl D , Cm --no-scripts
87+
If a deinstallation script exists for a given package, do not execute it.
88+
.It Fl f , Cm --force
89+
Forces packages to be removed from the db despite leaving unresolved dependencies.
90+
In combination with the
91+
.Fl a
92+
or
93+
.Fl -all
94+
flag, causes
95+
.Xr pkg 8
96+
to be removed as well as all other packages.
97+
.It Fl g , Cm --glob
98+
Treat the package names as shell glob patterns.
99+
.It Fl i , Cm --case-insensitive
100+
Make the standard or regular expression
101+
.Fl ( x )
102+
matching against
103+
.Ar pkg-name
104+
case insensitive.
105+
This is the default, unless modified by setting
106+
.Ev CASE_SENSITIVE_MATCH
107+
to true in
108+
.Pa pkg.conf .
109+
.It Fl n , Cm --dry-run
110+
Dry run mode.
111+
The list of packages to delete is always printed, but no packages are
112+
actually deleted.
113+
.It Fl q , Cm --quiet
114+
Force quiet output, except where
115+
.Fl n
116+
is also used, when
117+
.Nm
118+
will show the list of packages to be deleted.
119+
.It Fl R , Cm --recursive
120+
Delete all packages that require the listed packages as well.
121+
.It Fl x , Cm --regex
122+
Treat the package names as regular expressions according to the
123+
"modern" or "extended" syntax of
124+
.Xr re_format 7 .
125+
.It Fl y , Cm --yes
126+
Assume yes when asked for confirmation before package deletion.
127+
.El
128+
.Sh ENVIRONMENT
129+
The following environment variables affect the execution of
130+
.Nm .
131+
See
132+
.Xr pkg.conf 5
133+
for further description.
134+
.Bl -tag -width ".Ev NO_DESCRIPTIONS"
135+
.It Ev DEFAULT_ALWAYS_YES
136+
.It Ev ASSUME_ALWAYS_YES
137+
.It Ev HANDLE_RC_SCRIPTS
138+
.It Ev PKG_DBDIR
139+
.It Ev CASE_SENSITIVE_MATCH
140+
.El
141+
.Sh FILES
142+
See
143+
.Xr pkg.conf 5 .
144+
.Sh SEE ALSO
145+
.Xr pkg_create 3 ,
146+
.Xr pkg_delete 3 ,
147+
.Xr pkg_printf 3 ,
148+
.Xr pkg_repo_create 3 ,
149+
.Xr pkg_repos 3 ,
150+
.Xr pkg-keywords 5 ,
151+
.Xr pkg-lua-script 5 ,
152+
.Xr pkg-repository 5 ,
153+
.Xr pkg-script 5 ,
154+
.Xr pkg-triggers 5 ,
155+
.Xr pkg.conf 5 ,
156+
.Xr pkg 8 ,
157+
.Xr pkg-add 8 ,
158+
.Xr pkg-alias 8 ,
159+
.Xr pkg-annotate 8 ,
160+
.Xr pkg-audit 8 ,
161+
.Xr pkg-autoremove 8 ,
162+
.Xr pkg-check 8 ,
163+
.Xr pkg-clean 8 ,
164+
.Xr pkg-config 8 ,
165+
.Xr pkg-create 8 ,
166+
.Xr pkg-fetch 8 ,
167+
.Xr pkg-info 8 ,
168+
.Xr pkg-install 8 ,
169+
.Xr pkg-key 8 ,
170+
.Xr pkg-lock 8 ,
171+
.Xr pkg-query 8 ,
172+
.Xr pkg-register 8 ,
173+
.Xr pkg-repo 8 ,
174+
.Xr pkg-repositories 8 ,
175+
.Xr pkg-rquery 8 ,
176+
.Xr pkg-search 8 ,
177+
.Xr pkg-set 8 ,
178+
.Xr pkg-shell 8 ,
179+
.Xr pkg-shlib 8 ,
180+
.Xr pkg-ssh 8 ,
181+
.Xr pkg-stats 8 ,
182+
.Xr pkg-triggers 8 ,
183+
.Xr pkg-update 8 ,
184+
.Xr pkg-updating 8 ,
185+
.Xr pkg-upgrade 8 ,
186+
.Xr pkg-version 8 ,
187+
.Xr pkg-which 8

libpkg/pkg.h.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ typedef enum _pkg_flags {
415415
PKG_FLAG_USE_IPV4 = (1U << 11),
416416
PKG_FLAG_USE_IPV6 = (1U << 12),
417417
PKG_FLAG_UPGRADE_VULNERABLE = (1U << 13),
418-
PKG_FLAG_NOEXEC = (1U << 14)
418+
PKG_FLAG_NOEXEC = (1U << 14),
419+
PKG_FLAG_KEEPFILES = (1U << 15)
419420
} pkg_flags;
420421

421422
typedef enum _pkg_stats_t {

libpkg/pkg_delete.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ pkg_delete(struct pkg *pkg, struct pkg *rpkg, struct pkgdb *db, int flags,
100100
return (ret);
101101
}
102102

103-
ret = pkg_delete_files(db, pkg, rpkg, flags, t);
104-
if (ret == EPKG_CANCEL)
105-
cancel = 1;
106-
else if (ret != EPKG_OK)
107-
return (ret);
103+
if ((flags & PKG_DELETE_KEEPFILES) == 0) {
104+
ret = pkg_delete_files(db, pkg, rpkg, flags, t);
105+
if (ret == EPKG_CANCEL)
106+
cancel = 1;
107+
else if (ret != EPKG_OK)
108+
return (ret);
109+
}
108110

109111
if ((flags & PKG_DELETE_NOSCRIPT) == 0) {
110112
bool noexec = ((flags & PKG_DELETE_NOEXEC) == PKG_DELETE_NOEXEC);

libpkg/pkg_jobs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,8 @@ pkg_jobs_handle_delete(struct pkg_solved *ps, struct pkg_jobs *j)
20182018
flags = 0;
20192019
if ((j->flags & PKG_FLAG_NOSCRIPT) != 0)
20202020
flags |= PKG_DELETE_NOSCRIPT;
2021+
if ((j->flags & PKG_FLAG_KEEPFILES) != 0)
2022+
flags |= PKG_DELETE_KEEPFILES;
20212023
if (ps->type == PKG_SOLVED_UPGRADE_REMOVE) {
20222024
flags |= PKG_DELETE_UPGRADE;
20232025
rpkg = ps->xlink->items[0]->pkg;

libpkg/private/pkg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ int pkg_delete(struct pkg *pkg, struct pkg *rpkg, struct pkgdb *db, int flags,
663663
#define PKG_DELETE_UPGRADE (1 << 1) /* delete as a split upgrade */
664664
#define PKG_DELETE_NOSCRIPT (1 << 2) /* don't run delete scripts */
665665
#define PKG_DELETE_NOEXEC (1 << 3) /* don't run delete scripts which execute things*/
666+
#define PKG_DELETE_KEEPFILES (1 << 4) /* don't delete files */
666667

667668
int pkg_fetch_file_to_fd(struct pkg_repo *repo, int dest, struct fetch_item *,
668669
bool silent);

src/Makefile.autosetup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SRCS= add.c \
3131
ssh.c \
3232
stats.c \
3333
triggers.c \
34+
unregister.c \
3435
update.c \
3536
updating.c \
3637
upgrade.c \

src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static struct commands {
8989
{ "stats", "Displays package database statistics", exec_stats, usage_stats},
9090
{ "triggers", "Execute deferred triggers", exec_triggers, usage_triggers},
9191
{ "unlock", "Unlocks a package, allowing modification or deletion", exec_unlock, usage_lock},
92+
{ "unregister", "Deletes only packages entries from the database", exec_unregister, usage_unregister},
9293
{ "update", "Updates package repository catalogues", exec_update, usage_update},
9394
{ "updating", "Displays UPDATING information for a package", exec_updating, usage_updating},
9495
{ "upgrade", "Performs upgrades of packaged software distributions", exec_upgrade, usage_upgrade},

src/pkgcli.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ void usage_stats(void);
125125
int exec_triggers(int, char **);
126126
void usage_triggers(void);
127127

128+
/* pkg unregister */
129+
void usage_unregister(void);
130+
int exec_unregister(int, char **);
131+
128132
/* pkg update */
129133
int exec_update(int, char **);
130134
void usage_update(void);

0 commit comments

Comments
 (0)