synchronous (does not interact with the cache)
(ctx context.Context, zoneId string, name string, meta wshrpc.FileMeta, opts wshrpc.FileOpts)
| 113 | |
| 114 | // synchronous (does not interact with the cache) |
| 115 | func (s *FileStore) MakeFile(ctx context.Context, zoneId string, name string, meta wshrpc.FileMeta, opts wshrpc.FileOpts) error { |
| 116 | if opts.MaxSize < 0 { |
| 117 | return fmt.Errorf("max size must be non-negative") |
| 118 | } |
| 119 | if opts.Circular && opts.MaxSize <= 0 { |
| 120 | return fmt.Errorf("circular file must have a max size") |
| 121 | } |
| 122 | if opts.Circular && opts.IJson { |
| 123 | return fmt.Errorf("circular file cannot be ijson") |
| 124 | } |
| 125 | if opts.Circular { |
| 126 | if opts.MaxSize%partDataSize != 0 { |
| 127 | opts.MaxSize = (opts.MaxSize/partDataSize + 1) * partDataSize |
| 128 | } |
| 129 | } |
| 130 | if opts.IJsonBudget > 0 && !opts.IJson { |
| 131 | return fmt.Errorf("ijson budget requires ijson") |
| 132 | } |
| 133 | if opts.IJsonBudget < 0 { |
| 134 | return fmt.Errorf("ijson budget must be non-negative") |
| 135 | } |
| 136 | return withLock(s, zoneId, name, func(entry *CacheEntry) error { |
| 137 | if entry.File != nil { |
| 138 | return fs.ErrExist |
| 139 | } |
| 140 | now := time.Now().UnixMilli() |
| 141 | file := &WaveFile{ |
| 142 | ZoneId: zoneId, |
| 143 | Name: name, |
| 144 | Size: 0, |
| 145 | CreatedTs: now, |
| 146 | ModTs: now, |
| 147 | Opts: opts, |
| 148 | Meta: meta, |
| 149 | } |
| 150 | return dbInsertFile(ctx, file) |
| 151 | }) |
| 152 | } |
| 153 | |
| 154 | func (s *FileStore) DeleteFile(ctx context.Context, zoneId string, name string) error { |
| 155 | return withLock(s, zoneId, name, func(entry *CacheEntry) error { |