-
Notifications
You must be signed in to change notification settings - Fork 6
[AUTOMATION] fix(clawpatch): address daily finding #290
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,7 +440,8 @@ func readClaudeSettings() (string, map[string]any, error) { | |
| } | ||
|
|
||
| func backupFile(path, label string) error { | ||
| if _, err := os.Stat(path); os.IsNotExist(err) { | ||
| mode, err := fileModeOrDefault(path, 0o600) | ||
| if os.IsNotExist(err) { | ||
| return nil | ||
| } else if err != nil { | ||
| return err | ||
|
|
@@ -450,16 +451,28 @@ func backupFile(path, label string) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| return os.WriteFile(backupPath, input, 0o644) | ||
| return os.WriteFile(backupPath, input, mode) | ||
| } | ||
|
|
||
| func writeJSONFile(path string, value any) error { | ||
| mode, err := fileModeOrDefault(path, 0o600) | ||
| if err != nil && !os.IsNotExist(err) { | ||
| return err | ||
| } | ||
| bytes, err := json.MarshalIndent(value, "", " ") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| bytes = append(bytes, '\n') | ||
| return os.WriteFile(path, bytes, 0o644) | ||
| return os.WriteFile(path, bytes, mode) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| func fileModeOrDefault(path string, fallback os.FileMode) (os.FileMode, error) { | ||
| info, err := os.Stat(path) | ||
| if err != nil { | ||
| return fallback, err | ||
| } | ||
| return info.Mode().Perm(), nil | ||
| } | ||
|
|
||
| func mergeHooks(raw any, hookCommand string) map[string]any { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backup filename has only second-level precision, and this write overwrites an existing backup if two hook operations run in the same second. Since
os.WriteFiledoes not chmod an existing file, a colliding backup that was first created with broader permissions can stay broad even when this call computes0600; it can also replace the earlier backup contents.