Skip to content

Commit

Permalink
Warn when rootDir lacks extended attribute support (#685)
Browse files Browse the repository at this point in the history
* Warn when rootDir lacks extended attribute support

This hints to the user to reconfigure the server.  References #684.

* internal/backend/fs: bail if xattr is not supported

I think this is better than a warning. xattr is required, so users
should either use the memory backend or a filesystem that supports
xattr.

If this hurts people too much, we can stop using xattr.

* internal/backend: fix test

* go mod tidy

Co-authored-by: francisco souza <[email protected]>
  • Loading branch information
gaul and fsouza authored Feb 21, 2022
1 parent dee5921 commit 1579a72
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/go-cmp v0.5.7
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/pkg/xattr v0.4.5
github.com/pkg/xattr v0.4.6-0.20220216010434-3698607f1c00
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/xattr v0.4.5 h1:P5SvUc1T07cHLto76ESJ+/x5kexU7s9127iVoeEW/hs=
github.com/pkg/xattr v0.4.5/go.mod h1:sBD3RAqlr8Q+RC3FutZcikpT8nyDrIEEBw2J744gVWs=
github.com/pkg/xattr v0.4.6-0.20220216010434-3698607f1c00 h1:WViBaFRqFoWFBntuJYbcFzXG0GnySh2URrEiSSzSTgk=
github.com/pkg/xattr v0.4.6-0.20220216010434-3698607f1c00/go.mod h1:sBD3RAqlr8Q+RC3FutZcikpT8nyDrIEEBw2J744gVWs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
12 changes: 12 additions & 0 deletions internal/backend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/fsouza/fake-gcs-server/internal/checksum"
"github.com/pkg/xattr"
)

// storageFS is an implementation of the backend storage that stores data on disk
Expand Down Expand Up @@ -45,6 +46,17 @@ func NewStorageFS(objects []Object, rootDir string) (Storage, error) {
if err != nil {
return nil, err
}

// Check if rootDir supports xattr.
if xattr.XATTR_SUPPORTED {
_, err = readXattr(rootDir)
if err != nil {
if xerr, ok := err.(*xattr.Error); !ok || xerr.Err != xattr.ENOATTR {
return nil, fmt.Errorf("failed to determine if %q supports xattr, consider using a different storage backend or a filesystem that supports it (e.g. not tmpfs on Linux): %w", rootDir, err)
}
}
}

s := &storageFS{rootDir: rootDir}
for _, o := range objects {
_, err := s.CreateObject(o)
Expand Down

0 comments on commit 1579a72

Please sign in to comment.