Skip to content

[Bug] Windows下Rule规则配置时 #490

@woobbo

Description

@woobbo

在配置 Rule 规则时,Windows系统下有Bug,如下的例子:

EXTERNAL, site:C:\github\xxxxxxx\build\windows\x64\runner\Debug\data\geosite.dat:cn, Direct

修改 ./leaf/src/config/external_rule.rs 里的 load_file_or_default 函数 (直接替换)

pub fn load_file_or_default(filter: &str, default: &str) -> Result<(String, String)> {
    let all_parts: Vec<&str> = filter.split(':').collect();
    
    if all_parts.len() == 2 {
        let asset_loc = Path::new(&*crate::option::ASSET_LOCATION);
        let path = asset_loc.join(default).to_string_lossy().to_string();
        return Ok((path, all_parts[1].to_string()));
    }

    let first_colon = filter.find(':');
    let last_colon = filter.rfind(':');

    if let (Some(start), Some(end)) = (first_colon, last_colon) {
        if start != end {
            let path_part = &filter[start + 1..end];
            let code_part = &filter[end + 1..];

            let path = if Path::new(path_part).is_absolute() {
                path_part.to_string()
            } else {
                let asset_loc = Path::new(&*crate::option::ASSET_LOCATION);
                asset_loc.join(path_part).to_string_lossy().to_string()
            };
            
            return Ok((path, code_part.to_string()));
        }
    }

    Err(anyhow!("invalid external rule: {}", filter))
}

感谢作者!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions