mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-06-21 14:29:00 -04:00
6
changelog/unreleased/fix-code-smells.md
Normal file
6
changelog/unreleased/fix-code-smells.md
Normal file
@@ -0,0 +1,6 @@
|
||||
Change: refactor code to remove code smells
|
||||
|
||||
Scanning the code using a static code analyzer showed some code smells.
|
||||
This change fixes them.
|
||||
|
||||
https://github.com/owncloud/ocis-thumbnails/issues/21
|
||||
@@ -40,15 +40,15 @@ func New() *Metrics {
|
||||
}, []string{}),
|
||||
}
|
||||
|
||||
prometheus.Register(
|
||||
_ = prometheus.Register(
|
||||
m.Counter,
|
||||
)
|
||||
|
||||
prometheus.Register(
|
||||
_ = prometheus.Register(
|
||||
m.Latency,
|
||||
)
|
||||
|
||||
prometheus.Register(
|
||||
_ = prometheus.Register(
|
||||
m.Duration,
|
||||
)
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func NewService(opts ...Option) grpc.Service {
|
||||
thumbnail = svc.NewLogging(thumbnail, options.Logger)
|
||||
}
|
||||
|
||||
proto.RegisterThumbnailServiceHandler(
|
||||
_ = proto.RegisterThumbnailServiceHandler(
|
||||
service.Server(),
|
||||
thumbnail,
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ type FileSystem struct {
|
||||
// Get retrieves an image from the filesystem.
|
||||
func (s FileSystem) Get(ctx context.Context, file string) (image.Image, error) {
|
||||
imgPath := filepath.Join(s.basePath, file)
|
||||
f, err := os.Open(imgPath)
|
||||
f, err := os.Open(filepath.Clean(imgPath))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load the file %s from %s error %s", file, imgPath, err.Error())
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ type FileSystem struct {
|
||||
|
||||
// Get loads the image from the file system.
|
||||
func (s FileSystem) Get(key string) []byte {
|
||||
content, err := ioutil.ReadFile(filepath.Join(s.dir, key))
|
||||
path := filepath.Join(s.dir, key)
|
||||
content, err := ioutil.ReadFile(filepath.Clean(path))
|
||||
if err != nil {
|
||||
s.logger.Warn().Err(err).Msgf("could not read file %s", key)
|
||||
return nil
|
||||
@@ -48,7 +49,11 @@ func (s FileSystem) Set(key string, img []byte) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create file \"%s\" error: %s", key, err.Error())
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
s.logger.Warn().Err(err).Msg("closing file resulted in an error")
|
||||
}
|
||||
}()
|
||||
_, err = f.Write(img)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not write to file \"%s\" error: %s", key, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user