Skip to content

Commit a6c5373

Browse files
committed
[Web] Fix DirAccess::unlink() not updating the IDBFS
1 parent aa8d9b8 commit a6c5373

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

drivers/unix/dir_access_unix.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,19 @@ Error DirAccessUnix::remove(String p_path) {
438438
return FAILED;
439439
}
440440

441+
int err;
441442
if (S_ISDIR(flags.st_mode) && !is_link(p_path)) {
442-
return ::rmdir(p_path.utf8().get_data()) == 0 ? OK : FAILED;
443+
err = ::rmdir(p_path.utf8().get_data());
443444
} else {
444-
return ::unlink(p_path.utf8().get_data()) == 0 ? OK : FAILED;
445+
err = ::unlink(p_path.utf8().get_data());
445446
}
447+
if (err != 0) {
448+
return FAILED;
449+
}
450+
if (remove_notification_func != nullptr) {
451+
remove_notification_func(p_path);
452+
}
453+
return OK;
446454
}
447455

448456
bool DirAccessUnix::is_link(String p_file) {
@@ -552,6 +560,8 @@ DirAccessUnix::DirAccessUnix() {
552560
change_dir(current_dir);
553561
}
554562

563+
DirAccessUnix::RemoveNotificationFunc DirAccessUnix::remove_notification_func = nullptr;
564+
555565
DirAccessUnix::~DirAccessUnix() {
556566
list_dir_end();
557567
}

drivers/unix/dir_access_unix.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class DirAccessUnix : public DirAccess {
5252
virtual bool is_hidden(const String &p_name);
5353

5454
public:
55+
typedef void (*RemoveNotificationFunc)(const String &p_file);
56+
static RemoveNotificationFunc remove_notification_func;
57+
5558
virtual Error list_dir_begin() override; ///< This starts dir listing
5659
virtual String get_next() override;
5760
virtual bool current_is_dir() const override;

drivers/unix/file_access_unix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ void FileAccessUnix::close() {
443443
_close();
444444
}
445445

446-
CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr;
446+
FileAccessUnix::CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr;
447447

448448
FileAccessUnix::~FileAccessUnix() {
449449
_close();

drivers/unix/file_access_unix.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838

3939
#if defined(UNIX_ENABLED)
4040

41-
typedef void (*CloseNotificationFunc)(const String &p_file, int p_flags);
42-
4341
class FileAccessUnix : public FileAccess {
4442
FILE *f = nullptr;
4543
int flags = 0;
@@ -56,6 +54,7 @@ class FileAccessUnix : public FileAccess {
5654
#endif
5755

5856
public:
57+
typedef void (*CloseNotificationFunc)(const String &p_file, int p_flags);
5958
static CloseNotificationFunc close_notification_func;
6059

6160
virtual Error open_internal(const String &p_path, int p_mode_flags) override; ///< open a file

platform/web/os_web.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ void OS_Web::file_access_close_callback(const String &p_file, int p_flags) {
224224
}
225225
}
226226

227+
void OS_Web::dir_access_remove_callback(const String &p_file) {
228+
OS_Web *os = OS_Web::get_singleton();
229+
bool is_file_persistent = p_file.begins_with("/userfs");
230+
#ifdef TOOLS_ENABLED
231+
// Hack for editor persistence (can we track).
232+
is_file_persistent = is_file_persistent || p_file.begins_with("/home/web_user/");
233+
#endif
234+
if (is_file_persistent) {
235+
os->idb_needs_sync = true;
236+
}
237+
}
238+
227239
void OS_Web::update_pwa_state_callback() {
228240
if (OS_Web::get_singleton()) {
229241
OS_Web::get_singleton()->pwa_is_waiting = true;
@@ -287,4 +299,5 @@ OS_Web::OS_Web() {
287299
_set_logger(memnew(CompositeLogger(loggers)));
288300

289301
FileAccessUnix::close_notification_func = file_access_close_callback;
302+
DirAccessUnix::remove_notification_func = dir_access_remove_callback;
290303
}

platform/web/os_web.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class OS_Web : public OS_Unix {
5353
WASM_EXPORT static void main_loop_callback();
5454

5555
WASM_EXPORT static void file_access_close_callback(const String &p_file, int p_flags);
56+
WASM_EXPORT static void dir_access_remove_callback(const String &p_file);
5657
WASM_EXPORT static void fs_sync_callback();
5758
WASM_EXPORT static void update_pwa_state_callback();
5859

0 commit comments

Comments
 (0)