Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,20 @@ namespace Hashit {
public void get_file_hash (string path) {
this.files_uris.append_val (path);

string hash = Hashit.Backend.Checksum.calculate_hash (
string? hash = Hashit.Backend.Checksum.calculate_hash (
this.selection_box.get_dropdown_value (),
path
);

GLib.Idle.add (() => {
if (hash == null) {
var toast = new Adw.Toast (_("Failed to calculate hash"));
toast.set_timeout (2);
this.toast_overlay.add_toast (toast);

return false;
}

this.last_hash_entry.set_text (hash);

TextIter text_end_iter;
Expand Down
9 changes: 7 additions & 2 deletions src/Backend/Checksum.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Hashit.Backend.Checksum {

public static string calculate_hash (string type, string file_path) {
public static string? calculate_hash (string type, string file_path) {
GLib.Checksum checksum = null;

switch (type) {
Expand All @@ -23,7 +23,12 @@ namespace Hashit.Backend.Checksum {
break;
}

FileStream stream = FileStream.open (file_path, "rb");
FileStream? stream = FileStream.open (file_path, "rb");
if (stream == null) {
warning ("Failed to open \"%s\": %s", file_path, strerror(errno));
return null;
}

uint8 buffer[100];
size_t size;

Expand Down