Skip to content

Add sync watcher and conflict resolution spec#20

Open
Intina47 wants to merge 1 commit into
mainfrom
mamba/implement-filesystem-watcher-and-conflict-spec
Open

Add sync watcher and conflict resolution spec#20
Intina47 wants to merge 1 commit into
mainfrom
mamba/implement-filesystem-watcher-and-conflict-spec

Conversation

@Intina47
Copy link
Copy Markdown
Owner

Motivation

  • Enable safe sync by adding a local filesystem watcher to detect changes to note files for sync operations.
  • Define a deterministic conflict resolution policy (last-write-wins with preserved conflict copies) so concurrent edits are recoverable.

Description

  • Add watcher.go which implements a polling Watcher with NewWatcher, Poll, Start, and snapshotDir, emitting FileEvent values for create, modify, and delete with deterministic ordering using sort.Slice.
  • Add watcher_test.go to validate detection of create/modify/delete transitions using Poll in a temporary directory.
  • Add sync_conflicts.go with conflictCopyPath that produces deterministic conflict filenames of the form <original>.conflict-<UTC timestamp>-<actor id> (actor defaults to unknown).
  • Add sync_conflicts_test.go to assert conflict filename formatting and default actor behavior, and add docs/sync-conflicts.md documenting conflict detection and the last-write-wins + conflict-copy policy.

Testing

  • Ran the full test suite with go test ./... and all tests passed.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2663d05941

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sync_conflicts.go
Comment on lines +13 to +15
timestamp := conflictAt.UTC().Format("20060102T150405Z")
filename := fmt.Sprintf("%s.conflict-%s-%s", filepath.Base(originalPath), timestamp, actorID)
return filepath.Join(filepath.Dir(originalPath), filename)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Sanitize actorID to prevent path traversal

Because actorID is interpolated directly into filename and then passed to filepath.Join, any actor ID containing path separators (e.g., ../ or ..\) will be treated as path components and can escape the note directory after path cleaning. This allows a remote sync client identifier to place conflict copies outside the intended directory (or overwrite unrelated files) instead of always writing alongside the original. Consider normalizing actorID to a safe character set (e.g., replacing path separators with _) before building the filename.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant