[gnome-games] ArchiveUtils: Rework errors
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ArchiveUtils: Rework errors
- Date: Sun, 19 May 2019 18:09:57 +0000 (UTC)
commit acd767d6a6b41b02e719209be93709a30953b092
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun May 19 22:58:49 2019 +0500
ArchiveUtils: Rework errors
Introduce CompressionError and ExtractionError instead of ArchiveError.
This will allow to rename Archive in the next commit without a name clash.
src/meson.build | 1 -
src/ui/application.vala | 4 +--
src/ui/preferences-page-backup-restore.vala | 4 +--
src/utils/archive-error.vala | 9 -----
src/utils/archive.vala | 53 +++++++++++++++++------------
5 files changed, 35 insertions(+), 36 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 139e8f6a..4ed5cc5e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -183,7 +183,6 @@ vala_sources = [
'ui/ui-view.vala',
'utils/archive.vala',
- 'utils/archive-error.vala',
'utils/composite-cover.vala',
'utils/composite-title.vala',
'utils/cue-sheet/cue-sheet.vala',
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 2e622e52..d1159fd0 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -447,14 +447,14 @@ public class Games.Application : Gtk.Application {
device.absolute_axis_event.connect (on_gamepad_absolute_axis_event);
}
- public static void restore_from (string archive_path) throws ArchiveError {
+ public static void restore_from (string archive_path) throws ExtractionError {
var data_dir = Application.get_data_dir ();
string[] database = { Application.get_database_path () };
extract_archive (archive_path, data_dir, database);
}
- public static void backup_to (string file_path) throws ArchiveError {
+ public static void backup_to (string file_path) throws CompressionError {
var data_dir = File.new_for_path (Application.get_data_dir ());
string[] database = { Application.get_database_path () };
diff --git a/src/ui/preferences-page-backup-restore.vala b/src/ui/preferences-page-backup-restore.vala
index a0b2f15e..8d8fc349 100644
--- a/src/ui/preferences-page-backup-restore.vala
+++ b/src/ui/preferences-page-backup-restore.vala
@@ -19,7 +19,7 @@ private class Games.PreferencesPageBackupRestore : PreferencesPage {
try {
Application.restore_from (archive_name);
}
- catch (Error e) {
+ catch (ExtractionError e) {
var msg = _("Couldn’t restore: %s").printf (e.message);
show_error_message (msg);
}
@@ -49,7 +49,7 @@ private class Games.PreferencesPageBackupRestore : PreferencesPage {
try {
Application.backup_to (filename);
}
- catch (ArchiveError e) {
+ catch (CompressionError e) {
var msg = _("Couldn’t back up: %s").printf (e.message);
show_error_message (msg);
}
diff --git a/src/utils/archive.vala b/src/utils/archive.vala
index 25b86cc6..005605e4 100644
--- a/src/utils/archive.vala
+++ b/src/utils/archive.vala
@@ -1,7 +1,21 @@
// This file is part of GNOME Games. License: GPL-3.0+.
+public errordomain Games.CompressionError {
+ CLOSING_FAILED,
+ COULDNT_ENUMERATE_CHILDREN,
+ COULDNT_WRITE_HEADER,
+ COULDNT_WRITE_FILE,
+ INITIALIZATION_FAILED,
+}
+
+public errordomain Games.ExtractionError {
+ CLEANUP_FAILED,
+ COULDNT_READ_HEADER,
+ DIDNT_REACH_EOF,
+}
+
namespace Games {
- private void compress_dir (string name, File parent_dir, File export_data, string[]? exclude_files =
null) throws ArchiveError {
+ private void compress_dir (string name, File parent_dir, File export_data, string[]? exclude_files =
null) throws CompressionError {
var archive = new Archive.Write ();
archive.add_filter_gzip ();
archive.set_format_pax_restricted ();
@@ -10,11 +24,11 @@ namespace Games {
backup_data (parent_dir, export_data, archive, exclude_files);
if (archive.close () != Archive.Result.OK) {
var error_message = _("Error: %s (%d)").printf (archive.error_string (),
archive.errno ());
- throw new ArchiveError.COMPRESSION_FAILED (error_message);
+ throw new CompressionError.CLOSING_FAILED (error_message);
}
}
- private void backup_data (File parent, File dir, Archive.Write archive, string[] exclusions) throws
ArchiveError {
+ private void backup_data (File parent, File dir, Archive.Write archive, string[] exclusions) throws
CompressionError {
var dtype = dir.query_file_type (FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
if (dtype == FileType.DIRECTORY) {
@@ -27,7 +41,7 @@ namespace Games {
}
}
catch (Error e) {
- throw new ArchiveError.COMPRESSION_FAILED (e.message);
+ throw new CompressionError.COULDNT_ENUMERATE_CHILDREN (e.message);
}
}
else {
@@ -38,7 +52,7 @@ namespace Games {
}
}
- private void compress_files (File parent_working_dir, File export_dir, Archive.Write export_archive)
throws ArchiveError {
+ private void compress_files (File parent_working_dir, File export_dir, Archive.Write export_archive)
throws CompressionError {
FileInfo export_info;
FileInputStream input_stream;
DataInputStream data_input_stream;
@@ -50,7 +64,7 @@ namespace Games {
data_input_stream = new DataInputStream (input_stream);
}
catch (Error e) {
- throw new ArchiveError.INITIALIZATION_FAILED (e.message);
+ throw new CompressionError.INITIALIZATION_FAILED (e.message);
}
var entry = new Archive.Entry ();
@@ -62,7 +76,7 @@ namespace Games {
entry.set_perm (0644);
if (export_archive.write_header (entry) != Archive.Result.OK) {
var error_msg = _("Error writing “%s”: %s (%d)").printf (export_dir.get_path (),
export_archive.error_string (), export_archive.errno ());
- throw new ArchiveError.COMPRESSION_FAILED (error_msg);
+ throw new CompressionError.COULDNT_WRITE_HEADER (error_msg);
}
size_t bytes_read;
@@ -76,7 +90,7 @@ namespace Games {
}
}
catch (Error e) {
- throw new ArchiveError.FILE_HANDLING (e.message);
+ throw new CompressionError.COULDNT_WRITE_FILE (e.message);
}
}
@@ -84,16 +98,11 @@ namespace Games {
var dtype = file.query_file_type (FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
if (dtype == FileType.DIRECTORY) {
- try {
- var file_children = file.enumerate_children (FileAttribute.STANDARD_NAME, 0);
- FileInfo file_info;
- while ((file_info = file_children.next_file ()) != null) {
- var child = file.get_child (file_info.get_name ());
- delete_files (child, exclusions);
- }
- }
- catch (Error e) {
- throw e;
+ var file_children = file.enumerate_children (FileAttribute.STANDARD_NAME, 0);
+ FileInfo file_info;
+ while ((file_info = file_children.next_file ()) != null) {
+ var child = file.get_child (file_info.get_name ());
+ delete_files (child, exclusions);
}
}
else {
@@ -104,13 +113,13 @@ namespace Games {
}
}
- private void extract_archive (string archive_path, string extract_dir, string[] exclude) throws
ArchiveError {
+ private void extract_archive (string archive_path, string extract_dir, string[] exclude) throws
ExtractionError {
try {
var file_dir = File.new_for_path (extract_dir);
delete_files (file_dir, exclude);
}
catch (Error e) {
- throw new ArchiveError.DELETION_FAILED (e.message);
+ throw new ExtractionError.CLEANUP_FAILED (e.message);
}
var restore_archive = new Archive.Read ();
@@ -131,7 +140,7 @@ namespace Games {
var dir_pathname = ("%s/%s").printf (extract_dir, entry.pathname ());
entry.set_pathname (dir_pathname);
if (extractor_archive.write_header (entry) != Archive.Result.OK)
- throw new ArchiveError.EXTRACTION_FAILED ("%s\n",
extractor_archive.error_string ());
+ throw new ExtractionError.COULDNT_READ_HEADER ("%s\n",
extractor_archive.error_string ());
uint8[] buffer = new uint8[64];
size_t buffer_length;
@@ -141,6 +150,6 @@ namespace Games {
}
if (last_result != Archive.Result.EOF)
- throw new ArchiveError.EXTRACTION_FAILED ("%s (%d)", restore_archive.error_string (),
restore_archive.errno ());
+ throw new ExtractionError.DIDNT_REACH_EOF ("%s (%d)", restore_archive.error_string
(), restore_archive.errno ());
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]