Skip to content
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

Docs and errors about keys with slashes #2725

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/IPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ The specific implementations of the `DriverPublisher` interface and `DriverSubsc
##### `socketdriver.Publisher` Updates

When `socketdriver.Publisher` receives updates from its calling `pubsub.Publication`, it saves the data in a file, whose name is determined
as `<dirName>/<key>.json`.
as `<dirName>/<key>.json`. Key must not contain slashes and should fit max filesize limit (not exceed 255 symbols).

For example, if the `<dirName>` from above was `/persist/tester/configmgr/inputs/`, and the `Publish()` used the key `important`, then
the filename is `/persist/tester/configmgr/inputs/important.json`.
Expand Down
9 changes: 9 additions & 0 deletions pkg/pillar/pubsub/socketdriver/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,20 @@ type Publisher struct {
rootDir string
}

const maxFileName = 255

// Publish publish a key-value pair
func (s *Publisher) Publish(key string, item []byte) error {
if len(item) == 0 {
return fmt.Errorf("empty content published for %s/%s", s.name, key)
}
if strings.Contains(key, "/") {
return fmt.Errorf("key(%s) must not contain slashes", key)
}
if len(key+".json") > maxFileName {
return fmt.Errorf("key(%s) exceed maximum filename limit of %d bytes: %d",
key, maxFileName, len(key+".json"))
}
fileName := s.dirName + "/" + key + ".json"
s.log.Tracef("Publish writing %s\n", fileName)

Expand Down