[glom] test_document_export_po: Remove the test file.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] test_document_export_po: Remove the test file.
- Date: Wed, 6 Nov 2013 10:39:39 +0000 (UTC)
commit f907e03b75deeec8912224608a8d35f9084dfa33
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Nov 6 10:54:37 2013 +0100
test_document_export_po: Remove the test file.
* glom/libglom/utils.[h|cc]:
Add delete_file() and catch exceptions in delete_directory().
* tests/translations_po/test_document_export_po.cc:
Delete the file that the test creates.
glom/libglom/utils.cc | 71 ++++++++++++++++------
glom/libglom/utils.h | 6 ++
tests/translations_po/test_document_export_po.cc | 2 +-
3 files changed, 58 insertions(+), 21 deletions(-)
---
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 712b0b5..417aefc 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -1234,32 +1234,40 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_update_with_where_clause(
bool Utils::delete_directory(const Glib::RefPtr<Gio::File>& directory)
{
- if(!(directory->query_exists()))
- return true;
+ try
+ {
+ if(!(directory->query_exists()))
+ return true;
- //(Recursively) Delete any child files and directories,
- //so we can delete this directory.
- Glib::RefPtr<Gio::FileEnumerator> enumerator = directory->enumerate_children();
+ //(Recursively) Delete any child files and directories,
+ //so we can delete this directory.
+ Glib::RefPtr<Gio::FileEnumerator> enumerator = directory->enumerate_children();
- Glib::RefPtr<Gio::FileInfo> info = enumerator->next_file();
- while(info)
- {
- Glib::RefPtr<Gio::File> child = directory->get_child(info->get_name());
- bool removed_child = false;
- if(child->query_file_type() == Gio::FILE_TYPE_DIRECTORY)
- removed_child = delete_directory(child);
- else
- removed_child = child->remove();
+ Glib::RefPtr<Gio::FileInfo> info = enumerator->next_file();
+ while(info)
+ {
+ Glib::RefPtr<Gio::File> child = directory->get_child(info->get_name());
+ bool removed_child = false;
+ if(child->query_file_type() == Gio::FILE_TYPE_DIRECTORY)
+ removed_child = delete_directory(child);
+ else
+ removed_child = child->remove();
- if(!removed_child)
- return false;
+ if(!removed_child)
+ return false;
- info = enumerator->next_file();
- }
+ info = enumerator->next_file();
+ }
- //Delete the actual directory:
- if(!directory->remove())
+ //Delete the actual directory:
+ if(!directory->remove())
+ return false;
+ }
+ catch(const Glib::Error& ex)
+ {
+ std::cerr << G_STRFUNC << ": Exception from Gio::File: " << ex.what() << std::endl;
return false;
+ }
return true;
}
@@ -1270,6 +1278,29 @@ bool Utils::delete_directory(const std::string& uri)
return delete_directory(file);
}
+bool Utils::delete_file(const std::string& uri)
+{
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
+ if(file->query_file_type() == Gio::FILE_TYPE_DIRECTORY)
+ {
+ std::cerr << G_STRFUNC << ": The file is a directory." << std::endl;
+ return false;
+ }
+
+ try
+ {
+ if(!file->remove())
+ return false;
+ }
+ catch(const Glib::Error& ex)
+ {
+ std::cerr << G_STRFUNC << ": Exception from Gio::File: " << ex.what() << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
/** For instance, to find the first file in the directory with a .glom extension.
*/
Glib::ustring Utils::get_directory_child_with_suffix(const Glib::ustring& uri_directory, const std::string&
suffix, bool recursive)
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index dfa2bc6..fbaabff 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -187,9 +187,15 @@ bool delete_directory(const Glib::RefPtr<Gio::File>& directory);
/** Delete a directory, if it exists, and its contents.
* Unlike g_file_delete(), this does not fail if the directory is not empty.
+ * See also delete_file().
*/
bool delete_directory(const std::string& uri);
+/** Delete a file, if it exists.
+ * See also delete_directory().
+ */
+bool delete_file(const std::string& uri);
+
/** For instance, to find the first file in the directory with a .glom extension.
*/
Glib::ustring get_directory_child_with_suffix(const Glib::ustring& uri_directory, const std::string& suffix,
bool recursive);
diff --git a/tests/translations_po/test_document_export_po.cc
b/tests/translations_po/test_document_export_po.cc
index 19a882e..3f81f88 100644
--- a/tests/translations_po/test_document_export_po.cc
+++ b/tests/translations_po/test_document_export_po.cc
@@ -154,7 +154,7 @@ int main()
//Check that the .po file is valid:
check_po_file(po_file_path);
- //TODO: Remove po_file_uri
+ Glom::Utils::delete_file(po_file_uri);
Glom::libglom_deinit();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]