static fssh_status_t remove_entry(int dir, const char *entry, bool recursive, bool force) { // stat the file struct fssh_stat st; fssh_status_t error = _kern_read_stat(dir, entry, false, &st, sizeof(st)); if (error != FSSH_B_OK) { if (force && error == FSSH_B_ENTRY_NOT_FOUND) return FSSH_B_OK; fprintf(stderr, "Error: Failed to remove \"%s\": %s\n", entry, fssh_strerror(error)); return error; } if (FSSH_S_ISDIR(st.fssh_st_mode)) { if (!recursive) { fprintf(stderr, "Error: \"%s\" is a directory.\n", entry); // TODO: get the full path return FSSH_EISDIR; } // remove the contents error = remove_dir_contents(dir, entry, force); if (error != FSSH_B_OK) return error; // remove the directory error = _kern_remove_dir(dir, entry); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to remove directory \"%s\": %s\n", entry, fssh_strerror(error)); return error; } } else { // remove the entry error = _kern_unlink(dir, entry); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to remove entry \"%s\": %s\n", entry, fssh_strerror(error)); return error; } } return FSSH_B_OK; }
static int fuse_rmdir(const char* path) { PRINTD("##rmdir\n"); return _ERR(_kern_remove_dir(-1, path)); }