Update to 1.4

This commit is contained in:
Bastien Nocera 2015-02-05 15:34:14 +01:00
parent 64a90dd3ad
commit d2c9ebda85
7 changed files with 7 additions and 332 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ shared-mime-info-0.71.tar.bz2
/shared-mime-info-1.1.tar.xz
/shared-mime-info-1.2.tar.xz
/shared-mime-info-1.3.tar.xz
/shared-mime-info-1.4.tar.xz

View File

@ -1,80 +0,0 @@
From fd48920cf82402a95f658cab93db0cf3786c4d6e Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 25 Jun 2014 17:23:50 +0200
Subject: [PATCH 7/8] Split out fdatasync() usage
---
update-mime-database.c | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/update-mime-database.c b/update-mime-database.c
index c043606..c1a6f9f 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -936,39 +936,49 @@ set_error_from_errno (GError **error)
g_strerror(errsv));
}
-/* Renames pathname by removing the .new extension */
-static gboolean atomic_update(const gchar *pathname, GError **error)
+static int
+sync_file(const gchar *pathname, GError **error)
{
- gboolean ret = FALSE;
- gchar *new_name = NULL;
- int len;
int fd;
- len = strlen(pathname);
-
- g_return_val_if_fail(strcmp(pathname + len - 4, ".new") == 0, FALSE);
-
- new_name = g_strndup(pathname, len - 4);
-
#ifdef HAVE_FDATASYNC
fd = open(pathname, O_RDWR);
if (fd == -1)
{
set_error_from_errno(error);
- goto out;
+ return -1;
}
if (fdatasync(fd) == -1)
{
set_error_from_errno(error);
- goto out;
+ return -1;
}
if (close(fd) == -1)
{
set_error_from_errno(error);
- goto out;
+ return -1;
}
#endif
+ return 0;
+}
+
+/* Renames pathname by removing the .new extension */
+static gboolean atomic_update(const gchar *pathname, GError **error)
+{
+ gboolean ret = FALSE;
+ gchar *new_name = NULL;
+ int len;
+
+ len = strlen(pathname);
+
+ g_return_val_if_fail(strcmp(pathname + len - 4, ".new") == 0, FALSE);
+
+ new_name = g_strndup(pathname, len - 4);
+
+ if (sync_file(pathname, error) == -1)
+ goto out;
+
#ifdef _WIN32
/* we need to remove the old file first! */
remove(new_name);
--
1.9.3

View File

@ -1,47 +0,0 @@
From 1f7683bfcbecbeffa802a1c361e1842db2fff4f8 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 25 Jun 2014 17:25:50 +0200
Subject: [PATCH 8/8] Disable fdatasync() usage if PKGSYSTEM_ENABLE_FSYNC is
set
If the PKGSYSTEM_ENABLE_FSYNC envvar is set to a non-zero value,
the fdatasync() call will be skipped, at the expense of data integrity.
https://bugs.freedesktop.org/show_bug.cgi?id=70366
---
update-mime-database.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/update-mime-database.c b/update-mime-database.c
index c1a6f9f..894ac97 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -936,11 +936,25 @@ set_error_from_errno (GError **error)
g_strerror(errsv));
}
+static gboolean
+sync_enabled(void)
+{
+ const char *env;
+
+ env = g_getenv("PKGSYSTEM_ENABLE_FSYNC");
+ if (!env)
+ return TRUE;
+ return atoi(env);
+}
+
static int
sync_file(const gchar *pathname, GError **error)
{
int fd;
+ if (!sync_enabled())
+ return 0;
+
#ifdef HAVE_FDATASYNC
fd = open(pathname, O_RDWR);
if (fd == -1)
--
1.9.3

View File

@ -1,105 +0,0 @@
From 4b3f9f774da8859d4f1f7e991b12832d6c09b63e Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 27 Jun 2014 16:57:08 +0200
Subject: [PATCH 13/14] Skip mime database update if packages are older than
cache
Check for the mtime of the version file, the last one to be created when
updating the database to see against the mtime of the newest packages
file.
If one of the files inside the packages directory is newer than the
version file, really update the database.
---
update-mime-database.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/update-mime-database.c b/update-mime-database.c
index 894ac97..d1849a3 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <glib.h>
#include <glib/gprintf.h>
+#include <glib/gstdio.h>
#include <errno.h>
#include <dirent.h>
#include <libxml/parser.h>
@@ -3538,6 +3539,61 @@ fclose_gerror(FILE *f, GError **error)
return TRUE;
}
+static gint64
+newest_mtime(const char *packagedir)
+{
+ GDir *dir;
+ GStatBuf statbuf;
+ gint64 mtime = G_MININT64;
+ const char *name;
+ int retval;
+
+ retval = g_stat(packagedir, &statbuf);
+ if (retval < 0)
+ return mtime;
+ mtime = statbuf.st_mtime;
+
+ dir = g_dir_open(packagedir, 0, NULL);
+ if (!dir)
+ return mtime;
+
+ while ((name = g_dir_read_name(dir))) {
+ char *path;
+
+ path = g_build_filename(packagedir, name, NULL);
+ retval = g_stat(path, &statbuf);
+ g_free(path);
+ if (retval < 0)
+ continue;
+ if (statbuf.st_mtime > mtime)
+ mtime = statbuf.st_mtime;
+ }
+
+ g_dir_close(dir);
+ return mtime;
+}
+
+static gboolean
+is_cache_up_to_date (const char *mimedir, const char *packagedir)
+{
+ GStatBuf version_stat;
+ gint64 package_mtime;
+ char *mimeversion;
+ int retval;
+
+ mimeversion = g_build_filename(mimedir, "/version", NULL);
+ retval = g_stat(mimeversion, &version_stat);
+ g_free(mimeversion);
+ if (retval < 0)
+ return FALSE;
+
+ package_mtime = newest_mtime(packagedir);
+ if (package_mtime < 0)
+ return FALSE;
+
+ return version_stat.st_mtime >= package_mtime;
+}
+
int main(int argc, char **argv)
{
char *mime_dir = NULL;
@@ -3610,6 +3666,11 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
+ if (is_cache_up_to_date(mime_dir, package_dir)) {
+ g_message ("Skipping mime update as the cache is up-to-date");
+ return EXIT_SUCCESS;
+ }
+
types = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, free_type);
globs_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
--
1.9.3

