Skip to content

Commit b21981a

Browse files
committed
Add comments to explain why openAndTruncateStream()
1 parent df94167 commit b21981a

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/subscription/services/SubscriptionsExportService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
7676

7777
try {
7878
outFile = new StoredFileHelper(this, path, "application/json");
79+
// truncate the file before writing to it, otherwise if the new content is smaller than
80+
// the previous file size, the file will retain part of the previous content and be
81+
// corrupted
7982
outputStream = new SharpOutputStream(outFile.openAndTruncateStream());
8083
} catch (final IOException e) {
8184
handleError(e);

app/src/main/java/org/schabi/newpipe/settings/export/ImportExportManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
2424
*/
2525
@Throws(Exception::class)
2626
fun exportDatabase(preferences: SharedPreferences, file: StoredFileHelper) {
27+
// truncate the file before writing to it, otherwise if the new content is smaller than the
28+
// previous file size, the file will retain part of the previous content and be corrupted
2729
ZipOutputStream(SharpOutputStream(file.openAndTruncateStream()).buffered()).use { outZip ->
2830
// add the database
2931
ZipHelper.addFileToZip(

0 commit comments

Comments
 (0)