Skip to content

Fix: Prevent duplicate sync markers when syncing to markdown file#134

Merged
yogeshpaliyal merged 2 commits intomasterfrom
copilot/fix-41b4cbc5-85c9-4709-ada5-3647d2202b3f
Oct 2, 2025
Merged

Fix: Prevent duplicate sync markers when syncing to markdown file#134
yogeshpaliyal merged 2 commits intomasterfrom
copilot/fix-41b4cbc5-85c9-4709-ada5-3647d2202b3f

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 2, 2025

Problem

When syncing deeplinks to a markdown file multiple times, especially after deleting deeplinks from the app, the sync operation would append content to the existing file instead of overwriting it. This caused:

  • Multiple <!-- End of Deepr Sync Data --> markers appearing in the file
  • Orphaned deeplink data from previous syncs remaining in the file
  • Duplicate headers and table structures
  • Corrupted markdown file structure

Example of the bug:

After first sync with 3 deeplinks, then deleting 2 deeplinks and syncing again:

<!-- Headers and data from first sync -->
| Link1 | ... |
| Link2 | ... |  ⚠️ Deleted but still in file
| Link3 | ... |  ⚠️ Deleted but still in file
<!-- End of Deepr Sync Data -->

<!-- Headers and data from second sync (appended) -->
| Link1 | ... |
<!-- End of Deepr Sync Data -->  ⚠️ Duplicate marker

Root Cause

The ContentResolver.openOutputStream(Uri) method without a mode parameter opens the output stream in append mode by default. This caused each sync operation to add new content to the end of the existing file rather than replacing it.

Solution

Changed line 38 in SyncRepositoryImpl.kt to use the two-parameter version of openOutputStream() with the "wt" mode (write-truncate):

- context.contentResolver.openOutputStream(filePath.toUri())?.use {
+ context.contentResolver.openOutputStream(filePath.toUri(), "wt")?.use {

The "wt" mode explicitly truncates (clears) the file before writing, ensuring a clean write operation that completely replaces the file content on each sync.

Impact

  • ✅ Minimal change: 1 line, 5 characters added
  • ✅ No breaking changes or side effects
  • ✅ Directly addresses the root cause
  • ✅ Each sync now produces a clean file with current data only

Testing

To verify the fix:

  1. Sync deeplinks to a markdown file
  2. Delete some deeplinks from the app
  3. Sync again
  4. Verify the file contains only current deeplinks with exactly one <!-- End of Deepr Sync Data --> marker

Fixes the issue described in the original report where duplicate end markers were created between multiple sync operations.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/gradle-daemon-main-8.13.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/agents/gradle-instrumentation-agent-8.13.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.13 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>If you sync to .md then delete deeplink(s) and sync again, the link is not fully removed but...</issue_title>
<issue_description>It creates a new <!-- End of Deepr Sync Data --> and writes part of the deeplink between the now 2 <!-- End of Deepr Sync Data --></issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #121

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

… duplicate markers

Co-authored-by: yogeshpaliyal <9381846+yogeshpaliyal@users.noreply.github.com>
Copilot AI changed the title [WIP] If you sync to .md then delete deeplink(s) and sync again, the link is not fully removed but... Fix: Prevent duplicate sync markers when syncing to markdown file Oct 2, 2025
Copilot AI requested a review from yogeshpaliyal October 2, 2025 10:22
@yogeshpaliyal yogeshpaliyal marked this pull request as ready for review October 2, 2025 12:28
@yogeshpaliyal yogeshpaliyal merged commit c74998a into master Oct 2, 2025
1 check passed
@yogeshpaliyal yogeshpaliyal deleted the copilot/fix-41b4cbc5-85c9-4709-ada5-3647d2202b3f branch October 2, 2025 12:28
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.

If you sync to .md then delete deeplink(s) and sync again, the link is not fully removed but...

2 participants