Skip to content

Commit 64ed86a

Browse files
tridgepeterbarker
authored andcommitted
GCS_MAVLINK: cope with dirent not having dtype
1 parent c2e52af commit 64ed86a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

libraries/GCS_MAVLink/GCS_FTP.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -588,16 +588,23 @@ void GCS_MAVLINK::ftp_worker(void) {
588588

589589
// calculates how much string length is needed to fit this in a list response
590590
int GCS_MAVLINK::gen_dir_entry(char *dest, size_t space, const char *path, const struct dirent * entry) {
591+
#if AP_FILESYSTEM_HAVE_DIRENT_DTYPE
591592
const bool is_file = entry->d_type == DT_REG || entry->d_type == DT_LNK;
593+
#else
594+
// assume true initially, then handle below
595+
const bool is_file = true;
596+
#endif
592597

593598
if (space < 3) {
594599
return -1;
595600
}
596601
dest[0] = 0;
597602

603+
#if AP_FILESYSTEM_HAVE_DIRENT_DTYPE
598604
if (!is_file && entry->d_type != DT_DIR) {
599605
return -1; // this just forces it so we can't send this back, it's easier then sending skips to a GCS
600606
}
607+
#endif
601608

602609
if (is_file) {
603610
#ifdef MAX_NAME_LEN
@@ -612,6 +619,12 @@ int GCS_MAVLINK::gen_dir_entry(char *dest, size_t space, const char *path, const
612619
if (AP::FS().stat(full_path, &st)) {
613620
return -1;
614621
}
622+
623+
#if !AP_FILESYSTEM_HAVE_DIRENT_DTYPE
624+
if (S_ISDIR(st.st_mode)) {
625+
return hal.util->snprintf(dest, space, "D%s%c", entry->d_name, (char)0);
626+
}
627+
#endif
615628
return hal.util->snprintf(dest, space, "F%s\t%u%c", entry->d_name, (unsigned)st.st_size, (char)0);
616629
} else {
617630
return hal.util->snprintf(dest, space, "D%s%c", entry->d_name, (char)0);

0 commit comments

Comments
 (0)