View File

@ -1,89 +0,0 @@
From 29a04be6c9cbaf0865c8b57428b7b7c37fbda4c3 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 27 Jun 2014 18:25:57 +0200
Subject: [PATCH 14/14] Add "-n" option to update-mime-database
When "-n" is passed, the cache will only be updated if
$MIME_DIR/packages or one of the files in that directory is newer
than $MIME_DIR/version.
This is useful for package pre- and post-installation scripts.
---
update-mime-database.1 | 7 +++++++
update-mime-database.c | 10 +++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/update-mime-database.1 b/update-mime-database.1
index c9164e1..b18eac3 100644
--- a/update-mime-database.1
+++ b/update-mime-database.1
@@ -16,6 +16,8 @@ update-mime-database \- a program to build the Shared MIME-Info database cache
.B \-v
| [
.B \-V
+|
+.B \-n
]
.I MIME-DIR
@@ -38,6 +40,11 @@ Print out the version information.
.TP
\fB\-V\fR
Be verbose.
+.TP
+\fB\-n\fR
+Only update if \fBMIME-DIR\fR/packages/ or a file in that directory
+is newer than \fBMIME-DIR\fR/version. This is useful for package pre-
+and post-installation scripts.
.SH ARGUMENTS
.TP
diff --git a/update-mime-database.c b/update-mime-database.c
index d1849a3..be4aba2 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -194,7 +194,7 @@ fatal_gerror (GError *error)
static void usage(const char *name)
{
- g_fprintf(stderr, _("Usage: %s [-hvV] MIME-DIR\n"), name);
+ g_fprintf(stderr, _("Usage: %s [-hvVn] MIME-DIR\n"), name);
}
static void free_type(gpointer data)
@@ -3601,11 +3601,12 @@ int main(int argc, char **argv)
int opt;
GError *local_error = NULL;
GError **error = &local_error;
+ gboolean if_newer = FALSE;
/* Install the filtering log handler */
g_log_set_default_handler(g_log_handler, NULL);
- while ((opt = getopt(argc, argv, "hvV")) != -1)
+ while ((opt = getopt(argc, argv, "hvVn")) != -1)
{
switch (opt)
{
@@ -3624,6 +3625,9 @@ int main(int argc, char **argv)
enabled_log_levels |= G_LOG_LEVEL_MESSAGE
| G_LOG_LEVEL_INFO;
break;
+ case 'n':
+ if_newer = TRUE;
+ break;
default:
return EXIT_FAILURE;
}
@@ -3666,7 +3670,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- if (is_cache_up_to_date(mime_dir, package_dir)) {
+ if (if_newer && is_cache_up_to_date(mime_dir, package_dir)) {
g_message ("Skipping mime update as the cache is up-to-date");
return EXIT_SUCCESS;
}
--
1.9.3

View File

@ -1,7 +1,7 @@
Summary: Shared MIME information database
Name: shared-mime-info
Version: 1.3
Release: 15%{?dist}
Version: 1.4
Release: 1%{?dist}
License: GPLv2+
Group: System Environment/Base
URL: http://freedesktop.org/Software/shared-mime-info
@ -20,14 +20,6 @@ Source4: eog-defaults.list
# Work-around for https://bugs.freedesktop.org/show_bug.cgi?id=40354
Patch0: 0001-Remove-sub-classing-from-OO.o-mime-types.patch
# support PKGSYSTEM_ENABLE_FSYNC
# https://bugs.freedesktop.org/show_bug.cgi?id=70366#c30
Patch1: 0007-Split-out-fdatasync-usage.patch
Patch2: 0008-Disable-fdatasync-usage-if-PKGSYSTEM_ENABLE_FSYNC-is.patch
Patch3: 0013-Skip-mime-database-update-if-packages-are-older-than.patch
Patch4: 0014-Add-n-option-to-update-mime-database.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libxml2-devel
BuildRequires: glib2-devel
@ -95,6 +87,9 @@ rm -rf $RPM_BUILD_ROOT%{_datadir}/locale/*
%{_mandir}/man*/*
%changelog
* Thu Feb 05 2015 Bastien Nocera <bnocera@redhat.com> 1.4-1
- Update to 1.4
* Tue Sep 30 2014 Bastien Nocera <bnocera@redhat.com> 1.3-15
- Fix Totem being the default music player (#1146001)

View File

@ -1 +1 @@
743720bc4803dd69f55449013d350f31 shared-mime-info-1.3.tar.xz
16c02f7b658fff2a9c207406d388ea31 shared-mime-info-1.4.tar.xz