Skip to content

Commit

Permalink
Also split out deleting files
Browse files Browse the repository at this point in the history
Removes need for special handling of 0-sized archives in pkg_delete_files().

  # pkg delete -f git apache24 xorg
  [1/3] Deinstalling git-2.0.2_1...
  Updating /etc/shells
  ==> You should manually remove the "git_daemon" user.
  [1/3] Deleting files for git-2.0.2_1: 100%
  [2/3] Deinstalling apache24-2.4.10_1...
  /usr/local/etc/apache24/httpd.conf
  [2/3] Deleting files for apache24-2.4.10_1: 100%
  [3/3] Deinstalling xorg-7.7...

Issue:	freebsd#758
  • Loading branch information
bdrewery committed Aug 25, 2014
1 parent 5da7e15 commit 9822755
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
8 changes: 8 additions & 0 deletions libpkg/pkg.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,8 @@ typedef enum {
PKG_EVENT_UPGRADE_FINISHED,
PKG_EVENT_EXTRACT_BEGIN,
PKG_EVENT_EXTRACT_FINISHED,
PKG_EVENT_DELETE_FILES_BEGIN,
PKG_EVENT_DELETE_FILES_FINISHED,
PKG_EVENT_ADD_DEPS_BEGIN,
PKG_EVENT_ADD_DEPS_FINISHED,
PKG_EVENT_FETCHING,
Expand Down Expand Up @@ -1486,6 +1488,12 @@ struct pkg_event {
struct {
struct pkg *pkg;
} e_extract_finished;
struct {
struct pkg *pkg;
} e_delete_files_begin;
struct {
struct pkg *pkg;
} e_delete_files_finished;
struct {
struct pkg *pkg;
} e_add_deps_begin;
Expand Down
8 changes: 5 additions & 3 deletions libpkg/pkg_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ pkg_delete_files(struct pkg *pkg, unsigned force)

nfiles = HASH_COUNT(pkg->files);

pkg_emit_progress_start(NULL);
/* fake to show a 100% progress */
if (nfiles == 0)
pkg_emit_progress_tick(1, 1);
return (EPKG_OK);

pkg_emit_delete_files_begin(pkg);
pkg_emit_progress_start(NULL);

while (pkg_files(pkg, &file) == EPKG_OK) {
pkg_emit_progress_tick(cur_file++, nfiles);
Expand All @@ -177,6 +178,7 @@ pkg_delete_files(struct pkg *pkg, unsigned force)
}

pkg_emit_progress_tick(nfiles, nfiles);
pkg_emit_delete_files_finished(pkg);

return (EPKG_OK);
}
Expand Down
22 changes: 22 additions & 0 deletions libpkg/pkg_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,28 @@ pkg_emit_extract_finished(struct pkg *p)
pkg_emit_event(&ev);
}

void
pkg_emit_delete_files_begin(struct pkg *p)
{
struct pkg_event ev;

ev.type = PKG_EVENT_DELETE_FILES_BEGIN;
ev.e_delete_files_begin.pkg = p;

pkg_emit_event(&ev);
}

void
pkg_emit_delete_files_finished(struct pkg *p)
{
struct pkg_event ev;

ev.type = PKG_EVENT_DELETE_FILES_FINISHED;
ev.e_delete_files_finished.pkg = p;

pkg_emit_event(&ev);
}

void
pkg_emit_integritycheck_begin(void)
{
Expand Down
2 changes: 2 additions & 0 deletions libpkg/private/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ void pkg_emit_add_deps_begin(struct pkg *p);
void pkg_emit_add_deps_finished(struct pkg *p);
void pkg_emit_extract_begin(struct pkg *p);
void pkg_emit_extract_finished(struct pkg *p);
void pkg_emit_delete_files_begin(struct pkg *p);
void pkg_emit_delete_files_finished(struct pkg *p);

#endif
16 changes: 15 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,26 @@ event_callback(void *data, struct pkg_event *ev)
job_status_begin(msg_buf);

pkg = ev->e_install_begin.pkg;
pkg_sbuf_printf(msg_buf, "Deleting %n-%v", pkg, pkg);
pkg_sbuf_printf(msg_buf, "Deinstalling %n-%v...\n", pkg, pkg);
sbuf_finish(msg_buf);
printf("%s", sbuf_data(msg_buf));
break;
case PKG_EVENT_DEINSTALL_FINISHED:
if (quiet)
break;
break;
case PKG_EVENT_DELETE_FILES_BEGIN:
if (quiet)
break;
else {
job_status_begin(msg_buf);
pkg = ev->e_install_begin.pkg;
pkg_sbuf_printf(msg_buf, "Deleting files for %n-%v",
pkg, pkg);
}
break;
case PKG_EVENT_DELETE_FILES_FINISHED:
break;
case PKG_EVENT_UPGRADE_BEGIN:
if (quiet)
break;
Expand Down

0 comments on commit 9822755

Please sign in to comment.