[gparted] Improve initialization logic for FS_Info class



commit 8d024d86dfc4529589fc0e25ff5896591b7c1164
Author: Curtis Gedak <gedakc gmail com>
Date:   Fri Apr 24 17:18:36 2009 -0600

    Improve initialization logic for FS_Info class
    
    Ensure that fs_info_cache is populated in any first instantiation in
    a program, even for an instantiation such as:
        FS_Info A(false);
---
 include/FS_Info.h |    3 +++
 src/FS_Info.cc    |   27 ++++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/include/FS_Info.h b/include/FS_Info.h
index d7c49fa..49b7218 100644
--- a/include/FS_Info.h
+++ b/include/FS_Info.h
@@ -34,7 +34,10 @@ public:
 	Glib::ustring get_uuid( const Glib::ustring & path ) ;
 private:
 	void load_fs_info_cache() ;
+	void set_commands_found() ;
 	Glib::ustring get_device_entry( const Glib::ustring & path ) ;
+	static bool fs_info_cache_initialized ;
+	static bool blkid_found ;
 	static Glib::ustring fs_info_cache ;
 };
 
diff --git a/src/FS_Info.cc b/src/FS_Info.cc
index fd7b26c..16df40a 100644
--- a/src/FS_Info.cc
+++ b/src/FS_Info.cc
@@ -20,18 +20,33 @@
 namespace GParted
 {
 
-//initialize static data element
+//initialize static data elements
+bool FS_Info::fs_info_cache_initialized = false ;
+bool FS_Info::blkid_found  = false ;
 Glib::ustring FS_Info::fs_info_cache = "";
 
 FS_Info::FS_Info()
 {
 	//Ensure that cache has been loaded at least once
-	if ( fs_info_cache == "" )
+	if ( ! fs_info_cache_initialized )
+	{
+		fs_info_cache_initialized = true ;
+		set_commands_found() ;
 		load_fs_info_cache() ;
+	}
 }
 
 FS_Info:: FS_Info( bool do_refresh )
 {
+	//Ensure that cache has been loaded at least once
+	if ( ! fs_info_cache_initialized )
+	{
+		fs_info_cache_initialized = true ;
+		set_commands_found() ;
+		if ( do_refresh == false )
+			load_fs_info_cache() ;
+	}
+
 	if ( do_refresh )
 		load_fs_info_cache() ;
 }
@@ -43,7 +58,7 @@ FS_Info::~FS_Info()
 void FS_Info::load_fs_info_cache()
 {
 	Glib::ustring output, error ;
-	if ( ! Glib::find_program_in_path( "blkid" ) .empty() )
+	if ( blkid_found )
 	{
 		if ( ! Utils::execute_command( "blkid -c /dev/null", output, error, true ) )
 			fs_info_cache = output ;
@@ -52,6 +67,12 @@ void FS_Info::load_fs_info_cache()
 	}
 }
 
+void FS_Info::set_commands_found()
+{
+	//Set status of commands found 
+	blkid_found = (! Glib::find_program_in_path( "blkid" ) .empty() ) ;
+}
+
 Glib::ustring FS_Info::get_device_entry( const Glib::ustring & path )
 {
 	//Retrieve the line containing the device path



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]