Skip to content

Commit

Permalink
Use absolute instead of canonicalize for better Windows path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro committed Aug 10, 2024
1 parent 8d06b92 commit c4a0bca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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
6 changes: 4 additions & 2 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 Down Expand Up @@ -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

0 comments on commit c4a0bca

Please sign in to comment.