diff --git a/BasiliskII/src/AmigaOS/extfs_amiga.cpp b/BasiliskII/src/AmigaOS/extfs_amiga.cpp index 4216d473..2d6aaf68 100644 --- a/BasiliskII/src/AmigaOS/extfs_amiga.cpp +++ b/BasiliskII/src/AmigaOS/extfs_amiga.cpp @@ -365,6 +365,31 @@ size_t extfs_write(int fd, void *buffer, size_t length) } +/* + * Remove file/directory (and associated helper files), + * returns false on error (and sets errno) + */ + +bool extfs_remove(const char *path) +{ + // Remove helpers first, don't complain if this fails + char helper_path[MAX_PATH_LENGTH]; + make_helper_path(path, helper_path, ".finf/", false); + remove(helper_path); + make_helper_path(path, helper_path, ".rsrc/", false); + remove(helper_path); + + // Now remove file or directory + if (remove(path) < 0) { + if (errno == EISDIR) + return rmdir(path) == 0; + else + return false; + } + return true; +} + + /* * ftruncate() is missing from libnix */ diff --git a/BasiliskII/src/BeOS/extfs_beos.cpp b/BasiliskII/src/BeOS/extfs_beos.cpp index 625705f5..606e0657 100644 --- a/BasiliskII/src/BeOS/extfs_beos.cpp +++ b/BasiliskII/src/BeOS/extfs_beos.cpp @@ -455,3 +455,19 @@ size_t extfs_write(int fd, void *buffer, size_t length) } return actual; } + + +/* + * Remove file/directory, returns false on error (and sets errno) + */ + +bool extfs_remove(const char *path) +{ + if (remove(path) < 0) { + if (errno == EISDIR) + return rmdir(path) == 0; + else + return false; + } + return true; +} diff --git a/BasiliskII/src/Unix/extfs_unix.cpp b/BasiliskII/src/Unix/extfs_unix.cpp index f03107e0..de926553 100644 --- a/BasiliskII/src/Unix/extfs_unix.cpp +++ b/BasiliskII/src/Unix/extfs_unix.cpp @@ -368,3 +368,28 @@ size_t extfs_write(int fd, void *buffer, size_t length) errno = 0; return write(fd, buffer, length); } + + +/* + * Remove file/directory (and associated helper files), + * returns false on error (and sets errno) + */ + +bool extfs_remove(const char *path) +{ + // Remove helpers first, don't complain if this fails + char helper_path[MAX_PATH_LENGTH]; + make_helper_path(path, helper_path, ".finf/", false); + remove(helper_path); + make_helper_path(path, helper_path, ".rsrc/", false); + remove(helper_path); + + // Now remove file or directory + if (remove(path) < 0) { + if (errno == EISDIR) + return rmdir(path) == 0; + else + return false; + } + return true; +} diff --git a/BasiliskII/src/extfs.cpp b/BasiliskII/src/extfs.cpp index 674c918c..c01c84fa 100644 --- a/BasiliskII/src/extfs.cpp +++ b/BasiliskII/src/extfs.cpp @@ -1898,16 +1898,9 @@ static int16 fs_delete(uint32 pb, uint32 dirID) return result; // Delete file - if (remove(full_path) < 0) { - int16 err = errno2oserr(); - if (errno == EISDIR) { // Workaround for BeOS bug - if (rmdir(full_path) < 0) - return errno2oserr(); - else - return noErr; - } else - return err; - } else + if (!extfs_remove(full_path)) + return errno2oserr(); + else return noErr; } diff --git a/BasiliskII/src/include/extfs.h b/BasiliskII/src/include/extfs.h index 6f7d3d71..897ec06b 100644 --- a/BasiliskII/src/include/extfs.h +++ b/BasiliskII/src/include/extfs.h @@ -42,6 +42,7 @@ extern int open_rfork(const char *path, int flag); extern void close_rfork(const char *path, int fd); extern size_t extfs_read(int fd, void *buffer, size_t length); extern size_t extfs_write(int fd, void *buffer, size_t length); +extern bool extfs_remove(const char *path); // Maximum length of full path name const int MAX_PATH_LENGTH = 1024;