collect
collect copied to clipboard
Collect crashes when trying to download media file with path as `filename`
Originally reported on the forum.
This only happens with "custom" server implementations as Central won't return filename
with a hierarchical path.
Software and hardware versions
Collect v2021.3, custom server
Problem description
Collect crashes when trying to copy a downloaded media file to the form's media directory if the filename
attribute in the manifest is a path (dir1/dir2/file.extension
) instead of a file name (file.extension
).
Steps to reproduce the problem
- Set up Collect with a server that returns paths in
filename
- Attempt to download a form
Expected behavior
Off the top of my head, there are three options we could go for here:
- Collect could copy the file into the specified path relative to the media dir (
<media dir>/dir1/dir2/file.extension
) - Collect could ignore everything other than the file name and just copy the file into the media dir directly (
<media dir>/file.extension
) - Collect could throw a
FormSourceException.ParseError
when the manifest is fetched - this would probably mean us also updating the spec to make it stricter.
Other information
Stack trace of crash:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.RuntimeException: Could not copy '/storage/emulated/0/Android/data/org.odk.collect.android/files/projects/ac2d95cd-c319-4f58-9a90-3a2f91ccaefc/.cache/download-b7854eef-0a51-4477-9172-47a2677450ac/tag.xml3517133847896120566.tempDownload' over '/storage/emulated/0/Android/data/org.odk.collect.android/files/projects/ac2d95cd-c319-4f58-9a90-3a2f91ccaefc/.cache/download-b7854eef-0a51-4477-9172-47a2677450ac/media/example/terms/tag.xml'. Reason: /storage/emulated/0/Android/data/org.odk.collect.android/files/projects/ac2d95cd-c319-4f58-9a90-3a2f91ccaefc/.cache/download-b7854eef-0a51-4477-9172-47a2677450ac/media/example/terms/tag.xml (No such file or directory)
at org.odk.collect.android.formmanagement.ServerFormDownloader.writeFile(SourceFile:368)
at org.odk.collect.android.formmanagement.ServerFormDownloader.downloadMediaFiles(SourceFile:389)
at org.odk.collect.android.formmanagement.ServerFormDownloader.processOneForm(SourceFile:109)
at org.odk.collect.android.formmanagement.ServerFormDownloader.downloadForm(SourceFile:81)
at org.odk.collect.android.tasks.DownloadFormsTask.doInBackground(SourceFile:62)
at org.odk.collect.android.tasks.DownloadFormsTask.doInBackground(SourceFile:41)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)