mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 15:32:24 -05:00 
			
		
		
		
	don't error out if storage key already exists (#840)
This commit is contained in:
		
					parent
					
						
							
								3777f5c684
							
						
					
				
			
			
				commit
				
					
						de26924a4a
					
				
			
		
					 4 changed files with 16 additions and 6 deletions
				
			
		|  | @ -136,7 +136,7 @@ func (p *ProcessingEmoji) loadStatic(ctx context.Context) error { | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// put the static in storage | 		// put the static in storage | ||||||
| 		if err := p.storage.Put(ctx, p.emoji.ImageStaticPath, static.small); err != nil { | 		if err := p.storage.Put(ctx, p.emoji.ImageStaticPath, static.small); err != nil && err != storage.ErrAlreadyExists { | ||||||
| 			p.err = fmt.Errorf("loadStatic: error storing static: %s", err) | 			p.err = fmt.Errorf("loadStatic: error storing static: %s", err) | ||||||
| 			atomic.StoreInt32(&p.staticState, int32(errored)) | 			atomic.StoreInt32(&p.staticState, int32(errored)) | ||||||
| 			return p.err | 			return p.err | ||||||
|  | @ -217,7 +217,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { | ||||||
| 	multiReader := io.MultiReader(bytes.NewBuffer(firstBytes), reader) | 	multiReader := io.MultiReader(bytes.NewBuffer(firstBytes), reader) | ||||||
| 
 | 
 | ||||||
| 	// store this for now -- other processes can pull it out of storage as they please | 	// store this for now -- other processes can pull it out of storage as they please | ||||||
| 	if err := p.storage.PutStream(ctx, p.emoji.ImagePath, multiReader); err != nil { | 	if err := p.storage.PutStream(ctx, p.emoji.ImagePath, multiReader); err != nil && err != storage.ErrAlreadyExists { | ||||||
| 		return fmt.Errorf("store: error storing stream: %s", err) | 		return fmt.Errorf("store: error storing stream: %s", err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -162,7 +162,7 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) error { | ||||||
| 
 | 
 | ||||||
| 		// put the thumbnail in storage | 		// put the thumbnail in storage | ||||||
| 		log.Tracef("loadThumb: storing new thumbnail %s", p.attachment.URL) | 		log.Tracef("loadThumb: storing new thumbnail %s", p.attachment.URL) | ||||||
| 		if err := p.storage.Put(ctx, p.attachment.Thumbnail.Path, thumb.small); err != nil { | 		if err := p.storage.Put(ctx, p.attachment.Thumbnail.Path, thumb.small); err != nil && err != storage.ErrAlreadyExists { | ||||||
| 			p.err = fmt.Errorf("loadThumb: error storing thumbnail: %s", err) | 			p.err = fmt.Errorf("loadThumb: error storing thumbnail: %s", err) | ||||||
| 			atomic.StoreInt32(&p.thumbState, int32(errored)) | 			atomic.StoreInt32(&p.thumbState, int32(errored)) | ||||||
| 			return p.err | 			return p.err | ||||||
|  | @ -341,7 +341,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error { | ||||||
| 	p.attachment.File.FileSize = fileSize | 	p.attachment.File.FileSize = fileSize | ||||||
| 
 | 
 | ||||||
| 	// store this for now -- other processes can pull it out of storage as they please | 	// store this for now -- other processes can pull it out of storage as they please | ||||||
| 	if err := p.storage.PutStream(ctx, p.attachment.File.Path, clean); err != nil { | 	if err := p.storage.PutStream(ctx, p.attachment.File.Path, clean); err != nil && err != storage.ErrAlreadyExists { | ||||||
| 		return fmt.Errorf("store: error storing stream: %s", err) | 		return fmt.Errorf("store: error storing stream: %s", err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -24,6 +24,7 @@ import ( | ||||||
| 	"net/url" | 	"net/url" | ||||||
| 
 | 
 | ||||||
| 	"codeberg.org/gruf/go-store/kv" | 	"codeberg.org/gruf/go-store/kv" | ||||||
|  | 	"codeberg.org/gruf/go-store/storage" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type Local struct { | type Local struct { | ||||||
|  | @ -39,11 +40,19 @@ func (l *Local) GetStream(ctx context.Context, key string) (io.ReadCloser, error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Local) PutStream(ctx context.Context, key string, r io.Reader) error { | func (l *Local) PutStream(ctx context.Context, key string, r io.Reader) error { | ||||||
| 	return l.KVStore.PutStream(key, r) | 	err := l.KVStore.PutStream(key, r) | ||||||
|  | 	if err == storage.ErrAlreadyExists { | ||||||
|  | 		return ErrAlreadyExists | ||||||
|  | 	} | ||||||
|  | 	return err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Local) Put(ctx context.Context, key string, value []byte) error { | func (l *Local) Put(ctx context.Context, key string, value []byte) error { | ||||||
| 	return l.KVStore.Put(key, value) | 	err := l.KVStore.Put(key, value) | ||||||
|  | 	if err == storage.ErrAlreadyExists { | ||||||
|  | 		return ErrAlreadyExists | ||||||
|  | 	} | ||||||
|  | 	return err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Local) Delete(ctx context.Context, key string) error { | func (l *Local) Delete(ctx context.Context, key string) error { | ||||||
|  |  | ||||||
|  | @ -34,6 +34,7 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var ErrNotSupported = errors.New("driver does not suppport functionality") | var ErrNotSupported = errors.New("driver does not suppport functionality") | ||||||
|  | var ErrAlreadyExists = errors.New("storage key already exists") | ||||||
| 
 | 
 | ||||||
| // Driver implements the functionality to store and retrieve blobs | // Driver implements the functionality to store and retrieve blobs | ||||||
| // (images,video,audio) | // (images,video,audio) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue