[tracker/nospace] libtracker-data: Do not allow updates when low on disk space
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/nospace] libtracker-data: Do not allow updates when low on disk space
- Date: Wed, 3 Mar 2010 12:26:32 +0000 (UTC)
commit 8a4a9e03cc1a812fb5eec7855d0827ef77e1c6bf
Author: Jürg Billeter <j bitron ch>
Date: Wed Mar 3 13:09:18 2010 +0100
libtracker-data: Do not allow updates when low on disk space
Fixes NB#158864.
src/libtracker-common/tracker-file-utils.c | 37 +++++++++++++++-------------
src/libtracker-common/tracker-file-utils.h | 3 +-
src/libtracker-data/tracker-data-update.c | 12 +++++++++
src/libtracker-data/tracker-data-update.h | 3 +-
src/libtracker-db/tracker-db-manager.c | 17 +++++++++++-
src/libtracker-db/tracker-db-manager.h | 1 +
6 files changed, 52 insertions(+), 21 deletions(-)
---
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index e2650ac..bed45ff 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -187,7 +187,8 @@ tracker_file_get_mime_type (GFile *file)
gboolean
tracker_file_system_has_enough_space (const gchar *path,
- gulong required_bytes)
+ gulong required_bytes,
+ gboolean creating_db)
{
struct statvfs st;
gchar *str1;
@@ -201,25 +202,27 @@ tracker_file_system_has_enough_space (const gchar *path,
return FALSE;
}
- str1 = g_format_size_for_display (required_bytes);
- str2 = g_format_size_for_display (st.f_bsize * st.f_bavail);
-
enough = ((long long) st.f_bsize * st.f_bavail) >= required_bytes;
- if (!enough) {
- g_critical ("Not enough disk space to create databases, "
- "%s remaining, %s required as a minimum",
- str2,
- str1);
- } else {
- g_message ("Checking for adequate disk space to create databases, "
- "%s remaining, %s required as a minimum",
- str2,
- str1);
- }
+ if (creating_db) {
+ str1 = g_format_size_for_display (required_bytes);
+ str2 = g_format_size_for_display (st.f_bsize * st.f_bavail);
- g_free (str2);
- g_free (str1);
+ if (!enough) {
+ g_critical ("Not enough disk space to create databases, "
+ "%s remaining, %s required as a minimum",
+ str2,
+ str1);
+ } else {
+ g_message ("Checking for adequate disk space to create databases, "
+ "%s remaining, %s required as a minimum",
+ str2,
+ str1);
+ }
+
+ g_free (str2);
+ g_free (str1);
+ }
return enough;
}
diff --git a/src/libtracker-common/tracker-file-utils.h b/src/libtracker-common/tracker-file-utils.h
index d5e4962..bbdd980 100644
--- a/src/libtracker-common/tracker-file-utils.h
+++ b/src/libtracker-common/tracker-file-utils.h
@@ -40,7 +40,8 @@ goffset tracker_file_get_size (const gchar *uri);
guint64 tracker_file_get_mtime (const gchar *uri);
gchar * tracker_file_get_mime_type (GFile *file);
gboolean tracker_file_system_has_enough_space (const gchar *path,
- gulong required_bytes);
+ gulong required_bytes,
+ gboolean creating_db);
void tracker_path_remove (const gchar *uri);
gboolean tracker_path_is_in_path (const gchar *path,
const gchar *in_path);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index ffe3451..3e6bdd9 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2283,6 +2283,12 @@ tracker_data_update_sparql (const gchar *update,
g_return_if_fail (update != NULL);
+ if (!tracker_db_manager_has_enough_space ()) {
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_NO_SPACE,
+ "There is not enough space on the file system for update operations");
+ return;
+ }
+
iface = tracker_db_manager_get_db_interface ();
sparql_query = tracker_sparql_query_new_update (update);
@@ -2331,6 +2337,12 @@ tracker_data_update_sparql_blank (const gchar *update,
g_return_val_if_fail (update != NULL, NULL);
+ if (!tracker_db_manager_has_enough_space ()) {
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_NO_SPACE,
+ "There is not enough space on the file system for update operations");
+ return NULL;
+ }
+
iface = tracker_db_manager_get_db_interface ();
sparql_query = tracker_sparql_query_new_update (update);
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index f239493..df5484d 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -39,7 +39,8 @@ typedef enum {
TRACKER_DATA_ERROR_UNKNOWN_CLASS,
TRACKER_DATA_ERROR_UNKNOWN_PROPERTY,
TRACKER_DATA_ERROR_INVALID_TYPE,
- TRACKER_DATA_ERROR_CONSTRAINT
+ TRACKER_DATA_ERROR_CONSTRAINT,
+ TRACKER_DATA_ERROR_NO_SPACE
} TrackerDataError;
typedef void (*TrackerStatementCallback) (const gchar *graph,
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index f7fb442..8f2fe5b 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -1432,7 +1432,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
*first_time = TRUE;
}
- if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE)) {
+ if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, TRUE)) {
return FALSE;
}
@@ -1512,7 +1512,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
}
}
- if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE)) {
+ if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, TRUE)) {
return FALSE;
}
@@ -1848,3 +1848,16 @@ tracker_db_manager_get_db_interface (void)
return resources_iface;
}
+/**
+ * tracker_db_manager_has_enough_space:
+ *
+ * Checks whether the file system, where the database files are stored,
+ * has enough free space to allow modifications.
+ *
+ * returns: TRUE if there is enough space, FALSE otherwise
+ **/
+gboolean
+tracker_db_manager_has_enough_space (void)
+{
+ return tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE, FALSE);
+}
diff --git a/src/libtracker-db/tracker-db-manager.h b/src/libtracker-db/tracker-db-manager.h
index 5947652..a94d3de 100644
--- a/src/libtracker-db/tracker-db-manager.h
+++ b/src/libtracker-db/tracker-db-manager.h
@@ -60,6 +60,7 @@ void tracker_db_manager_remove_temp (void);
void tracker_db_manager_move_to_temp (void);
void tracker_db_manager_restore_from_temp (void);
void tracker_db_manager_init_locations (void);
+gboolean tracker_db_manager_has_enough_space (void);
TrackerDBManagerFlags
tracker_db_manager_get_flags (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]