Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Fix DirAccess::unlink() not updating the IDBFS #100221

Merged
merged 1 commit into from
Jan 3, 2025
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
14 changes: 12 additions & 2 deletions drivers/unix/dir_access_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,19 @@ Error DirAccessUnix::remove(String p_path) {
return FAILED;
}

int err;
if (S_ISDIR(flags.st_mode) && !is_link(p_path)) {
return ::rmdir(p_path.utf8().get_data()) == 0 ? OK : FAILED;
err = ::rmdir(p_path.utf8().get_data());
} else {
return ::unlink(p_path.utf8().get_data()) == 0 ? OK : FAILED;
err = ::unlink(p_path.utf8().get_data());
}
if (err != 0) {
return FAILED;
}
if (remove_notification_func != nullptr) {
remove_notification_func(p_path);
}
return OK;
}

bool DirAccessUnix::is_link(String p_file) {
Expand Down Expand Up @@ -552,6 +560,8 @@ DirAccessUnix::DirAccessUnix() {
change_dir(current_dir);
}

DirAccessUnix::RemoveNotificationFunc DirAccessUnix::remove_notification_func = nullptr;

DirAccessUnix::~DirAccessUnix() {
list_dir_end();
}
Expand Down
3 changes: 3 additions & 0 deletions drivers/unix/dir_access_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class DirAccessUnix : public DirAccess {
virtual bool is_hidden(const String &p_name);

public:
typedef void (*RemoveNotificationFunc)(const String &p_file);
static RemoveNotificationFunc remove_notification_func;

virtual Error list_dir_begin() override; ///< This starts dir listing
virtual String get_next() override;
virtual bool current_is_dir() const override;
Expand Down
2 changes: 1 addition & 1 deletion drivers/unix/file_access_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void FileAccessUnix::close() {
_close();
}

CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr;
FileAccessUnix::CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr;

FileAccessUnix::~FileAccessUnix() {
_close();
Expand Down
3 changes: 1 addition & 2 deletions drivers/unix/file_access_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

#if defined(UNIX_ENABLED)

typedef void (*CloseNotificationFunc)(const String &p_file, int p_flags);

class FileAccessUnix : public FileAccess {
FILE *f = nullptr;
int flags = 0;
Expand All @@ -56,6 +54,7 @@ class FileAccessUnix : public FileAccess {
#endif

public:
typedef void (*CloseNotificationFunc)(const String &p_file, int p_flags);
static CloseNotificationFunc close_notification_func;

virtual Error open_internal(const String &p_path, int p_mode_flags) override; ///< open a file
Expand Down
13 changes: 13 additions & 0 deletions platform/web/os_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ void OS_Web::file_access_close_callback(const String &p_file, int p_flags) {
}
}

void OS_Web::dir_access_remove_callback(const String &p_file) {
OS_Web *os = OS_Web::get_singleton();
bool is_file_persistent = p_file.begins_with("/userfs");
#ifdef TOOLS_ENABLED
// Hack for editor persistence (can we track).
is_file_persistent = is_file_persistent || p_file.begins_with("/home/web_user/");
#endif
if (is_file_persistent) {
os->idb_needs_sync = true;
}
}

void OS_Web::update_pwa_state_callback() {
if (OS_Web::get_singleton()) {
OS_Web::get_singleton()->pwa_is_waiting = true;
Expand Down Expand Up @@ -287,4 +299,5 @@ OS_Web::OS_Web() {
_set_logger(memnew(CompositeLogger(loggers)));

FileAccessUnix::close_notification_func = file_access_close_callback;
DirAccessUnix::remove_notification_func = dir_access_remove_callback;
}
1 change: 1 addition & 0 deletions platform/web/os_web.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class OS_Web : public OS_Unix {
WASM_EXPORT static void main_loop_callback();

WASM_EXPORT static void file_access_close_callback(const String &p_file, int p_flags);
WASM_EXPORT static void dir_access_remove_callback(const String &p_file);
WASM_EXPORT static void fs_sync_callback();
WASM_EXPORT static void update_pwa_state_callback();

Expand Down
Loading