Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix downloading/exporting when overwriting file would not truncate #11745

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

Stypox
Copy link
Member

@Stypox Stypox commented Nov 24, 2024

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

This PR adds a method to open a file and immediately truncate it: openAndTruncateStream(). Database and subscription exports previously did not truncate the file before writing to it, resulting in corrupted files like in #7802 when the new content is shorter than the previous content. I looked at how the Downloader interacts with files, but the downloader correctly sets the length of the file before writing to it, so I did not change anything there. I tested on my phone (Android 13 SAF) and on API 22 emulated (SAF and NNFP) and it worked in both.

Fixes the following issue(s)

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.

Due diligence

@github-actions github-actions bot added the size/small PRs with less than 50 changed lines label Nov 24, 2024
Copy link
Contributor

@TobiGr TobiGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'd love to see some comments explainig why the file needs to be truncated. Otherwise this fix might be removed by accident at a later point in time.

@TobiGr
Copy link
Contributor

TobiGr commented Nov 27, 2024

Test is failing:

> Task :app:testDebugUnitTest

ImportExportManagerTest > The settings must be exported successfully in the correct format FAILED
    java.lang.NullPointerException at ImportExportManagerTest.kt:59

@Stypox
Copy link
Member Author

Stypox commented Nov 27, 2024

@TobiGr fixed, I just had to mock a different method in the test, now all tests pass. Also, I added the comments you requested.

Copy link

sonarqubecloud bot commented Nov 27, 2024

@Stypox
Copy link
Member Author

Stypox commented Nov 27, 2024

image
The SonarCloud analysis is wrong in this case, since the error is caught (and rethrown) to be able to properly close the stream, and every error should be caught, not just Exceptions.

@TobiGr
Copy link
Contributor

TobiGr commented Nov 27, 2024

I copied your comment to sonarcloud and marked the warning as false positive.

@TobiGr TobiGr merged commit c6b8bcf into TeamNewPipe:dev Nov 27, 2024
6 checks passed
@ShareASmile ShareASmile added bug Issue is related to a bug import/export labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is related to a bug import/export size/small PRs with less than 50 changed lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot import from previous export
3 participants