Skip to content

Use absolute instead of canonicalize for better Windows path handling #861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion av1an-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "av1an-core"
version = "0.4.1"
rust-version = "1.70"
rust-version = "1.79"
edition = "2021"
authors = ["Zen <[email protected]>"]
description = """
Expand Down
14 changes: 13 additions & 1 deletion av1an-core/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::path::{Path, PathBuf};
use std::{
io,
path::{absolute, Path, PathBuf},
};

/// Count the number of elements passed to this macro.
///
Expand Down Expand Up @@ -133,6 +136,15 @@ pub fn read_in_dir(path: &Path) -> anyhow::Result<impl Iterator<Item = PathBuf>>
}))
}

#[inline]
pub(crate) fn to_absolute_path(path: &Path) -> io::Result<PathBuf> {
if cfg!(target_os = "windows") {
absolute(path)
} else {
path.canonicalize()
}
}

#[cfg(test)]
mod tests {
use std::borrow::Cow;
Expand Down
8 changes: 5 additions & 3 deletions av1an-core/src/vapoursynth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::process::Command;
use vapoursynth::prelude::*;
use vapoursynth::video_info::VideoInfo;

use crate::util::to_absolute_path;

use super::ChunkMethod;

static VAPOURSYNTH_PLUGINS: Lazy<HashSet<String>> = Lazy::new(|| {
Expand Down Expand Up @@ -193,7 +195,7 @@ pub fn create_vs_file(
chunk_method: ChunkMethod,
) -> anyhow::Result<PathBuf> {
let temp: &Path = temp.as_ref();
let source = source.canonicalize()?;
let source = to_absolute_path(source)?;

let load_script_path = temp.join("split").join("loadscript.vpy");

Expand All @@ -205,7 +207,7 @@ pub fn create_vs_file(
ChunkMethod::FFMS2 => "ffindex",
ChunkMethod::LSMASH => "lwi",
ChunkMethod::DGDECNV => "dgi",
ChunkMethod::BESTSOURCE => "json",
ChunkMethod::BESTSOURCE => "bsindex",
_ => return Err(anyhow!("invalid chunk method")),
}
)))?;
Expand All @@ -222,7 +224,7 @@ pub fn create_vs_file(
.arg(&dgindexnv_output)
.output()?;

let dgindex_path = dgindexnv_output.canonicalize()?;
let dgindex_path = to_absolute_path(&dgindexnv_output)?;
load_script.write_all(
format!(
"from vapoursynth import core\n\
Expand Down
Loading