(data []byte, key ...string)
| 166 | } |
| 167 | |
| 168 | func (vs *fileStore) Set(data []byte, key ...string) error { |
| 169 | if vs.locked == nil { |
| 170 | return errors.Join(ErrFaultyImplementation, fmt.Errorf("operations on the store must use locking")) |
| 171 | } |
| 172 | |
| 173 | if err := validateAllPathComponents(key...); err != nil { |
| 174 | return err |
| 175 | } |
| 176 | |
| 177 | fileName := key[len(key)-1] |
| 178 | parent := vs.dir |
| 179 | |
| 180 | if len(key) > 1 { |
| 181 | parent = filepath.Join(append([]string{parent}, key[0:len(key)-1]...)...) |
| 182 | err := os.MkdirAll(parent, vs.dirPerm) |
| 183 | if err != nil { |
| 184 | return errors.Join(ErrSystemFailure, err) |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | dest := filepath.Join(parent, fileName) |
| 189 | st, err := os.Stat(dest) |
| 190 | if err == nil { |
| 191 | if st.IsDir() { |
| 192 | return errors.Join(ErrFaultyImplementation, fmt.Errorf("%q is a directory and cannot be written to", dest)) |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if err := filesystem.WriteFileWithRename(filepath.Join(parent, fileName), data, vs.filePerm); err != nil { |
| 197 | return errors.Join(ErrSystemFailure, err) |
| 198 | } |
| 199 | |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | func (vs *fileStore) List(key ...string) ([]string, error) { |
| 204 | if vs.locked == nil { |
nothing calls this directly
no test coverage detected