Add sync watcher and conflict resolution spec#20
Conversation
There was a problem hiding this comment.
💡 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".
| timestamp := conflictAt.UTC().Format("20060102T150405Z") | ||
| filename := fmt.Sprintf("%s.conflict-%s-%s", filepath.Base(originalPath), timestamp, actorID) | ||
| return filepath.Join(filepath.Dir(originalPath), filename) |
There was a problem hiding this comment.
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 👍 / 👎.
Motivation
Description
watcher.gowhich implements a pollingWatcherwithNewWatcher,Poll,Start, andsnapshotDir, emittingFileEventvalues forcreate,modify, anddeletewith deterministic ordering usingsort.Slice.watcher_test.goto validate detection of create/modify/delete transitions usingPollin a temporary directory.sync_conflicts.gowithconflictCopyPaththat produces deterministic conflict filenames of the form<original>.conflict-<UTC timestamp>-<actor id>(actor defaults tounknown).sync_conflicts_test.goto assert conflict filename formatting and default actor behavior, and adddocs/sync-conflicts.mddocumenting conflict detection and the last-write-wins + conflict-copy policy.Testing
go test ./...and all tests passed.Codex Task