Skip to content

Commit

Permalink
PR47060 fixed by stacktic
Browse files Browse the repository at this point in the history
  • Loading branch information
imilh committed Nov 17, 2012
1 parent 0f41977 commit 700d301
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
20121117
PR47060 fixed by stacktic

20121114
0.6.3
Added show-no-keep by orgrim
Expand Down
22 changes: 15 additions & 7 deletions actions.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: actions.c,v 1.53 2012/08/04 14:23:46 imilh Exp $ */
/* $Id: actions.c,v 1.54 2012/11/17 14:04:13 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011, 2012 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -330,15 +330,15 @@ pkgin_install(char **opkgargs, uint8_t do_inst)
{
int installnum = 0, upgradenum = 0, removenum = 0;
int rc = EXIT_FAILURE;
uint64_t file_size = 0, size_pkg = 0;
uint64_t file_size = 0, size_pkg = 0, free_space;
Pkglist *premove, *pinstall;
Pkglist *pimpact;
Plisthead *impacthead; /* impact head */
Plisthead *removehead = NULL, *installhead = NULL;
char **pkgargs;
char *toinstall = NULL, *toupgrade = NULL, *toremove = NULL;
char *unmet_reqs = NULL;
char pkgpath[BUFSIZ], h_psize[H_BUF], h_fsize[H_BUF];
char pkgpath[BUFSIZ], h_psize[H_BUF], h_fsize[H_BUF], h_free[H_BUF];
struct stat st;

/* transform command line globs into pkgnames */
Expand Down Expand Up @@ -404,10 +404,18 @@ pkgin_install(char **opkgargs, uint8_t do_inst)
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);

/* check disk space */
if (!fs_has_room(pkgin_cache, (int64_t)file_size))
errx(EXIT_FAILURE, MSG_NO_CACHE_SPACE, pkgin_cache);
if (!fs_has_room(LOCALBASE, (int64_t)size_pkg))
errx(EXIT_FAILURE, MSG_NO_INSTALL_SPACE, LOCALBASE);
free_space = fs_room(pkgin_cache);
if (free_space < file_size) {
(void)humanize_number(h_free, H_BUF, (int64_t)free_space, "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
errx(EXIT_FAILURE, MSG_NO_CACHE_SPACE, pkgin_cache, h_fsize, h_free);
}
free_space = fs_room(LOCALBASE);
if (free_space < size_pkg) {
(void)humanize_number(h_free, H_BUF, (int64_t)free_space, "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
errx(EXIT_FAILURE, MSG_NO_INSTALL_SPACE, LOCALBASE, h_psize, h_free);
}

printf("\n");

Expand Down
13 changes: 12 additions & 1 deletion fsops.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: fsops.c,v 1.3 2012/06/13 13:50:17 imilh Exp $ */
/* $Id: fsops.c,v 1.4 2012/11/17 14:04:13 imilh Exp $ */

/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -64,6 +64,17 @@ fs_has_room(const char *dir, int64_t size)
return 0;
}

uint64_t
fs_room(const char *dir)
{
struct statvfs fsbuf;

if (statvfs(dir, &fsbuf) < 0)
err(EXIT_FAILURE, "Can't statvfs() `%s'", dir);

return (int64_t)fsbuf.f_bavail * (int64_t)fsbuf.f_frsize;
}

void
clean_cache()
{
Expand Down
6 changes: 3 additions & 3 deletions messages.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: messages.h,v 1.31 2012/10/02 10:20:24 imilh Exp $ */
/* $Id: messages.h,v 1.32 2012/11/17 14:04:13 imilh Exp $ */

/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -72,8 +72,8 @@
"%s (to be installed) conflicts with installed package %s.\n"
#define MSG_NOTHING_TO_DO "nothing to do.\n"
#define MSG_REQT_MISSING "the following packages have unmet requirements: %s\n\n"
#define MSG_NO_CACHE_SPACE "%s has not enough space for download\n"
#define MSG_NO_INSTALL_SPACE "%s has not enough space for installation\n"
#define MSG_NO_CACHE_SPACE "%s does not have enough space for download, (%s required but only %s is available)\n"
#define MSG_NO_INSTALL_SPACE "%s does not have enough space for installation (%s required but only %s is available)\n"
#define MSG_PKGS_TO_UPGRADE "%d packages to be upgraded: %s\n"
#define MSG_PKGS_TO_REMOVE "%d packages to be removed: %s\n"
#define MSG_NOTHING_TO_UPGRADE "nothing to upgrade.\n"
Expand Down
3 changes: 2 additions & 1 deletion pkgin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: pkgin.h,v 1.40 2012/10/02 10:20:24 imilh Exp $ */
/* $Id: pkgin.h,v 1.41 2012/11/17 14:04:13 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011, 2012 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -260,6 +260,7 @@ int pkg_is_kept(Pkglist *);
void pkg_keep(int, char **);
/* fsops.c */
int fs_has_room(const char *, int64_t);
uint64_t fs_room(const char *);
void clean_cache(void);
void create_dirs(void);
char *read_repos(void);
Expand Down

0 comments on commit 700d301

Please sign in to comment.