garmin: relax FIT filename rules for Descent Mk1

When on the actual watch, the filename format for the FIT files ends up
being something like

    2018-09-21-10-23-36.fit

but then if you download the activity from the Garmin Connect activity
website, it might show up as a ZIP file that contains a file named
something like

    3030954326.fit

instead.

In order to make it easy to import these fit files that have been
downloaded from the Garmin cloud, relax the filename rules a bit.

NOTE! You still need to have the proper directory structure, and put
your FIT files in a subdirectory like

  <some path>/Garmin/Activity/

to match the way the FIT files show up when you mount the Garmin Descent
locally.  You can then point subsurface to <some path> when you do a
"download" from the Garmin Descent, regardless of whether it's an actual
case of the dive computer being mounted, or if you've downloaded the FIT
files to your local filesystem.

Reported-by: Andrew Trevor-Jones <atj777atj777@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2018-09-21 14:21:35 -07:00
parent fb70928c83
commit 6f377182f5

View File

@ -130,8 +130,11 @@ static int get_file_list(DIR *dir, struct file_list *files)
while ((de = readdir(dir)) != NULL) {
int len = strlen(de->d_name);
struct fit_name *entry;
if (len != FIT_NAME_SIZE-1)
if (len < 5)
continue;
if (len >= FIT_NAME_SIZE)
continue;
if (strncasecmp(de->d_name + len - 4, ".FIT", 4))
continue;
@ -150,7 +153,14 @@ static int get_file_list(DIR *dir, struct file_list *files)
files->allocated = n;
}
memcpy(files->array + files->nr++, de->d_name, FIT_NAME_SIZE);
/*
* NOTE! This depends on the zero-padding that strncpy does.
*
* strncpy() doesn't just limit the size of the copy, it
* will zero-pad the end of the result buffer.
*/
entry = files->array + files->nr++;
strncpy(entry->name, de->d_name, FIT_NAME_SIZE);
}
qsort(files->array, files->nr, sizeof(struct fit_name), name_cmp);