| 238 | } |
| 239 | |
| 240 | func (s *FileStore) WriteAt(ctx context.Context, zoneId string, name string, offset int64, data []byte) error { |
| 241 | if offset < 0 { |
| 242 | return fmt.Errorf("offset must be non-negative") |
| 243 | } |
| 244 | return withLock(s, zoneId, name, func(entry *CacheEntry) error { |
| 245 | err := entry.loadFileIntoCache(ctx) |
| 246 | if err != nil { |
| 247 | return err |
| 248 | } |
| 249 | file := entry.File |
| 250 | if offset > file.Size { |
| 251 | return fmt.Errorf("offset is past the end of the file") |
| 252 | } |
| 253 | partMap := file.computePartMap(offset, int64(len(data))) |
| 254 | incompleteParts := incompletePartsFromMap(partMap) |
| 255 | err = entry.loadDataPartsIntoCache(ctx, incompleteParts) |
| 256 | if err != nil { |
| 257 | return err |
| 258 | } |
| 259 | entry.writeAt(offset, data, false) |
| 260 | return nil |
| 261 | }) |
| 262 | } |
| 263 | |
| 264 | func (s *FileStore) AppendData(ctx context.Context, zoneId string, name string, data []byte) error { |
| 265 | return withLock(s, zoneId, name, func(entry *CacheEntry) error { |