master-of-zen / Av1an

Cross-platform command-line AV1 / VP9 / HEVC / H264 encoding framework with per scene quality encoding
GNU General Public License v3.0
1.46k stars 151 forks source link

Change path handling in vapoursynth.rs for compatibility #860

Closed RivenSkaye closed 1 month ago

RivenSkaye commented 2 months ago

Currently the source file for vapoursynth is being canonicalized immediately (std::fs::canonicalize) which creates extended (UNC-like) paths on Windows. Depending on the compiler and functions used, code written in other languages may fail to understand these.

Changing the line let source = std::fs::canonicalize(source) to use std::path::absolute instead would fix and prevent future occurrances of e.g. vapoursynth/bestsource#59 altogether.

let source = if cfg!(target_os = "windows") {
    (std::path::absolute(source) 
} else {
    std::fs::canonicalize(source) 
};
shssoichiro commented 2 months ago

Looks like this was just stabilized in the latest Rust release, that would explain why I'd never heard of absolute before. But this behavior does seem a lot more intuitive.

RivenSkaye commented 2 months ago

Yeah, the only reason I included a cfg macro snippet is because of the different behavior between OSes here. I expect some things on Linux to break if they suddenly don't get canonicalized paths anymore, considering the lack of handling symlinks and e.g. .. there

shssoichiro commented 2 months ago

I would expect linux symlinks to be less of an issue, since linux filesystems should handle that natively (e.g. if a Vapoursynth script has a symlink in its source path, that should just work). I'll do some testing just to make sure.

RivenSkaye commented 2 months ago

My worries wrt Linux are more about not sanitizing . and .. which isn't always supported at the filesystem level, as well as being a PITA when debugging code. Sure, accessing the file should work in most cases, but I'd rather be safe than sorry. Especially considering the if cfg! block should be optimized out to either call depending on the target in the MIR optimization pass