fix: return etag with md5 in webdav responses (#5158)

This commit is contained in:
Konstantin Lebedev 2024-01-03 21:50:32 +05:00 committed by GitHub
parent d3688938d9
commit b832ddd1ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -96,6 +96,7 @@ type FileInfo struct {
size int64
mode os.FileMode
modifiedTime time.Time
etag string
isDirectory bool
}
@ -106,6 +107,10 @@ func (fi *FileInfo) ModTime() time.Time { return fi.modifiedTime }
func (fi *FileInfo) IsDir() bool { return fi.isDirectory }
func (fi *FileInfo) Sys() interface{} { return nil }
func (fi *FileInfo) ETag(ctx context.Context) (string, error) {
return fi.etag, nil
}
type WebDavFile struct {
fs *WebDavFileSystem
name string
@ -369,6 +374,7 @@ func (fs *WebDavFileSystem) stat(ctx context.Context, fullFilePath string) (os.F
fi.name = string(fullpath)
fi.mode = os.FileMode(entry.Attributes.FileMode)
fi.modifiedTime = time.Unix(entry.Attributes.Mtime, 0)
fi.etag = filer.ETag(entry)
fi.isDirectory = entry.IsDirectory
if fi.name == "/" {

View file

@ -95,3 +95,11 @@ func (w wrappedFileInfo) Name() string {
name := w.FileInfo.Name()
return strings.TrimPrefix(name, *w.subFolder)
}
func (w wrappedFileInfo) ETag(ctx context.Context) (string, error) {
etag, _ := w.FileInfo.(webdav.ETager).ETag(ctx)
if len(etag) == 0 {
return etag, webdav.ErrNotImplemented
}
return etag, nil
}