1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

skip file content reading if unnecessary

This commit is contained in:
Shelikhoo 2021-09-05 15:55:55 +01:00
parent ef738cce7a
commit a8c58c9ad4
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -64,6 +64,15 @@ func filterMessage(ctx context.Context, message protoreflect.Message) error {
fsenvironment := envctx.EnvironmentFromContext(ctx)
fsifce := fsenvironment.(filesystemcap.FileSystemCapabilitySet)
for _, v := range fileReadingQueue {
field := message.Descriptor().Fields().ByTextName(v.field)
if v.filename == "" {
continue
}
if len(message.Get(field).Bytes()) > 0 {
continue
}
file, err := fsifce.OpenFileForRead()(v.filename)
if err != nil {
return newError("unable to open file").Base(err)
@ -73,7 +82,6 @@ func filterMessage(ctx context.Context, message protoreflect.Message) error {
return newError("unable to read file").Base(err)
}
file.Close()
field := message.Descriptor().Fields().ByTextName(v.field)
message.Set(field, protoreflect.ValueOf(fileContent))
}
return nil