Compare commits

..

1 Commits

Author SHA1 Message Date
zzjc1234
f04b18189a feat: skip git module for non ascii check
All checks were successful
build / build (push) Successful in 2m49s
build / trigger-build-image (push) Has been skipped
build / build (pull_request) Successful in 3m32s
build / trigger-build-image (pull_request) Has been skipped
2025-11-07 20:52:09 +08:00
6 changed files with 152 additions and 145 deletions

16
go.mod
View File

@ -5,15 +5,15 @@ go 1.24.0
toolchain go1.24.1 toolchain go1.24.1
require ( require (
github.com/criyle/go-judge/pb v1.3.2 github.com/criyle/go-judge/pb v1.0.0
github.com/go-git/go-git/v5 v5.16.2 github.com/go-git/go-git/v5 v5.16.2
github.com/jinzhu/copier v0.4.0 github.com/jinzhu/copier v0.4.0
github.com/joint-online-judge/go-gitignore v0.0.0-20250212104351-ad79a46f8dcc github.com/joint-online-judge/go-gitignore v0.0.0-20250212104351-ad79a46f8dcc
github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7 github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7
github.com/mcuadros/go-defaults v1.2.0 github.com/mcuadros/go-defaults v1.2.0
github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/mapstructure v1.5.0
google.golang.org/grpc v1.77.0 google.golang.org/grpc v1.75.1
google.golang.org/protobuf v1.36.11 google.golang.org/protobuf v1.36.9
) )
require ( require (
@ -37,11 +37,11 @@ require (
github.com/sergi/go-diff v1.4.0 // indirect github.com/sergi/go-diff v1.4.0 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect github.com/skeema/knownhosts v1.3.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.46.0 // indirect golang.org/x/crypto v0.43.0 // indirect
golang.org/x/net v0.48.0 // indirect golang.org/x/net v0.45.0 // indirect
golang.org/x/sys v0.39.0 // indirect golang.org/x/sys v0.37.0 // indirect
golang.org/x/text v0.32.0 // indirect golang.org/x/text v0.30.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251213004720-97cd9d5aeac2 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250929231259-57b25ae835d4 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
) )

60
go.sum
View File

@ -13,8 +13,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0= github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/criyle/go-judge/pb v1.3.2 h1:S0c0EqRF+xePOwcZxSb9mPV+bkXgfOX9f7SQMrcdeb4= github.com/criyle/go-judge/pb v1.0.0 h1:8A4zHPPCGCDTuFY1GW5Hqpg+8ETIwzgXxiRpYKKb2zA=
github.com/criyle/go-judge/pb v1.3.2/go.mod h1:QfjmF1w4t5ODXikuUcy8Alqb901R6p0HDxJXGKZy0NE= github.com/criyle/go-judge/pb v1.0.0/go.mod h1:hjgixgK9NH9ktwc29xbXVdZDOlKfEkRkEbZ4W5bOMmw=
github.com/cyphar/filepath-securejoin v0.5.0 h1:hIAhkRBMQ8nIeuVwcAoymp7MY4oherZdAxD+m0u9zaw= github.com/cyphar/filepath-securejoin v0.5.0 h1:hIAhkRBMQ8nIeuVwcAoymp7MY4oherZdAxD+m0u9zaw=
github.com/cyphar/filepath-securejoin v0.5.0/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/cyphar/filepath-securejoin v0.5.0/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ= github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
@ -98,49 +98,49 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8= go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM= go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA= go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI= go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E= go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI=
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg= go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg=
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM= go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc=
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA= go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps=
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE= go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs= go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM=
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= golang.org/x/net v0.45.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q= golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg= golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251213004720-97cd9d5aeac2 h1:2I6GHUeJ/4shcDpoUlLs/2WPnhg7yJwvXtqcMJt9liA= google.golang.org/genproto/googleapis/rpc v0.0.0-20250929231259-57b25ae835d4 h1:i8QOKZfYg6AbGVZzUAY3LrNWCKF8O6zFisU9Wl9RER4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251213004720-97cd9d5aeac2/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk= google.golang.org/genproto/googleapis/rpc v0.0.0-20250929231259-57b25ae835d4/go.mod h1:HSkG/KdJWusxU1F6CNrwNDjBMgisKxGnc5dAZfT0mjQ=
google.golang.org/grpc v1.77.0 h1:wVVY6/8cGA6vvffn+wWK5ToddbgdU3d8MNENr4evgXM= google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
google.golang.org/grpc v1.77.0/go.mod h1:z0BY1iVj0q8E1uSQCjL9cppRj+gnZjzDnzV0dHhrNig= google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -8,34 +8,33 @@ import (
"github.com/criyle/go-judge/pb" "github.com/criyle/go-judge/pb"
"github.com/joint-online-judge/JOJ3/internal/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
"google.golang.org/protobuf/types/known/emptypb"
) )
// copied from https://github.com/criyle/go-judge/blob/master/cmd/go-judge-shell/grpc.go // copied from https://github.com/criyle/go-judge/blob/master/cmd/go-judge-shell/grpc.go
func convertPBCmd(cmd []stage.Cmd) []*pb.Request_CmdType { func convertPBCmd(cmd []stage.Cmd) []*pb.Request_CmdType {
ret := make([]*pb.Request_CmdType, 0, len(cmd)) ret := make([]*pb.Request_CmdType, 0, len(cmd))
for _, c := range cmd { for _, c := range cmd {
req := &pb.Request_CmdType{} ret = append(ret, &pb.Request_CmdType{
req.SetArgs(c.Args) Args: c.Args,
req.SetEnv(c.Env) Env: c.Env,
req.SetTty(c.TTY) Tty: c.TTY,
req.SetFiles(convertPBFiles([]*stage.CmdFile{c.Stdin, c.Stdout, c.Stderr})) Files: convertPBFiles([]*stage.CmdFile{c.Stdin, c.Stdout, c.Stderr}),
req.SetCpuTimeLimit(c.CPULimit) CpuTimeLimit: c.CPULimit,
req.SetClockTimeLimit(c.ClockLimit) ClockTimeLimit: c.ClockLimit,
req.SetMemoryLimit(c.MemoryLimit) MemoryLimit: c.MemoryLimit,
req.SetStackLimit(c.StackLimit) StackLimit: c.StackLimit,
req.SetProcLimit(c.ProcLimit) ProcLimit: c.ProcLimit,
req.SetCpuRateLimit(c.CPURateLimit) CpuRateLimit: c.CPURateLimit,
req.SetCpuSetLimit(c.CPUSetLimit) CpuSetLimit: c.CPUSetLimit,
req.SetDataSegmentLimit(c.DataSegmentLimit) DataSegmentLimit: c.DataSegmentLimit,
req.SetAddressSpaceLimit(c.AddressSpaceLimit) AddressSpaceLimit: c.AddressSpaceLimit,
req.SetCopyIn(convertPBCopyIn(c.CopyIn, c.CopyInDir)) CopyIn: convertPBCopyIn(c.CopyIn, c.CopyInDir),
req.SetCopyOut(convertPBCopyOut(c.CopyOut)) CopyOut: convertPBCopyOut(c.CopyOut),
req.SetCopyOutCached(convertPBCopyOut(c.CopyOutCached)) CopyOutCached: convertPBCopyOut(c.CopyOutCached),
req.SetCopyOutMax(c.CopyOutMax) CopyOutMax: c.CopyOutMax,
req.SetCopyOutDir(c.CopyOutDir) CopyOutDir: c.CopyOutDir,
req.SetSymlinks(convertSymlink(c.CopyIn)) Symlinks: convertSymlink(c.CopyIn),
ret = append(ret, req) })
} }
return ret return ret
} }
@ -82,10 +81,10 @@ func convertPBCopyOut(copyOut []string) []*pb.Request_CmdCopyOutFile {
optional = true optional = true
n = strings.TrimSuffix(n, "?") n = strings.TrimSuffix(n, "?")
} }
elem := &pb.Request_CmdCopyOutFile{} rt = append(rt, &pb.Request_CmdCopyOutFile{
elem.SetName(n) Name: n,
elem.SetOptional(optional) Optional: optional,
rt = append(rt, elem) })
} }
return rt return rt
} }
@ -114,7 +113,6 @@ func convertPBFiles(files []*stage.CmdFile) []*pb.Request_File {
} }
func convertPBFile(i stage.CmdFile) *pb.Request_File { func convertPBFile(i stage.CmdFile) *pb.Request_File {
req := &pb.Request_File{}
switch { switch {
case i.Src != nil: case i.Src != nil:
if !filepath.IsAbs(*i.Src) { if !filepath.IsAbs(*i.Src) {
@ -130,34 +128,18 @@ func convertPBFile(i stage.CmdFile) *pb.Request_File {
s = []byte{} s = []byte{}
slog.Error("convert pb file read file", "path", *i.Src, "error", err) slog.Error("convert pb file read file", "path", *i.Src, "error", err)
} }
m := &pb.Request_MemoryFile{} return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}}
m.SetContent(s)
req.SetMemory(m)
return req
case i.Content != nil: case i.Content != nil:
s := strToBytes(*i.Content) s := strToBytes(*i.Content)
m := &pb.Request_MemoryFile{} return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}}
m.SetContent(s)
req.SetMemory(m)
return req
case i.FileID != nil: case i.FileID != nil:
c := &pb.Request_CachedFile{} return &pb.Request_File{File: &pb.Request_File_Cached{Cached: &pb.Request_CachedFile{FileID: *i.FileID}}}
c.SetFileID(*i.FileID)
req.SetCached(c)
return req
case i.Name != nil && i.Max != nil: case i.Name != nil && i.Max != nil:
p := &pb.Request_PipeCollector{} return &pb.Request_File{File: &pb.Request_File_Pipe{Pipe: &pb.Request_PipeCollector{Name: *i.Name, Max: *i.Max, Pipe: i.Pipe}}}
p.SetName(*i.Name)
p.SetMax(*i.Max)
p.SetPipe(i.Pipe)
req.SetPipe(p)
return req
case i.StreamIn: case i.StreamIn:
req.SetStreamIn(&emptypb.Empty{}) return &pb.Request_File{File: &pb.Request_File_StreamIn{}}
return req
case i.StreamOut: case i.StreamOut:
req.SetStreamOut(&emptypb.Empty{}) return &pb.Request_File{File: &pb.Request_File_StreamOut{}}
return req
} }
return nil return nil
} }
@ -166,17 +148,17 @@ func convertPBResult(res []*pb.Response_Result) []stage.ExecutorResult {
ret := make([]stage.ExecutorResult, 0, len(res)) ret := make([]stage.ExecutorResult, 0, len(res))
for _, r := range res { for _, r := range res {
ret = append(ret, stage.ExecutorResult{ ret = append(ret, stage.ExecutorResult{
Status: stage.Status(r.GetStatus()), Status: stage.Status(r.Status),
ExitStatus: int(r.GetExitStatus()), ExitStatus: int(r.ExitStatus),
Error: r.GetError(), Error: r.Error,
Time: r.GetTime(), Time: r.Time,
Memory: r.GetMemory(), Memory: r.Memory,
RunTime: r.GetRunTime(), RunTime: r.RunTime,
ProcPeak: r.GetProcPeak(), ProcPeak: r.ProcPeak,
Files: convertFiles(r.GetFiles()), Files: convertFiles(r.Files),
Buffs: r.GetFiles(), Buffs: r.Files,
FileIDs: r.GetFileIDs(), FileIDs: r.FileIDs,
FileError: convertPBFileError(r.GetFileError()), FileError: convertPBFileError(r.FileError),
}) })
} }
return ret return ret
@ -194,9 +176,9 @@ func convertPBFileError(fe []*pb.Response_FileError) []stage.FileError {
ret := make([]stage.FileError, 0, len(fe)) ret := make([]stage.FileError, 0, len(fe))
for _, v := range fe { for _, v := range fe {
ret = append(ret, stage.FileError{ ret = append(ret, stage.FileError{
Name: v.GetName(), Name: v.Name,
Type: stage.FileErrorType(v.GetType()), Type: stage.FileErrorType(v.Type),
Message: v.GetMessage(), Message: v.Message,
}) })
} }
return ret return ret

View File

@ -36,17 +36,16 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
for i, pbCmd := range pbCmds { for i, pbCmd := range pbCmds {
slog.Debug("sandbox execute", "i", i, "pbCmd size", proto.Size(pbCmd)) slog.Debug("sandbox execute", "i", i, "pbCmd size", proto.Size(pbCmd))
} }
pbReq := &pb.Request{} pbReq := &pb.Request{Cmd: pbCmds}
pbReq.SetCmd(pbCmds)
slog.Debug("sandbox execute", "pbReq size", proto.Size(pbReq)) slog.Debug("sandbox execute", "pbReq size", proto.Size(pbReq))
pbRet, err := e.execClient.Exec(context.TODO(), pbReq) pbRet, err := e.execClient.Exec(context.TODO(), pbReq)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if pbRet.GetError() != "" { if pbRet.Error != "" {
return nil, fmt.Errorf("sandbox execute error: %s", pbRet.GetError()) return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error)
} }
results := convertPBResult(pbRet.GetResults()) results := convertPBResult(pbRet.Results)
for _, result := range results { for _, result := range results {
maps.Copy(e.cachedMap, result.FileIDs) maps.Copy(e.cachedMap, result.FileIDs)
} }
@ -55,9 +54,9 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
func (e *Sandbox) Cleanup() error { func (e *Sandbox) Cleanup() error {
for k, fileID := range e.cachedMap { for k, fileID := range e.cachedMap {
req := &pb.FileID{} _, err := e.execClient.FileDelete(context.TODO(), &pb.FileID{
req.SetFileID(fileID) FileID: fileID,
_, err := e.execClient.FileDelete(context.TODO(), req) })
if err != nil { if err != nil {
slog.Error("sandbox cleanup", "error", err) slog.Error("sandbox cleanup", "error", err)
} }

View File

@ -5,48 +5,31 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log/slog" "log/slog"
"strings"
"github.com/joint-online-judge/JOJ3/internal/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
) )
func (*Log) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { func (*Log) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
content, ok := executorResult.Files[conf.Filename] content := executorResult.Files[conf.Filename]
if !ok { var data map[string]any
slog.Error("file not found for log parser", "filename", conf.Filename) err := json.Unmarshal([]byte(content), &data)
if err != nil {
slog.Error(conf.Msg, "error", err)
return stage.ParserResult{ return stage.ParserResult{
Score: 0, Score: 0,
Comment: fmt.Sprintf("log parser: file %s not found", conf.Filename), Comment: fmt.Sprintf("Failed to parse content: %s", err),
} }
} }
contentBytes := []byte(content) args := make([]any, 0, len(data)*2)
var data map[string]any for key, value := range data {
if err := json.Unmarshal(contentBytes, &data); err != nil { args = append(args, key, value)
// Not a valid json or failed to unmarshal, log as raw string line by line.
for line := range strings.SplitSeq(content, "\n") {
if strings.TrimSpace(line) != "" {
slog.Default().Log(
context.Background(),
slog.Level(conf.Level),
conf.Msg,
"line",
line,
)
}
}
} else {
// Valid json, log as key-value pairs.
args := make([]any, 0, len(data)*2)
for key, value := range data {
args = append(args, key, value)
}
slog.Default().Log(
context.Background(),
slog.Level(conf.Level),
conf.Msg,
args...,
)
} }
slog.Default().Log(
context.Background(),
slog.Level(conf.Level),
conf.Msg,
args...,
)
return stage.ParserResult{ return stage.ParserResult{
Score: 0, Score: 0,
Comment: "", Comment: "",

View File

@ -9,9 +9,43 @@ import (
"strings" "strings"
"unicode" "unicode"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/format/gitattributes" "github.com/go-git/go-git/v5/plumbing/format/gitattributes"
) )
// getSubmodulePathsFromGoGit uses the go-git library to open the repository
// at the given root path and retrieve a list of all submodule paths.
// It returns a set of submodule paths for efficient lookup.
func getSubmodulePathsFromGoGit(root string) (map[string]struct{}, error) {
submodulePaths := make(map[string]struct{})
// Open the git repository at the given path.
repo, err := git.PlainOpen(root)
if err != nil {
if err == git.ErrRepositoryNotExists {
return submodulePaths, nil
}
return nil, fmt.Errorf("error opening git repository: %w", err)
}
worktree, err := repo.Worktree()
if err != nil {
return nil, fmt.Errorf("error getting worktree: %w", err)
}
// Get the list of submodules.
submodules, err := worktree.Submodules()
if err != nil {
return nil, fmt.Errorf("error getting submodules: %w", err)
}
for _, sm := range submodules {
submodulePaths[filepath.ToSlash(sm.Config().Path)] = struct{}{}
}
return submodulePaths, nil
}
// getNonASCII retrieves a list of files in the specified root directory that contain non-ASCII characters. // getNonASCII retrieves a list of files in the specified root directory that contain non-ASCII characters.
// It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters. // It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
func getNonASCII(root string) ([]string, error) { func getNonASCII(root string) ([]string, error) {
@ -23,6 +57,11 @@ func getNonASCII(root string) ([]string, error) {
gitattrExist = false gitattrExist = false
} }
submodules, err := getSubmodulePathsFromGoGit(root)
if err != nil {
return nil, err
}
if gitattrExist { if gitattrExist {
fs := os.DirFS(".") fs := os.DirFS(".")
f, err := fs.Open(".gitattributes") f, err := fs.Open(".gitattributes")
@ -42,18 +81,22 @@ func getNonASCII(root string) ([]string, error) {
return err return err
} }
relPath, err := filepath.Rel(root, path)
if err != nil {
return err
}
if info.IsDir() { if info.IsDir() {
if info.Name() == ".git" { if info.Name() == ".git" {
return filepath.SkipDir return filepath.SkipDir
} }
if _, isSubmodule := submodules[relPath]; isSubmodule {
return filepath.SkipDir
}
return nil return nil
} }
if gitattrExist { if gitattrExist {
relPath, err := filepath.Rel(root, path)
if err != nil {
return err
}
ret, matched := matcher.Match(strings.Split(relPath, "/"), nil) ret, matched := matcher.Match(strings.Split(relPath, "/"), nil)
if matched && ret["text"].IsUnset() && !ret["text"].IsSet() { if matched && ret["text"].IsUnset() && !ret["text"].IsSet() {
return nil return nil