mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
LibGUI: Added error events to FileSystemModel
This will allow us to catch errors early on FileManager
This commit is contained in:
parent
802c06ab7b
commit
451b3fa73c
2 changed files with 18 additions and 5 deletions
|
@ -60,6 +60,7 @@ bool FileSystemModel::Node::fetch_data(const String& full_path, bool is_root)
|
||||||
else
|
else
|
||||||
rc = lstat(full_path.characters(), &st);
|
rc = lstat(full_path.characters(), &st);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
m_error = errno;
|
||||||
perror("stat/lstat");
|
perror("stat/lstat");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +96,7 @@ void FileSystemModel::Node::traverse_if_needed(const FileSystemModel& model)
|
||||||
auto full_path = this->full_path(model);
|
auto full_path = this->full_path(model);
|
||||||
Core::DirIterator di(full_path, Core::DirIterator::SkipDots);
|
Core::DirIterator di(full_path, Core::DirIterator::SkipDots);
|
||||||
if (di.has_error()) {
|
if (di.has_error()) {
|
||||||
|
m_error = di.error();
|
||||||
fprintf(stderr, "DirIterator: %s\n", di.error_string());
|
fprintf(stderr, "DirIterator: %s\n", di.error_string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -288,11 +290,14 @@ static String permission_string(mode_t mode)
|
||||||
void FileSystemModel::set_root_path(const StringView& root_path)
|
void FileSystemModel::set_root_path(const StringView& root_path)
|
||||||
{
|
{
|
||||||
m_root_path = canonicalized_path(root_path);
|
m_root_path = canonicalized_path(root_path);
|
||||||
|
|
||||||
if (on_root_path_change)
|
|
||||||
on_root_path_change();
|
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
if (m_root->has_error()) {
|
||||||
|
if (on_error)
|
||||||
|
on_error(m_root->error(), m_root->error_string());
|
||||||
|
} else if (on_complete) {
|
||||||
|
on_complete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSystemModel::update()
|
void FileSystemModel::update()
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCore/Notifier.h>
|
#include <LibCore/Notifier.h>
|
||||||
#include <LibGUI/Model.h>
|
#include <LibGUI/Model.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -79,6 +80,10 @@ public:
|
||||||
bool is_directory() const { return S_ISDIR(mode); }
|
bool is_directory() const { return S_ISDIR(mode); }
|
||||||
bool is_executable() const { return mode & (S_IXUSR | S_IXGRP | S_IXOTH); }
|
bool is_executable() const { return mode & (S_IXUSR | S_IXGRP | S_IXOTH); }
|
||||||
|
|
||||||
|
bool has_error() const { return m_error != 0; }
|
||||||
|
int error() const { return m_error; }
|
||||||
|
const char* error_string() const { return strerror(m_error); }
|
||||||
|
|
||||||
String full_path(const FileSystemModel&) const;
|
String full_path(const FileSystemModel&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -91,6 +96,8 @@ public:
|
||||||
int m_watch_fd { -1 };
|
int m_watch_fd { -1 };
|
||||||
RefPtr<Core::Notifier> m_notifier;
|
RefPtr<Core::Notifier> m_notifier;
|
||||||
|
|
||||||
|
int m_error { 0 };
|
||||||
|
|
||||||
ModelIndex index(const FileSystemModel&, int column) const;
|
ModelIndex index(const FileSystemModel&, int column) const;
|
||||||
void traverse_if_needed(const FileSystemModel&);
|
void traverse_if_needed(const FileSystemModel&);
|
||||||
void reify_if_needed(const FileSystemModel&);
|
void reify_if_needed(const FileSystemModel&);
|
||||||
|
@ -112,7 +119,8 @@ public:
|
||||||
GUI::Icon icon_for_file(const mode_t mode, const String& name) const;
|
GUI::Icon icon_for_file(const mode_t mode, const String& name) const;
|
||||||
|
|
||||||
Function<void(int done, int total)> on_thumbnail_progress;
|
Function<void(int done, int total)> on_thumbnail_progress;
|
||||||
Function<void()> on_root_path_change;
|
Function<void()> on_complete;
|
||||||
|
Function<void(int error, const char* error_string)> on_error;
|
||||||
|
|
||||||
virtual int tree_column() const override { return Column::Name; }
|
virtual int tree_column() const override { return Column::Name; }
|
||||||
virtual int row_count(const ModelIndex& = ModelIndex()) const override;
|
virtual int row_count(const ModelIndex& = ModelIndex()) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue