MCPcopy
hub / github.com/wavetermdev/waveterm / MakeFile

Method MakeFile

pkg/filestore/blockstore.go:115–152  ·  view source on GitHub ↗

synchronous (does not interact with the cache)

(ctx context.Context, zoneId string, name string, meta wshrpc.FileMeta, opts wshrpc.FileOpts)

Source from the content-addressed store, hash-verified

113
114// synchronous (does not interact with the cache)
115func (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
154func (s *FileStore) DeleteFile(ctx context.Context, zoneId string, name string) error {
155 return withLock(s, zoneId, name, func(entry *CacheEntry) error {

Callers 15

MakePlotDataFunction · 0.80
SetVarCommandMethod · 0.80
SaveTerminalStateMethod · 0.80
StartJobFunction · 0.80
StartMethod · 0.80
CreateBlockWithTelemetryFunction · 0.80
TestCreateFunction · 0.80
TestDeleteFunction · 0.80
TestSetMetaFunction · 0.80
TestWriteAtFunction · 0.80
TestAppendFunction · 0.80

Calls 2

withLockFunction · 0.85
dbInsertFileFunction · 0.85

Tested by 11

TestCreateFunction · 0.64
TestDeleteFunction · 0.64
TestSetMetaFunction · 0.64
TestWriteAtFunction · 0.64
TestAppendFunction · 0.64
TestWriteFileFunction · 0.64
TestCircularWritesFunction · 0.64
TestMultiPartFunction · 0.64
TestSimpleDBFlushFunction · 0.64
TestConcurrentAppendFunction · 0.64
TestIJsonFunction · 0.64