@@ -63,11 +63,6 @@ func (fs *Eosfs) GetMD(ctx context.Context, ref *provider.Reference, mdKeys []st
6363 return nil , errtypes .BadRequest ("No ref was given to GetMD" )
6464 }
6565
66- fn , err := fs .resolve (ctx , ref )
67- if err != nil {
68- return nil , errtypes .BadRequest ("No ref was given to GetMD" )
69- }
70-
7166 // We use daemon for auth because we need access to the file in order to stat it
7267 // We cannot use the current user, because the file may be a shared file
7368 // and lightweight accounts don't have a uid
@@ -76,29 +71,39 @@ func (fs *Eosfs) GetMD(ctx context.Context, ref *provider.Reference, mdKeys []st
7671 return nil , fmt .Errorf ("error getting daemon auth" )
7772 }
7873
79- if ref .ResourceId != nil {
80- // Check if it's a version
81- // Cannot check with (ResourceId.StorageId == "versions") because of the storage provider
82- if strings .Contains (ref .ResourceId .OpaqueId , "@" ) {
83- parts := strings .Split (ref .ResourceId .OpaqueId , "@" )
84- version := ""
85- ref .ResourceId .OpaqueId , version = parts [0 ], parts [1 ]
86-
87- path , err := fs .getPath (ctx , ref .ResourceId )
88- if err != nil {
89- return nil , fmt .Errorf ("error getting path for resource id: %s" , ref .ResourceId .OpaqueId )
90- }
91- path = filepath .Join (fn , path )
74+ // Check for version references before calling resolve: resolve calls getPath which
75+ // cannot parse OpaqueIds containing "@<version>" as an integer.
76+ if ref .ResourceId != nil && strings .Contains (ref .ResourceId .OpaqueId , "@" ) {
77+ parts := strings .Split (ref .ResourceId .OpaqueId , "@" )
78+ opaqueID , version := parts [0 ], parts [1 ]
9279
93- versionFolder := eosclient .GetVersionFolder (path )
94- versionPath := filepath .Join (versionFolder , version )
95- eosFileInfo , err := fs .c .GetFileInfoByPath (ctx , auth , versionPath )
96- if err != nil {
97- return nil , fmt .Errorf ("error getting file info by path: %s" , versionPath )
98- }
80+ cleanID := & provider.ResourceId {
81+ StorageId : ref .ResourceId .StorageId ,
82+ SpaceId : ref .ResourceId .SpaceId ,
83+ OpaqueId : opaqueID ,
84+ }
85+ filePath , err := fs .getPath (ctx , cleanID )
86+ if err != nil {
87+ return nil , fmt .Errorf ("error getting path for resource id: %s" , opaqueID )
88+ }
89+ filePath = fs .wrap (ctx , filePath )
9990
100- return fs .convertToResourceInfo (ctx , eosFileInfo )
91+ versionFolder := eosclient .GetVersionFolder (filePath )
92+ versionPath := filepath .Join (versionFolder , version )
93+ eosFileInfo , err := fs .c .GetFileInfoByPath (ctx , auth , versionPath )
94+ if err != nil {
95+ return nil , fmt .Errorf ("error getting file info by path: %s" , versionPath )
10196 }
97+
98+ return fs .convertToResourceInfo (ctx , eosFileInfo )
99+ }
100+
101+ fn , err := fs .resolve (ctx , ref )
102+ if err != nil {
103+ return nil , errtypes .BadRequest ("No ref was given to GetMD" )
104+ }
105+
106+ if ref .ResourceId != nil {
102107 fid , err := strconv .ParseUint (ref .ResourceId .OpaqueId , 10 , 64 )
103108 if err != nil {
104109 return nil , fmt .Errorf ("error converting string to int for eos fileid: %s" , ref .ResourceId .OpaqueId )
0 commit comments