Skip to content

Commit 21a04fb

Browse files
committed
consistently return the same list of xattrs
also, if we are requesting s3.* xattrs then we can use the cached values from LIST
1 parent 0e0a805 commit 21a04fb

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

internal/goofys.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,17 @@ func (fs *Goofys) LookUpInodeMaybeDir(parent *Inode, name string, fullName strin
857857
inode = NewInode(parent, &name, &fullName, fs.flags)
858858
inode.Attributes = &fs.rootAttrs
859859
inode.KnownSize = &inode.Attributes.Size
860+
if len(resp.Contents) != 0 && *resp.Contents[0].Key == name+"/" {
861+
// it's actually a dir blob
862+
entry := resp.Contents[0]
863+
if entry.ETag != nil {
864+
inode.s3Metadata["etag"] = []byte(*entry.ETag)
865+
}
866+
if entry.StorageClass != nil {
867+
inode.s3Metadata["storage-class"] = []byte(*entry.StorageClass)
868+
}
869+
870+
}
860871
// if cheap is not on, the dir blob
861872
// could exist but this returned first
862873
if fs.flags.Cheap {
@@ -1064,6 +1075,12 @@ func (fs *Goofys) insertInodeFromDirEntry(parent *Inode, entry *DirHandleEntry)
10641075
path := parent.getChildName(*entry.Name)
10651076
inode = NewInode(parent, entry.Name, &path, fs.flags)
10661077
inode.Attributes = entry.Attributes
1078+
if entry.ETag != nil {
1079+
inode.s3Metadata["etag"] = []byte(*entry.ETag)
1080+
}
1081+
if entry.StorageClass != nil {
1082+
inode.s3Metadata["storage-class"] = []byte(*entry.StorageClass)
1083+
}
10671084
// these are fake dir entries, we will realize the refcnt when
10681085
// lookup is done
10691086
inode.refcnt = 0

internal/goofys_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,9 @@ func (s *GoofysTest) TestXAttrGet(t *C) {
13981398

13991399
names, err = emptyDir2.ListXattr(s.fs)
14001400
t.Assert(err, IsNil)
1401-
t.Assert(names, DeepEquals, []string{"s3.etag", "user.name"})
1401+
// https://github.com/andrewgaul/s3proxy/issues/234 means that
1402+
// s3proxy may or may not return the storage class
1403+
t.Assert(len(names) == 2 || len(names) == 3, Equals, true)
14021404

14031405
emptyDir, err := s.LookUpInode(t, "empty_dir")
14041406
t.Assert(err, IsNil)
@@ -1434,6 +1436,20 @@ func (s *GoofysTest) TestXAttrGet(t *C) {
14341436
}
14351437
}
14361438

1439+
func (s *GoofysTest) TestXAttrGetCached(t *C) {
1440+
s.fs.flags.StatCacheTTL = 1 * time.Minute
1441+
s.fs.flags.TypeCacheTTL = 1 * time.Minute
1442+
s.readDirIntoCache(t, fuseops.RootInodeID)
1443+
s.disableS3()
1444+
1445+
in, err := s.LookUpInode(t, "file1")
1446+
t.Assert(err, IsNil)
1447+
t.Assert(in.userMetadata, IsNil)
1448+
1449+
_, err = in.GetXattr(s.fs, "s3.etag")
1450+
t.Assert(err, IsNil)
1451+
}
1452+
14371453
func (s *GoofysTest) TestXAttrCopied(t *C) {
14381454
root := s.getRoot(t)
14391455

internal/handles.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ func (inode *Inode) fillXattrFromHead(resp *s3.HeadObjectOutput) {
506506

507507
// LOCKS_REQUIRED(inode.mu)
508508
func (inode *Inode) fillXattr(fs *Goofys) (err error) {
509-
if !inode.ImplicitDir &&
510-
(len(inode.s3Metadata) == 0 && inode.userMetadata == nil) {
509+
if !inode.ImplicitDir && inode.userMetadata == nil {
511510

512511
fullName := *inode.FullName
513512
if inode.isDir() {
@@ -537,11 +536,6 @@ func (inode *Inode) fillXattr(fs *Goofys) (err error) {
537536
func (inode *Inode) getXattrMap(fs *Goofys, name string, userOnly bool) (
538537
meta map[string][]byte, newName string, err error) {
539538

540-
err = inode.fillXattr(fs)
541-
if err != nil {
542-
return nil, "", err
543-
}
544-
545539
if strings.HasPrefix(name, "s3.") {
546540
if userOnly {
547541
return nil, "", syscall.EACCES
@@ -550,6 +544,11 @@ func (inode *Inode) getXattrMap(fs *Goofys, name string, userOnly bool) (
550544
newName = name[3:]
551545
meta = inode.s3Metadata
552546
} else if strings.HasPrefix(name, "user.") {
547+
err = inode.fillXattr(fs)
548+
if err != nil {
549+
return nil, "", err
550+
}
551+
553552
newName = name[5:]
554553
meta = inode.userMetadata
555554
} else {

0 commit comments

Comments
 (0)