Skip to content

fix: backup fails with 'illegal seek' when a content provider URI is selected - #1176

Open
mvanhorn wants to merge 1 commit into
UweTrottmann:devfrom
mvanhorn:fix/1089-seriesguide-backup-illegal-seek
Open

fix: backup fails with 'illegal seek' when a content provider URI is selected#1176
mvanhorn wants to merge 1 commit into
UweTrottmann:devfrom
mvanhorn:fix/1089-seriesguide-backup-illegal-seek

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jul 9, 2026

Copy link
Copy Markdown

Summary

Backing up to a location backed by a content provider (e.g. a cloud storage document) fails with "illegal seek". JsonExportTask truncated the export file via FileOutputStream.channel.truncate(), which requires a seekable file descriptor; pipe-backed descriptors from content providers are not seekable. Export and auto backup now truncate through ParcelFileDescriptor.openFileDescriptor(uri, "wt") semantics: a new openFileForOverwrite helper opens the descriptor for write-truncate and only falls back to channel truncation for plain seekable files.

Why this matters

The reporter in #1089 hit this when selecting a backup destination provided by a cloud storage app:

backup fails immediately with "illegal seek" after choosing the folder

Local file destinations mask the bug because their descriptors are seekable, so the failure only shows up for content-provider URIs, which is exactly the case the storage access framework encourages. Auto backup shares the same write path, so a failing destination also silently breaks scheduled backups until the user re-picks a folder.

Testing

Added JVM unit tests in JsonExportTaskTest covering the overwrite helper: truncation for seekable descriptors, the write-truncate path for non-seekable descriptors, and that export output is written through the returned stream. (Full Android instrumentation was not run; the change is confined to the data liberation write path.)

Fixes #1089

@UweTrottmann UweTrottmann added this to the 2026.3 milestone Jul 10, 2026
@UweTrottmann

Copy link
Copy Markdown
Owner

Thanks for the tip on the open mode!

I likely won't be merging as-is as this doesn't follow contribution guidelines and also I am currently making significant changes to the import and export logic.

Also, was any of this created using a coding tool?

@mvanhorn

Copy link
Copy Markdown
Author

Yes, AI tooling was involved - I use Claude to help investigate and draft fixes, with me directing and reviewing the changes. Happy to be upfront about that, and apologies for missing the contribution guidelines. Given you're reworking the import/export logic anyway, feel free to close this and just carry the open-mode detail into your rework if it's useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backup will fail if a content provider is selected for creating copies

2 participants