GCS_MAVLINK: cope with dirent not having dtype

This commit is contained in:
Andrew Tridgell 2024-07-06 09:42:28 +10:00 committed by Peter Barker
parent c2e52af1e2
commit 64ed86a82e
1 changed files with 13 additions and 0 deletions

View File

@ -588,16 +588,23 @@ void GCS_MAVLINK::ftp_worker(void) {
// calculates how much string length is needed to fit this in a list response
int GCS_MAVLINK::gen_dir_entry(char *dest, size_t space, const char *path, const struct dirent * entry) {
#if AP_FILESYSTEM_HAVE_DIRENT_DTYPE
const bool is_file = entry->d_type == DT_REG || entry->d_type == DT_LNK;
#else
// assume true initially, then handle below
const bool is_file = true;
#endif
if (space < 3) {
return -1;
}
dest[0] = 0;
#if AP_FILESYSTEM_HAVE_DIRENT_DTYPE
if (!is_file && entry->d_type != DT_DIR) {
return -1; // this just forces it so we can't send this back, it's easier then sending skips to a GCS
}
#endif
if (is_file) {
#ifdef MAX_NAME_LEN
@ -612,6 +619,12 @@ int GCS_MAVLINK::gen_dir_entry(char *dest, size_t space, const char *path, const
if (AP::FS().stat(full_path, &st)) {
return -1;
}
#if !AP_FILESYSTEM_HAVE_DIRENT_DTYPE
if (S_ISDIR(st.st_mode)) {
return hal.util->snprintf(dest, space, "D%s%c", entry->d_name, (char)0);
}
#endif
return hal.util->snprintf(dest, space, "F%s\t%u%c", entry->d_name, (unsigned)st.st_size, (char)0);
} else {
return hal.util->snprintf(dest, space, "D%s%c", entry->d_name, (char)0);