Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Use statvfs if it is available and sane.
Vsevolod Stakhov committed 11 years ago
commit a795143b0cfba6777c2b4841d44a9c1886dfc461
parent 01a02f30d6d7a4e34978759796b52fd62786c6f3
4 files changed +58 -13
modified configure.ac
@@ -100,8 +100,6 @@ AC_CHECK_HEADERS_ONCE([sys/endian.h])
AC_CHECK_HEADERS_ONCE([fcntl.h])
AC_CHECK_HEADERS_ONCE([dlfcn.h])
AC_CHECK_HEADERS_ONCE([memory.h])
-
AC_CHECK_HEADERS_ONCE([sys/types.h])
-
AC_CHECK_HEADERS_ONCE([sys/stat.h])
AC_CHECK_HEADERS_ONCE([stdlib.h])
AC_CHECK_HEADERS_ONCE([string.h])
AC_CHECK_HEADERS_ONCE([memory.h])
@@ -135,6 +133,7 @@ AC_CHECK_HEADERS_ONCE([sys/socket.h])
AC_CHECK_HEADERS_ONCE([netinet/in.h])
AC_CHECK_HEADERS_ONCE([netinet/in6.h])
AC_CHECK_HEADERS_ONCE([sys/statfs.h])
+
AC_CHECK_HEADERS_ONCE([sys/statvfs.h])
AC_CHECK_HEADERS_ONCE([dirent.h], [sys/ndir.h], [sys/dir.h], [ndir.h])
AC_CHECK_HEADERS_ONCE([sys/capability.h])
AC_CHECK_HEADERS_ONCE([sys/capsicum.h])
@@ -163,6 +162,7 @@ AC_CHECK_FUNCS_ONCE([strtonum])
AC_CHECK_FUNCS_ONCE([strnstr])
AC_CHECK_FUNCS_ONCE([funopen])
AC_CHECK_FUNCS_ONCE([fopencookie])
+
AC_CHECK_FUNCS_ONCE([statfs])
AC_CHECK_FUNCS_ONCE([sysctlbyname])
AC_CHECK_DECLS(
	[[fstatat], [openat], [unlinkat], [readlinkat], [faccessat]],
modified libpkg/pkg_jobs.c
@@ -53,6 +53,8 @@

#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
+
#elif defined(HAVE_SYS_STATVFS_H)
+
#include <sys/statvfs.h>
#endif

#include "utarray.h"
@@ -2008,9 +2010,8 @@ pkg_jobs_fetch(struct pkg_jobs *j)
{
	struct pkg *p = NULL;
	struct pkg_solved *ps;
-
	struct statfs fs;
	struct stat st;
-
	int64_t dlsize = 0;
+
	int64_t dlsize = 0, fs_avail = -1;
	const char *cachedir = NULL;
	char cachedpath[MAXPATHLEN];
	bool mirror = (j->flags & PKG_FLAG_FETCH_MIRROR) ? true : false;
@@ -2045,6 +2046,8 @@ pkg_jobs_fetch(struct pkg_jobs *j)
	if (dlsize == 0)
		return (EPKG_OK);

+
#ifdef HAVE_STATFS
+
	struct statfs fs;
	while (statfs(cachedir, &fs) == -1) {
		if (errno == ENOENT) {
			if (mkdirs(cachedir) != EPKG_OK)
@@ -2054,14 +2057,27 @@ pkg_jobs_fetch(struct pkg_jobs *j)
			return (EPKG_FATAL);
		}
	}
+
	fs_avail = fs.f_bsize * (int64_t)fs.f_bavail;
+
#elif defined(HAVE_SYS_STATVFS_H)
+
	struct statvfs fs;
+
	while (statvfs(cachedir, &fs) == -1) {
+
		if (errno == ENOENT) {
+
			if (mkdirs(cachedir) != EPKG_OK)
+
				return (EPKG_FATAL);
+
		} else {
+
			pkg_emit_errno("statvfs", cachedir);
+
			return (EPKG_FATAL);
+
		}
+
	}
+
	fs_avail = fs.f_bsize * (int64_t)fs.f_bavail;
+
#endif

-
	if (dlsize > ((int64_t)fs.f_bsize * (int64_t)fs.f_bavail)) {
-
		int64_t fsize = (int64_t)fs.f_bsize * (int64_t)fs.f_bavail;
+
	if (fs_avail != -1 && dlsize > fs_avail) {
		char dlsz[9], fsz[9];

		humanize_number(dlsz, sizeof(dlsz), dlsize, "B",
		    HN_AUTOSCALE, HN_IEC_PREFIXES);
-
		humanize_number(fsz, sizeof(fsz), fsize, "B",
+
		humanize_number(fsz, sizeof(fsz), fs_avail, "B",
		    HN_AUTOSCALE, HN_IEC_PREFIXES);
		pkg_emit_error("Not enough space in %s, needed %s available %s",
		    cachedir, dlsz, fsz);
modified libpkg/pkgdb.c
@@ -59,6 +59,8 @@

#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
+
#elif defined(HAVE_SYS_STATVFS_H)
+
#include <sys/statvfs.h>
#endif

#include "pkg.h"
@@ -898,7 +900,6 @@ int
pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
{
	struct pkgdb	*db = NULL;
-
	struct statfs	 stfs;
	bool		 reopen = false;
	bool		 profile = false;
	char		 localpath[MAXPATHLEN];
@@ -954,15 +955,25 @@ pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)

		sqlite3_initialize();

-
#ifdef MNT_LOCAL
		/*
		 * Fall back on unix-dotfile locking strategy if on a network filesystem
		 */
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
		struct statvfs stfs;
+

+
		if (statvfs(dbdir, &stfs) == 0) {
+
			if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
+
				sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
		}
+
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
+
		struct statfs stfs;
+

		if (statfs(dbdir, &stfs) == 0) {
			if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
				sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
		}
#endif
+

		if (sqlite3_open(localpath, &db->sqlite) != SQLITE_OK) {
			ERROR_SQLITE(db->sqlite, "sqlite open");
			pkgdb_close(db);
modified libpkg/repo/binary/init.c
@@ -41,6 +41,8 @@

#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
+
#elif defined(HAVE_SYS_STATVFS_H)
+
#include <sys/statvfs.h>
#endif

#include "pkg.h"
@@ -310,11 +312,19 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
	sqlite3_initialize();
	dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));

-
#ifdef MNT_LOCAL
-
	struct statfs stfs;
	/*
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
	struct statvfs stfs;
+

+
	if (statvfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
+
	struct statfs stfs;
+

	if (statfs(dbdir, &stfs) == 0) {
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
@@ -420,11 +430,19 @@ pkg_repo_binary_create(struct pkg_repo *repo)
	if (access(filepath, R_OK) == 0)
		return (EPKG_CONFLICT);

-
#ifdef MNT_LOCAL
-
	struct statfs stfs;
	/*
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */
+
#if defined(HAVE_SYS_STATVFS_H) && defined(ST_LOCAL)
+
	struct statvfs stfs;
+

+
	if (statvfs(dbdir, &stfs) == 0) {
+
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
+
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
	}
+
#elif defined(HAVE_STATFS) && defined(MNT_LOCAL)
+
	struct statfs stfs;
+

	if (statfs(dbdir, &stfs) == 0) {
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);