11use actix_web:: http:: { Method , Uri } ;
22use actix_web:: { HttpResponse , Route , guard, web} ;
3- use lazy_static:: lazy_static;
43use regex:: Regex ;
4+ use std:: sync:: LazyLock ;
55
66use crate :: error:: Result ;
77use crate :: intel_path:: IntelPath ;
@@ -100,15 +100,23 @@ pub fn rust_static_allow(_config: &Config, path: &str) -> bool {
100100 true
101101}
102102
103- pub fn wheels_allow ( _config : & Config , path : & str ) -> bool {
103+ pub fn wheel_allow_legacy ( _config : & Config , path : & str ) -> bool {
104104 path. ends_with ( ".whl" ) || path. ends_with ( ".html" )
105105}
106106
107+ pub fn wheels_allow ( _config : & Config , path : & str ) -> bool {
108+ if let Some ( ( wheel_path, sha256) ) = path. split_once ( "#sha256=" ) {
109+ return wheel_path. ends_with ( ".whl" )
110+ && sha256. len ( ) == 64
111+ && sha256. chars ( ) . all ( |c| c. is_ascii_hexdigit ( ) ) ;
112+ }
113+
114+ wheel_allow_legacy ( _config, path)
115+ }
116+
107117pub fn github_release_allow ( config : & Config , path : & str ) -> bool {
108- lazy_static ! {
109- static ref REGEX : Regex =
110- Regex :: new( "^[^/]*/[^/]*/releases/download/[^/]*/[^/]*$" ) . unwrap( ) ;
111- } ;
118+ static REGEX : LazyLock < Regex > =
119+ LazyLock :: new ( || Regex :: new ( "^[^/]+/[^/]+/releases/download/[^/]+/[^/]+$" ) . unwrap ( ) ) ;
112120
113121 if !config
114122 . github_release
@@ -123,10 +131,9 @@ pub fn github_release_allow(config: &Config, path: &str) -> bool {
123131}
124132
125133pub fn sjtug_internal_allow ( _config : & Config , path : & str ) -> bool {
126- lazy_static ! {
127- static ref REGEX : Regex =
128- Regex :: new( "^[^/]*/releases/download/[^/]*/[^/]*.(tar.gz|zip)$" ) . unwrap( ) ;
129- } ;
134+ static REGEX : LazyLock < Regex > = LazyLock :: new ( || {
135+ Regex :: new ( "^[^/]*/releases/download/[^/]*/[^/]*[.](tar[.]gz|zip)$" ) . unwrap ( )
136+ } ) ;
130137
131138 REGEX . is_match ( path)
132139}
@@ -738,6 +745,28 @@ mod tests {
738745 assert ! ( !flutter_allow( & config, "flutter/coverage/lcov.info" ) ) ;
739746 }
740747
748+ #[ test]
749+ fn test_wheels_allow ( ) {
750+ let config = Config :: default ( ) ;
751+ assert ! ( wheels_allow( & config, "torch_stable.html" ) ) ;
752+ assert ! ( wheels_allow(
753+ & config,
754+ "torch-2.0.0-cp311-cp311-manylinux.whl"
755+ ) ) ;
756+ assert ! ( !wheels_allow(
757+ & config,
758+ "torch-2.0.0-cp311-cp311-manylinux.whl#sha256=0123456789abcdef" ,
759+ ) ) ;
760+ assert ! ( wheels_allow(
761+ & config,
762+ "cpu/torch-2.11.0%2Bcpu-cp314-cp314t-manylinux_2_28_x86_64.whl" ,
763+ ) ) ;
764+ assert ! ( wheels_allow(
765+ & config,
766+ "cu130/torch-2.11.0%2Bcu130-cp314-cp314t-manylinux_2_28_x86_64.whl" ,
767+ ) ) ;
768+ }
769+
741770 #[ test]
742771 fn test_task_override ( ) {
743772 let mut task = Task {
0 commit comments